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

Commit 2570260e authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Update process lru when switching focus between visible activities

Ensure that the process of the latest touched activity refreshes the
last activity time and maintains its index at the top of the LRU.

Also add a pending flag to avoid updating intermediate state, e.g.
 Launch A
 WindowContainerTransaction {
  beginDeferResume
  reorder home to top // prev=A, update home as top -> avoid this
  reorder WallpaperActivity to top // no resumed activity
  reorder A to top // prevTopActivity becomes null
  endDeferResume
 }

Bug: 421872956
Flag: EXEMPT bugfix
Test: ActivityTaskSupervisorTests#testUpdatePendingTopForTopResumed
Change-Id: Id5f0dde7124200732747185cb8998abcf1254411
parent a08a0293
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -362,6 +362,9 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
     */
    private boolean mTopResumedActivityWaitingForPrev;

    /** Whether a process state update of top resumed activity is deferred. */
    private boolean mHasPendingTopResumedProcessState;

    /** The target root task bounds for the picture-in-picture mode changed that we need to
     * report to the application */
    private Rect mPipModeChangedTargetRootTaskBounds;
@@ -2359,6 +2362,17 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        }
    }

    /** This is only used for switching between resumed activities without activity state change. */
    private void updateTopResumedProcessState() {
        if (mTopResumedActivity == null || mTopResumedActivity.app == null) {
            return;
        }
        mTopResumedActivity.app.updateProcessInfo(
                false /* updateServiceConnectionActivities */, true /* activityChange */,
                false /* updateOomAdj */, true /* addPendingTopUid */);
        mService.updateOomAdj();
    }

    /**
     * Updates the record of top resumed activity when it changes and handles reporting of the
     * state changes to previous and new top activities. It will immediately dispatch top resumed
@@ -2393,10 +2407,11 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        // If the previous top is null, there should be activity state change from it, Then the
        // process state should also have been updated so no need to update again.
        if (mTopResumedActivity != null && prevTopActivity != null) {
            if (mTopResumedActivity.app != null) {
                mTopResumedActivity.app.addToPendingTop();
            if (readyToResume()) {
                updateTopResumedProcessState();
            } else {
                mHasPendingTopResumedProcessState = true;
            }
            mService.updateOomAdj();
        }
        // Update the last resumed activity and focused app when the top resumed activity changed
        // because the new top resumed activity might be already resumed and thus won't have
@@ -2689,6 +2704,10 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
    void endDeferResume() {
        mDeferResumeCount--;
        if (readyToResume()) {
            if (mHasPendingTopResumedProcessState) {
                mHasPendingTopResumedProcessState = false;
                updateTopResumedProcessState();
            }
            if (mLastReportedTopResumedActivity != null
                    && mTopResumedActivity != mLastReportedTopResumedActivity) {
                scheduleTopResumedActivityStateLossIfNeeded();
+3 −0
Original line number Diff line number Diff line
@@ -378,8 +378,11 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
            return null;
        }).when(mAtm.mAmInternal).addPendingTopUid(anyInt(), anyInt(), any());
        clearInvocations(mAtm);
        spyOn(activity1.app);
        activity1.moveFocusableActivityToTop("test");
        assertEquals(activity1.getUid(), pendingTopUid[0]);
        verify(activity1.app).updateProcessInfo(false /* updateServiceConnectionActivities */,
                true /* activityChange */, false /* updateOomAdj */, true /* addPendingTopUid */);
        verify(mAtm).updateOomAdj();
        verify(mAtm).setLastResumedActivityUncheckLocked(any(), eq("test"));
    }