summaryrefslogtreecommitdiff
path: root/core/java/android/os/UserManager.java
diff options
context:
space:
mode:
authorAdam Bookatz <bookatz@google.com>2020-05-19 14:30:33 -0700
committerAdam Bookatz <bookatz@google.com>2020-05-26 23:01:55 +0000
commitd626fd310ccc08bc9a0b9ed8345116f67eea8586 (patch)
treec9d333993bb29ca387d342f2a6b2de9663b30285 /core/java/android/os/UserManager.java
parent57e977a5859ff24f5ff909046dccde5bce341f6d (diff)
Unify multiuser switcher enabled setting
This does the following: 1. The multiuser switcher (in Settings and SysUI) is now disabled by default. In order for it to be enabled one of the following must be true: a. the user has explicitly toggled it on in Settings b. a new user gets created (via any means) c. config_showUserSwitcherByDefault overrides this default 2. Even if a new user is added, if the user had explicitly *disabled* the switcher, the switcher still won't be enabled. 3. SystemUI and Settings (et al.) all use UserManager.isUserSwitcherEnabled as the source of truth in this regard. No one else reads USER_SWITCHER_ENABLED directly. 4. If the switcher is enabled, then SystemUI will show the switcher avatar, even if there are no other users on the device, as long as new users can be created. This way, if the user has enabled the switcher, the user can use the avatar to add guest/secondary users (which would not be possible if enabled status was tied solely to the existence of other users). Bug: 137943217 Bug: 141372193 Bug: 149973281 Bug: 130270878 Test: manual: Settings > Multiuser doesn't turn on the systemui avatar Test: manual: Settings > Multiuser is initially disabled Test: manual: adb shell pm create-user A, does turn on sysui avatar even if the user didn't enable, but not if they disabled Change-Id: Ia440b4db78792da76f94322a563d93db0c68e933
Diffstat (limited to 'core/java/android/os/UserManager.java')
-rw-r--r--core/java/android/os/UserManager.java46
1 files changed, 34 insertions, 12 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index bf105ced65b9..0fdae12fbcf3 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -4032,12 +4032,25 @@ public class UserManager {
}
/**
- * Returns true if the user switcher should be shown, this will be if device supports multi-user
- * and there are at least 2 users available that are not managed profiles.
- * @hide
+ * Returns true if the user switcher should be shown.
+ * I.e., returns whether the user switcher is enabled and there is something actionable to show.
+ *
* @return true if user switcher should be shown.
+ * @hide
*/
public boolean isUserSwitcherEnabled() {
+ return isUserSwitcherEnabled(false);
+ }
+
+ /**
+ * Returns true if the user switcher should be shown.
+ *
+ * @param showEvenIfNotActionable value to return if the feature is enabled but there is nothing
+ * actionable for the user to do anyway
+ * @return true if user switcher should be shown.
+ * @hide
+ */
+ public boolean isUserSwitcherEnabled(boolean showEvenIfNotActionable) {
if (!supportsMultipleUsers()) {
return false;
}
@@ -4048,15 +4061,26 @@ public class UserManager {
if (isDeviceInDemoMode(mContext)) {
return false;
}
- // If user disabled this feature, don't show switcher
- final boolean userSwitcherEnabled = Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.USER_SWITCHER_ENABLED, 1) != 0;
- if (!userSwitcherEnabled) {
+ // Check the Settings.Global.USER_SWITCHER_ENABLED that the user can toggle on/off.
+ final boolean userSwitcherSettingOn = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.USER_SWITCHER_ENABLED,
+ Resources.getSystem().getBoolean(R.bool.config_showUserSwitcherByDefault) ? 1 : 0)
+ != 0;
+ if (!userSwitcherSettingOn) {
return false;
}
- List<UserInfo> users = getUsers(true);
+
+ // The feature is enabled. But is it worth showing?
+ return showEvenIfNotActionable
+ || areThereUsersToWhichToSwitch() // There are switchable users.
+ || !hasUserRestriction(UserManager.DISALLOW_ADD_USER); // New users can be added.
+ }
+
+ /** Returns whether there are any users (other than the current user) to which to switch. */
+ private boolean areThereUsersToWhichToSwitch() {
+ final List<UserInfo> users = getUsers(true);
if (users == null) {
- return false;
+ return false;
}
int switchableUserCount = 0;
for (UserInfo user : users) {
@@ -4064,9 +4088,7 @@ public class UserManager {
++switchableUserCount;
}
}
- final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
- .getGuestUserDisabled(null);
- return switchableUserCount > 1 || guestEnabled;
+ return switchableUserCount > 1;
}
/**