diff options
4 files changed, 26 insertions, 14 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 5b178750bf55..59b5da8eeb51 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -5183,6 +5183,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { String hostingType) { if (!mStartingProcessActivities.contains(activity)) { mStartingProcessActivities.add(activity); + // Let the activity with higher z-order be started first. + if (mStartingProcessActivities.size() > 1) { + mStartingProcessActivities.sort(null /* by WindowContainer#compareTo */); + } } else if (mProcessNames.get( activity.processName, activity.info.applicationInfo.uid) != null) { // The process is already starting. Wait for it to attach. diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index 4da8bbf64522..eb1a80b74b76 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -2583,8 +2583,12 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< // Containers don't belong to the same hierarchy??? if (commonAncestor == null) { - throw new IllegalArgumentException("No in the same hierarchy this=" - + thisParentChain + " other=" + otherParentChain); + final int thisZ = getPrefixOrderIndex(); + final int otherZ = other.getPrefixOrderIndex(); + Slog.w(TAG, "Compare not in the same hierarchy this=" + + thisParentChain + " thisZ=" + thisZ + " other=" + + otherParentChain + " otherZ=" + otherZ); + return Integer.compare(thisZ, otherZ); } // Children are always considered greater than their parents, so if one of the containers diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java index d6d8339e256a..d29505f02fe8 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java @@ -274,17 +274,28 @@ public class RootWindowContainerTests extends WindowTestsBase { @Test public void testAttachApplication() { - final ActivityRecord activity = new ActivityBuilder(mAtm).setCreateTask(true).build(); + final ActivityRecord activity = new ActivityBuilder(mAtm).setProcessName("testAttach") + .setCreateTask(true).build(); + final ActivityRecord topActivity = new ActivityBuilder(mAtm).setProcessName("testAttach") + .setUseProcess(activity.app).setTask(activity.getTask()).build(); activity.detachFromProcess(); - mAtm.startProcessAsync(activity, false /* knownToBeDead */, + topActivity.detachFromProcess(); + mAtm.startProcessAsync(topActivity, false /* knownToBeDead */, true /* isTop */, "test" /* hostingType */); + // Even if the activity is added after topActivity, the start order should still follow + // z-order, i.e. the topActivity will be started first. + mAtm.startProcessAsync(activity, false /* knownToBeDead */, + false /* isTop */, "test" /* hostingType */); + assertEquals(2, mAtm.mStartingProcessActivities.size()); + assertEquals("Top record must be at the tail to start first", + topActivity, mAtm.mStartingProcessActivities.get(1)); final WindowProcessController proc = mSystemServicesTestRule.addProcess( activity.packageName, activity.processName, 6789 /* pid */, activity.info.applicationInfo.uid); try { mRootWindowContainer.attachApplication(proc); - verify(mSupervisor).realStartActivityLocked(eq(activity), eq(proc), anyBoolean(), - anyBoolean()); + verify(mSupervisor).realStartActivityLocked(eq(topActivity), eq(proc), + anyBoolean(), anyBoolean()); } catch (RemoteException e) { e.rethrowAsRuntimeException(); } diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java index 45dbea2bdd45..401964c2f597 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java @@ -805,18 +805,11 @@ public class WindowContainerTests extends WindowTestsBase { final TestWindowContainer root2 = builder.setLayer(0).build(); + assertEquals("Roots have the same z-order", 0, root.compareTo(root2)); assertEquals(0, root.compareTo(root)); assertEquals(-1, child1.compareTo(child2)); assertEquals(1, child2.compareTo(child1)); - boolean inTheSameTree = true; - try { - root.compareTo(root2); - } catch (IllegalArgumentException e) { - inTheSameTree = false; - } - assertFalse(inTheSameTree); - assertEquals(-1, child1.compareTo(child11)); assertEquals(1, child21.compareTo(root)); assertEquals(1, child21.compareTo(child12)); |