diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-11-08 20:16:22 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-11-08 20:16:22 +0000 |
| commit | 42e0ab0651f0bcaf4dc9750ac3dbcff8f3d7591c (patch) | |
| tree | 9bf4e165056f0f2d5353e43b719da27285f304d7 /core/java | |
| parent | 607704394ffc2f9aa0b94dd7dfc005f231bb46e2 (diff) | |
| parent | ff66fa9ef2e12654b5869cae844a9747dfc441eb (diff) | |
Merge "Create a new user restriction to disallow user switching"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/os/UserManager.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index c54b72d40387..28836e4ae6cd 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -792,6 +792,19 @@ public class UserManager { public static final String DISALLOW_AUTOFILL = "no_autofill"; /** + * Specifies if user switching is blocked on the current user. + * + * <p> This restriction can only be set by the device owner, it will be applied to all users. + * + * <p>The default value is <code>false</code>. + * + * @see DevicePolicyManager#addUserRestriction(ComponentName, String) + * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) + * @see #getUserRestrictions() + */ + public static final String DISALLOW_USER_SWITCH = "no_user_switch"; + + /** * Application restriction key that is used to indicate the pending arrival * of real restrictions for the app. * @@ -917,7 +930,7 @@ public class UserManager { /** * Returns whether switching users is currently allowed. * <p>For instance switching users is not allowed if the current user is in a phone call, - * or system user hasn't been unlocked yet + * system user hasn't been unlocked yet, or {@link #DISALLOW_USER_SWITCH} is set. * @hide */ public boolean canSwitchUsers() { @@ -927,7 +940,9 @@ public class UserManager { boolean isSystemUserUnlocked = isUserUnlocked(UserHandle.SYSTEM); boolean inCall = TelephonyManager.getDefault().getCallState() != TelephonyManager.CALL_STATE_IDLE; - return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall; + boolean isUserSwitchDisallowed = hasUserRestriction(DISALLOW_USER_SWITCH); + return (allowUserSwitchingWhenSystemUserLocked || isSystemUserUnlocked) && !inCall + && !isUserSwitchDisallowed; } /** @@ -2298,6 +2313,9 @@ public class UserManager { if (!supportsMultipleUsers()) { return false; } + if (hasUserRestriction(DISALLOW_USER_SWITCH)) { + return false; + } // If Demo Mode is on, don't show user switcher if (isDeviceInDemoMode(mContext)) { return false; |
