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

Commit 638aa4bf authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Skip setting intermediate top when moving task to front

For example:
Start a new activity on a background task with an existing activity.
When moving the task to front, TDA#positionChildTaskAt ->
updateTopResumedActivityIfNeeded can be called before the new activity
is added on the task. Then the existing non-visible activity will be
set as top app within a short time. That will cause some resource
managements confusion about process importance.

Bug: 335085960
Test: ActivityTaskSupervisorTests#testUpdateTopResumed_moveToFront
      ResourceManagerMultiTest#testReclaimResource
Change-Id: I154b3afdff978ffceeea2dd34fa467baa20aa015
parent b3942280
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -2311,8 +2311,12 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
            mService.setLastResumedActivityUncheckLocked(mTopResumedActivity, reason);
        }
        scheduleTopResumedActivityStateIfNeeded();

        // If the device is not sleeping and there is no top resumed, do not update top app because
        // it may be an intermediate state while moving a task to front. The actual top will be set
        // when TaskFragment#setResumedActivity is called.
        if (mTopResumedActivity != null || mService.isSleepingLocked()) {
            mService.updateTopApp(mTopResumedActivity);
        }

        return mTopResumedActivity;
    }
+14 −0
Original line number Diff line number Diff line
@@ -343,6 +343,20 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
        verify(mAtm).setLastResumedActivityUncheckLocked(any(), eq("test"));
    }

    @Test
    public void testUpdateTopResumed_moveToFront() {
        final ActivityRecord activity1 = new ActivityBuilder(mAtm).setCreateTask(true).build();
        final ActivityRecord activity2 = new ActivityBuilder(mAtm).setCreateTask(true).build();
        activity2.setState(ActivityRecord.State.RESUMED, "test");
        assertEquals(activity2.app, mAtm.mTopApp);
        activity1.getTask().moveToFront("test");
        // If the device is not sleeping, the app should be only set with resumed state.
        assertEquals(activity2.app, mAtm.mTopApp);
        activity2.setState(ActivityRecord.State.PAUSED, "test");
        activity1.setState(ActivityRecord.State.RESUMED, "test");
        assertEquals(activity1.app, mAtm.mTopApp);
    }

    /**
     * We need to launch home again after user unlocked for those displays that do not have
     * encryption aware home app.
+1 −0
Original line number Diff line number Diff line
@@ -406,6 +406,7 @@ public class WindowProcessControllerTests extends WindowTestsBase {
        verify(tracker).onActivityResumedWhileVisible(mWpc);
        assertTrue(tracker.hasResumedActivity(mWpc.mUid));

        mAtm.mTopApp = null;
        activity.makeFinishingLocked();
        activity.setState(PAUSING, "test");