summaryrefslogtreecommitdiff
path: root/core/java/android/os/UserManager.java
diff options
context:
space:
mode:
authorBenjamin Franz <bfranz@google.com>2017-08-10 10:39:44 +0100
committerAlex Chau <alexchau@google.com>2017-11-07 11:33:18 +0800
commitff66fa9ef2e12654b5869cae844a9747dfc441eb (patch)
tree0c57770a2b5144507cc8aaa6036c767571397dc8 /core/java/android/os/UserManager.java
parenta674fafb62bdfc02677205b02e6beced731f0913 (diff)
Create a new user restriction to disallow user switching
For multi-user session implementation, we want to block the user from going back to user 0. Therefore, we block the user switcher in the secondary user, as well as swtiching via user section in Settings app. Bug: 64382189 Test: Manually verify user switcher is not displayed in QuickSettings Test: Manulaly verify not able to remove or switcher user in user section in Setting app Change-Id: I84bc9e67e3fe7fccb75edf0fc49b775b902f5290
Diffstat (limited to 'core/java/android/os/UserManager.java')
-rw-r--r--core/java/android/os/UserManager.java22
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;