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

Commit 82bb590c authored by Michal Karpinski's avatar Michal Karpinski
Browse files

Allow background activity starts for callers that have

the same uid as the recents component

Bug: 110956953
Test: atest WmTests:ActivityStarterTests
Test: manual - both with nexuslauncher and 3P launcher
Change-Id: I4f7a9db2ad22205d37c7b9a52325011a3906c247
parent 8596dedf
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -783,7 +783,7 @@ class ActivityStarter {
            // they will just get a cancel result.
            ActivityOptions.abort(checkedOptions);
            maybeLogActivityStart(callingUid, callingPackage, realCallingUid, intent, callerApp,
                    /* r= */ null, originatingPendingIntent, /* abortedStart= */ true);
                    null /*r*/, originatingPendingIntent, true /*abortedStart*/);
            return START_ABORTED;
        }

@@ -876,7 +876,7 @@ class ActivityStarter {
        mController.doPendingActivityLaunches(false);

        maybeLogActivityStart(callingUid, callingPackage, realCallingUid, intent, callerApp, r,
                originatingPendingIntent, /* abortedStart= */ false);
                originatingPendingIntent, false /*abortedStart*/);

        return startActivity(r, sourceRecord, voiceSession, voiceInteractor, startFlags,
                true /* doResume */, checkedOptions, inTask, outActivity);
@@ -903,6 +903,10 @@ class ActivityStarter {
        if (mService.mWindowManager.isAnyWindowVisibleForUid(callingUid)) {
            return false;
        }
        // don't abort if the caller has the same uid as the recents component
        if (mSupervisor.mRecentTasks.isCallerRecents(callingUid)) {
            return false;
        }
        // anything that has fallen through will currently be aborted
        // TODO: remove this toast after feature development is done
        mService.mUiHandler.post(() -> {
+14 −8
Original line number Diff line number Diff line
@@ -562,7 +562,7 @@ public class ActivityStarterTests extends ActivityTestsBase {
        doReturn(true).when(mService).isBackgroundActivityStartsEnabled();

        runAndVerifyBackgroundActivityStartsSubtest("allowed_noStartsAborted",
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, false);
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, false, false);
    }

    /**
@@ -574,7 +574,7 @@ public class ActivityStarterTests extends ActivityTestsBase {
        doReturn(false).when(mService).isBackgroundActivityStartsEnabled();

        runAndVerifyBackgroundActivityStartsSubtest("disallowed_unsupportedUsecase_aborted",
                true, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, false);
                true, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, false, false);
    }

    /**
@@ -587,20 +587,22 @@ public class ActivityStarterTests extends ActivityTestsBase {
        doReturn(false).when(mService).isBackgroundActivityStartsEnabled();

        runAndVerifyBackgroundActivityStartsSubtest("disallowed_rootUid_notAborted",
                false, Process.ROOT_UID, false, PROCESS_STATE_TOP + 1, false);
                false, Process.ROOT_UID, false, PROCESS_STATE_TOP + 1, false, false);
        runAndVerifyBackgroundActivityStartsSubtest("disallowed_systemUid_notAborted",
                false, Process.SYSTEM_UID, false, PROCESS_STATE_TOP + 1, false);
                false, Process.SYSTEM_UID, false, PROCESS_STATE_TOP + 1, false, false);
        runAndVerifyBackgroundActivityStartsSubtest("disallowed_hasVisibleWindow_notAborted",
                false, UNIMPORTANT_UID, true, PROCESS_STATE_TOP + 1, false);
                false, UNIMPORTANT_UID, true, PROCESS_STATE_TOP + 1, false, false);
        runAndVerifyBackgroundActivityStartsSubtest("disallowed_processStateTop_notAborted",
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP, false);
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP, false, false);
        runAndVerifyBackgroundActivityStartsSubtest("disallowed_hasForegroundActivities_notAborted",
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, true);
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, true, false);
        runAndVerifyBackgroundActivityStartsSubtest("disallowed_callerIsRecents_notAborted",
                false, UNIMPORTANT_UID, false, PROCESS_STATE_TOP + 1, false, true);
    }

    private void runAndVerifyBackgroundActivityStartsSubtest(String name, boolean shouldHaveAborted,
            int testCallingUid, boolean hasVisibleWindow, int procState,
            boolean hasForegroundActivities) {
            boolean hasForegroundActivities, boolean callerIsRecents) {
        // window visibility
        doReturn(hasVisibleWindow).when(mService.mWindowManager).isAnyWindowVisibleForUid(
                testCallingUid);
@@ -614,6 +616,10 @@ public class ActivityStarterTests extends ActivityTestsBase {
                new WindowProcessController(mService, ai, null, testCallingUid, -1, null, null);
        callerApp.setHasForegroundActivities(hasForegroundActivities);
        doReturn(callerApp).when(mService).getProcessController(caller);
        // caller is recents
        RecentTasks recentTasks = mock(RecentTasks.class);
        mService.mStackSupervisor.setRecentTasks(recentTasks);
        doReturn(callerIsRecents).when(recentTasks).isCallerRecents(testCallingUid);

        final ActivityOptions options = spy(ActivityOptions.makeBasic());
        ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK).setCaller(caller)