Merge "Unify multiuser switcher enabled setting" into rvc-dev am: 203a17d955 am: 7ea82860a5 am: ef92bf2f6d
Change-Id: Ied84b60880877f77de4b71dafdc5cf42bb7bfd3e
This commit is contained in:
@@ -4102,12 +4102,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;
|
||||
}
|
||||
@@ -4118,15 +4131,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) {
|
||||
@@ -4134,9 +4158,7 @@ public class UserManager {
|
||||
++switchableUserCount;
|
||||
}
|
||||
}
|
||||
final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
|
||||
.getGuestUserDisabled(null);
|
||||
return switchableUserCount > 1 || guestEnabled;
|
||||
return switchableUserCount > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,5 +48,8 @@
|
||||
|
||||
<!-- Set to true to enable the user switcher on the keyguard. -->
|
||||
<bool name="config_keyguardUserSwitcher">true</bool>
|
||||
|
||||
<!-- If true, show multiuser switcher by default unless the user specifically disables it. -->
|
||||
<bool name="config_showUserSwitcherByDefault">true</bool>
|
||||
</resources>
|
||||
|
||||
|
||||
@@ -4444,6 +4444,9 @@
|
||||
<!-- Set to true to enable the user switcher on the keyguard. -->
|
||||
<bool name="config_keyguardUserSwitcher">false</bool>
|
||||
|
||||
<!-- If true, show multiuser switcher by default unless the user specifically disables it. -->
|
||||
<bool name="config_showUserSwitcherByDefault">false</bool>
|
||||
|
||||
<!-- Set to true to make assistant show in front of the dream/screensaver. -->
|
||||
<bool name="config_assistantOnTopOfDream">false</bool>
|
||||
|
||||
|
||||
@@ -4007,6 +4007,9 @@
|
||||
<!-- Set to true to enable the user switcher on the keyguard. -->
|
||||
<java-symbol type="bool" name="config_keyguardUserSwitcher" />
|
||||
|
||||
<!-- If true, show multiuser switcher by default unless the user specifically disables it. -->
|
||||
<java-symbol type="bool" name="config_showUserSwitcherByDefault" />
|
||||
|
||||
<!-- Set to true to make assistant show in front of the dream/screensaver. -->
|
||||
<java-symbol type="bool" name="config_assistantOnTopOfDream"/>
|
||||
|
||||
|
||||
@@ -18,10 +18,8 @@ package com.android.systemui.statusbar.phone;
|
||||
|
||||
import static com.android.systemui.DejankUtils.whitelistIpcs;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -97,33 +95,9 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
|
||||
}
|
||||
|
||||
public boolean isMultiUserEnabled() {
|
||||
// Short-circuiting from UserManager. Needs to be extracted because of SystemUI boolean flag
|
||||
// qs_show_user_switcher_for_single_user
|
||||
|
||||
// TODO(b/138661450) Move IPC calls to background
|
||||
return whitelistIpcs(() -> {
|
||||
// The default in UserManager is to show the switcher. We want to not show it unless the
|
||||
// user explicitly requests it in Settings
|
||||
final boolean userSwitcherEnabled = Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.USER_SWITCHER_ENABLED, 0) != 0;
|
||||
|
||||
if (!userSwitcherEnabled
|
||||
|| !UserManager.supportsMultipleUsers()
|
||||
|| UserManager.isDeviceInDemoMode(mContext)
|
||||
|| mUserManager.hasUserRestriction(UserManager.DISALLOW_USER_SWITCH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
|
||||
.getGuestUserDisabled(null);
|
||||
return mUserSwitcherController.getSwitchableUserCount() > 1
|
||||
// If we cannot add guests even if they are enabled, do not show
|
||||
|| (guestEnabled && !mUserManager.hasUserRestriction(
|
||||
UserManager.DISALLOW_ADD_USER))
|
||||
|| mContext.getResources().getBoolean(
|
||||
R.bool.qs_show_user_switcher_for_single_user);
|
||||
});
|
||||
return whitelistIpcs(() -> mUserManager.isUserSwitcherEnabled(
|
||||
mContext.getResources().getBoolean(R.bool.qs_show_user_switcher_for_single_user)));
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
@@ -175,7 +149,7 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
|
||||
private void refreshContentDescription() {
|
||||
String currentUser = null;
|
||||
// TODO(b/138661450)
|
||||
if (whitelistIpcs(mUserManager::isUserSwitcherEnabled)
|
||||
if (whitelistIpcs(() -> mUserManager.isUserSwitcherEnabled())
|
||||
&& mUserSwitcherController != null) {
|
||||
currentUser = mUserSwitcherController.getCurrentUserName(mContext);
|
||||
}
|
||||
|
||||
@@ -409,18 +409,6 @@ public class UserSwitcherController implements Dumpable {
|
||||
Log.e(TAG, "Couldn't switch to user, id=" + userId);
|
||||
}
|
||||
|
||||
public int getSwitchableUserCount() {
|
||||
int count = 0;
|
||||
final int N = mUsers.size();
|
||||
for (int i = 0; i < N; ++i) {
|
||||
UserRecord record = mUsers.get(i);
|
||||
if (record.info != null && record.info.supportsSwitchToByUser()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
protected void switchToUserId(int id) {
|
||||
try {
|
||||
pauseRefreshUsers();
|
||||
|
||||
@@ -3507,7 +3507,7 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
Slog.w(LOG_TAG, "could not start pre-created user " + userId, e);
|
||||
}
|
||||
} else {
|
||||
dispatchUserAddedIntent(userInfo);
|
||||
dispatchUserAdded(userInfo);
|
||||
}
|
||||
|
||||
} finally {
|
||||
@@ -3568,7 +3568,7 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
// Could not read the existing permissions, re-grant them.
|
||||
mPm.onNewUserCreated(preCreatedUser.id);
|
||||
}
|
||||
dispatchUserAddedIntent(preCreatedUser);
|
||||
dispatchUserAdded(preCreatedUser);
|
||||
return preCreatedUser;
|
||||
}
|
||||
|
||||
@@ -3600,7 +3600,7 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
return (now > EPOCH_PLUS_30_YEARS) ? now : 0;
|
||||
}
|
||||
|
||||
private void dispatchUserAddedIntent(@NonNull UserInfo userInfo) {
|
||||
private void dispatchUserAdded(@NonNull UserInfo userInfo) {
|
||||
Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
|
||||
addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id);
|
||||
// Also, add the UserHandle for mainline modules which can't use the @hide
|
||||
@@ -3610,6 +3610,15 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
android.Manifest.permission.MANAGE_USERS);
|
||||
MetricsLogger.count(mContext, userInfo.isGuest() ? TRON_GUEST_CREATED
|
||||
: (userInfo.isDemo() ? TRON_DEMO_CREATED : TRON_USER_CREATED), 1);
|
||||
|
||||
if (!userInfo.isProfile()) {
|
||||
// If the user switch hasn't been explicitly toggled on or off by the user, turn it on.
|
||||
if (android.provider.Settings.Global.getString(mContext.getContentResolver(),
|
||||
android.provider.Settings.Global.USER_SWITCHER_ENABLED) == null) {
|
||||
android.provider.Settings.Global.putInt(mContext.getContentResolver(),
|
||||
android.provider.Settings.Global.USER_SWITCHER_ENABLED, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user