Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71ecd9c2 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Start activity from top z-order when attaching process

The order of start process request may not be the same as hierarchy
z-order. E.g. when moving a task with 2 translucent activities
which belong to the same dead process, the top activity will request
first. And then ensure-visibility may be called from completePaused
of previous activity, then the bottom activity will also request to
start. And if realStartActivityLocked is called for the bottom activity,
the ensureVisibilityAndConfig in realStartActivityLocked will make top
activity create with deferResume=true, which causes to miss top resumed
(no wm_on_top_resumed_gained_called).

Also make WindowContainer#compareTo safer, which allows to compare
container without parent. The result is still valid by tracing the
parent and index.

Bug: 352423986
Flag: EXEMPT bugfix
Test: RootWindowContainerTests#testAttachApplication
Change-Id: Iabccb9fd0cd2260d803756dc4cd0b7613b11a7fb
parent 9a70da4e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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.
+6 −2
Original line number Diff line number Diff line
@@ -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
+15 −4
Original line number Diff line number Diff line
@@ -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();
        }
+1 −8
Original line number Diff line number Diff line
@@ -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));