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

Commit a05b6b05 authored by Winson Chung's avatar Winson Chung
Browse files

Fix app switch regression

- SystemUI has STOP_APP_SWITCHES, which meant that
  checkAppSwitchAllowedLocked() would never block the launch of an
  activity after hitting the home button when launching from recents.
  However, Launcher does not have this permission, so quick launches of
  home/launcher-based-recents activity would be blocked (waiting for the
  app switch timeout). This is only apparent when we have the fallback
  3 button nav bar, since we do not stop app switches when swiping up.

  This CL enables the system defined recents activity to manage app
  switches.

Bug: 77152886
Test: Manual, enable three button nav bar, go home, double tap recents and
      then tap again to go home.
Test: atest FrameworksServicesTests:RecentTasksTest

Change-Id: I51959c2b0f8d8b7c5f184a1fdf15294b569f5a50
parent e81e6faf
Loading
Loading
Loading
Loading
+9 −18
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS;
import static android.Manifest.permission.READ_FRAME_BUFFER;
import static android.Manifest.permission.REMOVE_TASKS;
import static android.Manifest.permission.START_TASKS_FROM_RECENTS;
import static android.Manifest.permission.STOP_APP_SWITCHES;
import static android.app.ActivityManager.LOCK_TASK_MODE_NONE;
import static android.app.ActivityManager.RESIZE_MODE_PRESERVE_WINDOW;
import static android.app.ActivityManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
@@ -13338,12 +13339,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    @Override
    public void stopAppSwitches() {
        if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("viewquires permission "
                    + android.Manifest.permission.STOP_APP_SWITCHES);
        }
        enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "stopAppSwitches");
        synchronized(this) {
            mAppSwitchesAllowedTime = SystemClock.uptimeMillis()
                    + APP_SWITCH_DELAY_TIME;
@@ -13353,12 +13349,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    public void resumeAppSwitches() {
        if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires permission "
                    + android.Manifest.permission.STOP_APP_SWITCHES);
        }
        enforceCallerIsRecentsOrHasPermission(STOP_APP_SWITCHES, "resumeAppSwitches");
        synchronized(this) {
            // Note that we don't execute any pending app switches... we will
            // let those wait until either the timeout, or the next start
@@ -13385,9 +13376,11 @@ public class ActivityManagerService extends IActivityManager.Stub
            return true;
        }
        int perm = checkComponentPermission(
                android.Manifest.permission.STOP_APP_SWITCHES, sourcePid,
                sourceUid, -1, true);
        if (mRecentTasks.isCallerRecents(sourceUid)) {
            return true;
        }
        int perm = checkComponentPermission(STOP_APP_SWITCHES, sourcePid, sourceUid, -1, true);
        if (perm == PackageManager.PERMISSION_GRANTED) {
            return true;
        }
@@ -13398,9 +13391,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        // If the actual IPC caller is different from the logical source, then
        // also see if they are allowed to control app switches.
        if (callingUid != -1 && callingUid != sourceUid) {
            perm = checkComponentPermission(
                    android.Manifest.permission.STOP_APP_SWITCHES, callingPid,
                    callingUid, -1, true);
            perm = checkComponentPermission(STOP_APP_SWITCHES, callingPid, callingUid, -1, true);
            if (perm == PackageManager.PERMISSION_GRANTED) {
                return true;
            }
+2 −0
Original line number Diff line number Diff line
@@ -650,6 +650,8 @@ public class RecentTasksTest extends ActivityTestsBase {
        assertSecurityException(expectCallable, () -> mService.startRecentsActivity(null, null,
                null));
        assertSecurityException(expectCallable, () -> mService.cancelRecentsAnimation(true));
        assertSecurityException(expectCallable, () -> mService.stopAppSwitches());
        assertSecurityException(expectCallable, () -> mService.resumeAppSwitches());
    }

    private void testGetTasksApis(boolean expectCallable) {