diff options
author | Felipe Leme <felipeal@google.com> | 2021-11-03 19:42:44 -0700 |
---|---|---|
committer | Felipe Leme <felipeal@google.com> | 2021-11-08 16:32:42 -0800 |
commit | 61292e22edb46bf972b24c75cc03d80e4c3ea2dd (patch) | |
tree | cbaba6546f92fb8eb4ad86f003dc2e6e3e0da0e5 | |
parent | 533ce6f9f0bbecd804ca8194577767727876fb5d (diff) |
Renamed setStopBackgroundUsersOnSwitch to setStopUserOnSwitch()
Test: atest NeneTest:UsersTest
Test: m update-api CtsVerifier
Test: adb shell cmd activity set-stop-user-on-switch false
Test: adb shell cmd activity set-stop-user-on-switch
Test: adb shell dumpsys activity users|grep OnSwitch
Bug: 203752848
Merged-In: Iea03164319768abf159bf8ae2ccc539620cb30fe
Change-Id: Iea03164319768abf159bf8ae2ccc539620cb30fe
7 files changed, 59 insertions, 62 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 40880c19f0a0..3d507714519c 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -113,7 +113,7 @@ package android.app { method @RequiresPermission(android.Manifest.permission.RESET_APP_ERRORS) public void resetAppErrors(); method public static void resumeAppSwitches() throws android.os.RemoteException; method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public void scheduleApplicationInfoChanged(java.util.List<java.lang.String>, int); - method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public void setStopBackgroundUsersOnSwitch(int); + method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public void setStopUserOnSwitch(int); method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public boolean stopUser(int, boolean); method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public boolean updateMccMncConfiguration(@NonNull String, @NonNull String); method @RequiresPermission(android.Manifest.permission.DUMP) public void waitForBroadcastIdle(); @@ -128,9 +128,9 @@ package android.app { field public static final int PROCESS_CAPABILITY_NONE = 0; // 0x0 field public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4; // 0x4 field public static final int PROCESS_STATE_TOP = 2; // 0x2 - field public static final int STOP_BG_USERS_ON_SWITCH_DEFAULT = -1; // 0xffffffff - field public static final int STOP_BG_USERS_ON_SWITCH_FALSE = 0; // 0x0 - field public static final int STOP_BG_USERS_ON_SWITCH_TRUE = 1; // 0x1 + field public static final int STOP_USER_ON_SWITCH_DEFAULT = -1; // 0xffffffff + field public static final int STOP_USER_ON_SWITCH_FALSE = 0; // 0x0 + field public static final int STOP_USER_ON_SWITCH_TRUE = 1; // 0x1 } public static class ActivityManager.RunningAppProcessInfo implements android.os.Parcelable { diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 50a562b66f16..f0deecac96c5 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -4081,45 +4081,46 @@ public class ActivityManager { * @hide */ @TestApi - public static final int STOP_BG_USERS_ON_SWITCH_DEFAULT = -1; + public static final int STOP_USER_ON_SWITCH_DEFAULT = -1; /** - * Overrides value defined by the platform and stop background users on switch. + * Overrides value defined by the platform and stop user on switch. * * @hide */ @TestApi - public static final int STOP_BG_USERS_ON_SWITCH_TRUE = 1; + public static final int STOP_USER_ON_SWITCH_TRUE = 1; /** - * Overrides value defined by the platform and don't stop background users on switch. + * Overrides value defined by the platform and don't stop user on switch. * * @hide */ @TestApi - public static final int STOP_BG_USERS_ON_SWITCH_FALSE = 0; + public static final int STOP_USER_ON_SWITCH_FALSE = 0; /** @hide */ - @IntDef(prefix = { "STOP_BG_USERS_ON_SWITCH_" }, value = { - STOP_BG_USERS_ON_SWITCH_DEFAULT, - STOP_BG_USERS_ON_SWITCH_TRUE, - STOP_BG_USERS_ON_SWITCH_FALSE + @IntDef(prefix = { "STOP_USER_ON_SWITCH_" }, value = { + STOP_USER_ON_SWITCH_DEFAULT, + STOP_USER_ON_SWITCH_TRUE, + STOP_USER_ON_SWITCH_FALSE }) - public @interface StopBgUsersOnSwitch {} + public @interface StopUserOnSwitch {} /** - * Sets whether background users should be stopped when the current user is switched. + * Sets whether the current foreground user (and its profiles) should be stopped after switched + * out. * - * <p>Should only be used on tests. + * <p>Should only be used on tests. Doesn't apply to {@link UserHandle#SYSTEM system user}. * * @hide */ @TestApi @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) - public void setStopBackgroundUsersOnSwitch(@StopBgUsersOnSwitch int value) { + public void setStopUserOnSwitch(@StopUserOnSwitch int value) { try { - getService().setStopBackgroundUsersOnSwitch(value); + getService().setStopUserOnSwitch(value); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java index b416c95329b2..7be4c3e1465b 100644 --- a/core/java/android/app/ActivityManagerInternal.java +++ b/core/java/android/app/ActivityManagerInternal.java @@ -16,7 +16,7 @@ package android.app; -import static android.app.ActivityManager.StopBgUsersOnSwitch; +import static android.app.ActivityManager.StopUserOnSwitch; import android.annotation.NonNull; import android.annotation.Nullable; @@ -663,9 +663,10 @@ public abstract class ActivityManagerInternal { @Nullable VoiceInteractionManagerProvider provider); /** - * Sets whether background users should be stopped when the current user is switched. + * Sets whether the current foreground user (and its profiles) should be stopped after switched + * out. */ - public abstract void setStopBackgroundUsersOnSwitch(@StopBgUsersOnSwitch int value); + public abstract void setStopUserOnSwitch(@StopUserOnSwitch int value); /** * Provides the interface to communicate between voice interaction manager service and diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index 601ec9a152ca..0210a94eafcc 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -341,7 +341,7 @@ interface IActivityManager { @UnsupportedAppUsage boolean switchUser(int userid); @UnsupportedAppUsage - void setStopBackgroundUsersOnSwitch(int value); + void setStopUserOnSwitch(int value); boolean removeTask(int taskId); @UnsupportedAppUsage void registerProcessObserver(in IProcessObserver observer); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index cd743f9524e6..b5f3389c50e0 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -31,7 +31,7 @@ import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY; import static android.app.ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; import static android.app.ActivityManager.PROCESS_STATE_TOP; -import static android.app.ActivityManager.StopBgUsersOnSwitch; +import static android.app.ActivityManager.StopUserOnSwitch; import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY; import static android.app.ActivityManagerInternal.ALLOW_NON_FULL; import static android.app.AppOpsManager.OP_NONE; @@ -15099,8 +15099,8 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public void setStopBackgroundUsersOnSwitch(@StopBgUsersOnSwitch int value) { - mUserController.setStopBackgroundUsersOnSwitch(value); + public void setStopUserOnSwitch(@StopUserOnSwitch int value) { + mUserController.setStopUserOnSwitch(value); } @Override @@ -16402,8 +16402,8 @@ public class ActivityManagerService extends IActivityManager.Stub } @Override - public void setStopBackgroundUsersOnSwitch(int value) { - ActivityManagerService.this.setStopBackgroundUsersOnSwitch(value); + public void setStopUserOnSwitch(int value) { + ActivityManagerService.this.setStopUserOnSwitch(value); } } diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 60b2149b1f14..31e48fb0837f 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -331,7 +331,7 @@ final class ActivityManagerShellCommand extends ShellCommand { case "get-isolated-pids": return runGetIsolatedProcesses(pw); case "set-stop-user-on-switch": - return runSetStopBackgroundUsersOnSwitch(pw); + return runSetStopUserOnSwitch(pw); default: return handleDefaultCommands(cmd); } @@ -3166,25 +3166,24 @@ final class ActivityManagerShellCommand extends ShellCommand { return 0; } - private int runSetStopBackgroundUsersOnSwitch(PrintWriter pw) throws RemoteException { + private int runSetStopUserOnSwitch(PrintWriter pw) throws RemoteException { mInternal.enforceCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, - "setStopBackgroundUsersOnSwitch()"); + "setStopUserOnSwitch()"); String arg = getNextArg(); if (arg == null) { - Slogf.i(TAG, "runSetStopBackgroundUsersOnSwitch(): resetting to default value"); - mInternal.setStopBackgroundUsersOnSwitch( - ActivityManager.STOP_BG_USERS_ON_SWITCH_DEFAULT); + Slogf.i(TAG, "setStopUserOnSwitch(): resetting to default value"); + mInternal.setStopUserOnSwitch(ActivityManager.STOP_USER_ON_SWITCH_DEFAULT); pw.println("Reset to default value"); return 0; } boolean stop = Boolean.parseBoolean(arg); int value = stop - ? ActivityManager.STOP_BG_USERS_ON_SWITCH_TRUE - : ActivityManager.STOP_BG_USERS_ON_SWITCH_FALSE; + ? ActivityManager.STOP_USER_ON_SWITCH_TRUE + : ActivityManager.STOP_USER_ON_SWITCH_FALSE; - Slogf.i(TAG, "runSetStopBackgroundUsersOnSwitch(): setting to %d (%b)", value, stop); - mInternal.setStopBackgroundUsersOnSwitch(value); + Slogf.i(TAG, "runSetStopUserOnSwitch(): setting to %d (%b)", value, stop); + mInternal.setStopUserOnSwitch(value); pw.println("Set to " + stop); return 0; diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index b8be6c5f83dd..319fa94058dd 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -19,9 +19,9 @@ package com.android.server.am; import static android.Manifest.permission.INTERACT_ACROSS_PROFILES; import static android.Manifest.permission.INTERACT_ACROSS_USERS; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; -import static android.app.ActivityManager.STOP_BG_USERS_ON_SWITCH_DEFAULT; -import static android.app.ActivityManager.STOP_BG_USERS_ON_SWITCH_TRUE; -import static android.app.ActivityManager.StopBgUsersOnSwitch; +import static android.app.ActivityManager.STOP_USER_ON_SWITCH_DEFAULT; +import static android.app.ActivityManager.STOP_USER_ON_SWITCH_TRUE; +import static android.app.ActivityManager.StopUserOnSwitch; import static android.app.ActivityManager.USER_OP_ERROR_IS_SYSTEM; import static android.app.ActivityManager.USER_OP_ERROR_RELATED_USERS_CANNOT_STOP; import static android.app.ActivityManager.USER_OP_IS_CURRENT; @@ -376,7 +376,7 @@ class UserController implements Handler.Callback { * user is switched. */ @GuardedBy("mLock") - private @StopBgUsersOnSwitch int mStopBgUsersOnSwitch = STOP_BG_USERS_ON_SWITCH_DEFAULT; + private @StopUserOnSwitch int mStopUserOnSwitch = STOP_USER_ON_SWITCH_DEFAULT; UserController(ActivityManagerService service) { this(new Injector(service)); @@ -418,29 +418,27 @@ class UserController implements Handler.Callback { } } - void setStopBackgroundUsersOnSwitch(@StopBgUsersOnSwitch int value) { + void setStopUserOnSwitch(@StopUserOnSwitch int value) { if (mInjector.checkCallingPermission(android.Manifest.permission.MANAGE_USERS) == PackageManager.PERMISSION_DENIED && mInjector.checkCallingPermission( android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) == PackageManager.PERMISSION_DENIED) { throw new SecurityException( "You either need MANAGE_USERS or INTERACT_ACROSS_USERS_FULL permission to " - + "call setStopBackgroundUsersOnSwitch()"); + + "call setStopUserOnSwitch()"); } synchronized (mLock) { - Slogf.i(TAG, "setStopBackgroundUsersOnSwitch(): %d -> %d", - mStopBgUsersOnSwitch, value); - mStopBgUsersOnSwitch = value; + Slogf.i(TAG, "setStopUserOnSwitch(): %d -> %d", mStopUserOnSwitch, value); + mStopUserOnSwitch = value; } } - private boolean shouldStopBackgroundUsersOnSwitch() { + private boolean shouldStopUserOnSwitch() { synchronized (mLock) { - if (mStopBgUsersOnSwitch != STOP_BG_USERS_ON_SWITCH_DEFAULT) { - final boolean value = mStopBgUsersOnSwitch == STOP_BG_USERS_ON_SWITCH_TRUE; - Slogf.i(TAG, "isStopBackgroundUsersOnSwitch(): returning overridden value (%b)", - value); + if (mStopUserOnSwitch != STOP_USER_ON_SWITCH_DEFAULT) { + final boolean value = mStopUserOnSwitch == STOP_USER_ON_SWITCH_TRUE; + Slogf.i(TAG, "shouldStopUserOnSwitch(): returning overridden value (%b)", value); return value; } } @@ -1834,7 +1832,7 @@ class UserController implements Handler.Callback { mUserSwitchObservers.finishBroadcast(); } - private void stopBackgroundUsersOnSwitchIfEnforced(@UserIdInt int oldUserId) { + private void stopUserOnSwitchIfEnforced(@UserIdInt int oldUserId) { // Never stop system user if (oldUserId == UserHandle.USER_SYSTEM) { return; @@ -1842,18 +1840,17 @@ class UserController implements Handler.Callback { boolean hasRestriction = hasUserRestriction(UserManager.DISALLOW_RUN_IN_BACKGROUND, oldUserId); synchronized (mLock) { - // If running in background is disabled or mStopBackgroundUsersOnSwitch mode, - // stop the user. - boolean disallowRunInBg = hasRestriction || shouldStopBackgroundUsersOnSwitch(); + // If running in background is disabled or mStopUserOnSwitch mode, stop the user. + boolean disallowRunInBg = hasRestriction || shouldStopUserOnSwitch(); if (!disallowRunInBg) { if (DEBUG_MU) { - Slogf.i(TAG, "stopBackgroundUsersIfEnforced() NOT stopping %d and related " - + "users", oldUserId); + Slogf.i(TAG, "stopUserOnSwitchIfEnforced() NOT stopping %d and related users", + oldUserId); } return; } if (DEBUG_MU) { - Slogf.i(TAG, "stopBackgroundUsersIfEnforced() stopping %d and related users", + Slogf.i(TAG, "stopUserOnSwitchIfEnforced() stopping %d and related users", oldUserId); } stopUsersLU(oldUserId, /* force= */ false, /* allowDelayedLocking= */ true, @@ -1956,7 +1953,7 @@ class UserController implements Handler.Callback { mHandler.removeMessages(REPORT_USER_SWITCH_COMPLETE_MSG); mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_COMPLETE_MSG, newUserId, 0)); stopGuestOrEphemeralUserIfBackground(oldUserId); - stopBackgroundUsersOnSwitchIfEnforced(oldUserId); + stopUserOnSwitchIfEnforced(oldUserId); } private void moveUserToForeground(UserState uss, int oldUserId, int newUserId) { @@ -2646,9 +2643,8 @@ class UserController implements Handler.Callback { pw.println(" mTargetUserId:" + mTargetUserId); pw.println(" mLastActiveUsers:" + mLastActiveUsers); pw.println(" mDelayUserDataLocking:" + mDelayUserDataLocking); - pw.println(" shouldStopBackgroundUsersOnSwitch():" - + shouldStopBackgroundUsersOnSwitch()); - pw.println(" mStopBgUsersOnSwitch:" + mStopBgUsersOnSwitch); + pw.println(" shouldStopUserOnSwitch():" + shouldStopUserOnSwitch()); + pw.println(" mStopUserOnSwitch:" + mStopUserOnSwitch); pw.println(" mMaxRunningUsers:" + mMaxRunningUsers); pw.println(" mUserSwitchUiEnabled:" + mUserSwitchUiEnabled); pw.println(" mInitialized:" + mInitialized); |