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

Commit e5275c80 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Do not account recents activity as previous process

When using 3rd party home, the RecentsActivity will be involved in
gesture navigation. E.g. when swiping to home, both the closing app
and recents will be stopped to update previous process.

Because RecentsActivity should already keep a higher oom-adj (100)
by the service binding from systemui to its TouchInteractionService,
it's better to let the real last used app be the previous process.

Also optimize isRecentsComponent a bit because uid check is faster
and easier to skip unnecessary string comparison.

Fix: 415340877
Flag: EXEMPT bugfix
Test: ActivityTaskManagerServiceTests#testUpdatePreviousProcess
Test: Set 3rd party launcher as default home.
      Use swipe-up gesture to return from an app to home.
      "adb shell dumpsys activity o | grep mPreviousProcess"
      The output should show the app.
Change-Id: I88cbb22319f3486a7456d39b7820a4cb9423bc34
parent bccf1b44
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -5372,7 +5372,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                // The stopped activity must have been visible later than the previous.
                && stoppedActivity.lastVisibleTime > mPreviousProcessVisibleTime
                // Home has its own retained state, so don't let it occupy the previous.
                && stoppedActivity.app != mHomeProcess) {
                && stoppedActivity.app != mHomeProcess
                // Exclude recents that should be bound-foreground-service state.
                && !mRecentTasks.isRecentsComponent(
                        stoppedActivity.mActivityComponent,
                        stoppedActivity.info.applicationInfo.uid)) {
            mPreviousProcess = stoppedActivity.app;
            mPreviousProcessVisibleTime = stoppedActivity.lastVisibleTime;
        }
+1 −1
Original line number Diff line number Diff line
@@ -446,7 +446,7 @@ class RecentTasks {
     * recents component.
     */
    boolean isRecentsComponent(ComponentName cn, int uid) {
        return cn.equals(mRecentsComponent) && UserHandle.isSameApp(uid, mRecentsUid);
        return UserHandle.isSameApp(uid, mRecentsUid) && cn.equals(mRecentsComponent);
    }

    /**
+25 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT;
import static com.android.server.wm.ActivityInterceptorCallback.MAINLINE_FIRST_ORDERED_ID;
@@ -47,6 +48,7 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doThrow;
@@ -583,6 +585,29 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
                PowerManagerInternal.MODE_DISPLAY_CHANGE, false);
    }

    @Test
    public void testUpdatePreviousProcess() {
        final ActivityRecord activity = new ActivityBuilder(mAtm).build();
        activity.lastVisibleTime = 1;
        mAtm.mTopApp = mock(WindowProcessController.class);
        mAtm.updatePreviousProcess(activity);

        assertEquals(activity.app, mAtm.mPreviousProcess);

        final ActivityRecord recentsActivity = new ActivityBuilder(mAtm)
                .setUid("recents".hashCode()).build();
        final RecentTasks recentTasks = mAtm.getRecentTasks();
        spyOn(recentTasks);
        doReturn(true).when(recentTasks).isRecentsComponent(
                eq(recentsActivity.mActivityComponent),
                eq(recentsActivity.info.applicationInfo.uid));
        recentsActivity.lastVisibleTime = 2;
        mAtm.updatePreviousProcess(recentsActivity);

        assertEquals("RecentsActivity must not occupy 'previous process'",
                activity.app, mAtm.mPreviousProcess);
    }

    @Test
    public void testSupportsMultiWindow_resizable() {
        final ActivityRecord activity = new ActivityBuilder(mAtm)