Loading core/java/android/content/pm/UserInfo.java +10 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; /** * Per-user information. Loading Loading @@ -135,6 +136,15 @@ public class UserInfo implements Parcelable { return !isManagedProfile() || SystemProperties.getBoolean("fw.show_hidden_users", false); } /** * @return true if this user can be switched to by end user through UI. */ public boolean supportsSwitchToByUser() { // Hide the system user when it does not represent a human user. boolean hideSystemUser = UserManager.isSplitSystemUser(); return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); } public UserInfo() { } Loading core/java/android/os/UserManager.java +13 −2 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package android.os; import android.annotation.Nullable; import android.annotation.SystemApi; import android.app.ActivityManager; import android.app.ActivityManagerNative; Loading Loading @@ -521,6 +522,16 @@ public class UserManager { Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); } /** * @hide * @return Whether the device is running with split system user. It means the system user and * primary user are two separate users. Previously system user and primary user are combined as * a single owner user. see @link {android.os.UserHandle#USER_OWNER} */ public static boolean isSplitSystemUser() { return SystemProperties.getBoolean("ro.fw.system_user_split", false); } /** * Returns the user handle for the user that this process is running under. * Loading Loading @@ -986,7 +997,7 @@ public class UserManager { * @return the Primary user, null if not found. * @hide */ public UserInfo getPrimaryUser() { public @Nullable UserInfo getPrimaryUser() { try { return mService.getPrimaryUser(); } catch (RemoteException re) { Loading Loading @@ -1293,7 +1304,7 @@ public class UserManager { } int switchableUserCount = 0; for (UserInfo user : users) { if (user.supportsSwitchTo()) { if (user.supportsSwitchToByUser()) { ++switchableUserCount; } } Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +20 −13 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ public class UserSwitcherController { private ArrayList<UserRecord> mUsers = new ArrayList<>(); private Dialog mExitGuestDialog; private Dialog mAddUserDialog; private int mLastNonGuestUser = UserHandle.USER_OWNER; private int mLastNonGuestUser = UserHandle.USER_SYSTEM; private boolean mSimpleUserSwitcher; private boolean mAddUsersWhenLocked; Loading @@ -95,7 +95,7 @@ public class UserSwitcherController { filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(Intent.ACTION_USER_STOPPING); filter.addAction(ACTION_REMOVE_GUEST); mContext.registerReceiverAsUser(mReceiver, UserHandle.OWNER, filter, mContext.registerReceiverAsUser(mReceiver, UserHandle.SYSTEM, filter, null /* permission */, null /* scheduler */); Loading Loading @@ -146,17 +146,21 @@ public class UserSwitcherController { } ArrayList<UserRecord> records = new ArrayList<>(infos.size()); int currentId = ActivityManager.getCurrentUser(); UserInfo currentUserInfo = null; UserRecord guestRecord = null; int avatarSize = mContext.getResources() .getDimensionPixelSize(R.dimen.max_avatar_size); for (UserInfo info : infos) { boolean isCurrent = currentId == info.id; if (isCurrent) { currentUserInfo = info; } if (info.isGuest()) { guestRecord = new UserRecord(info, null /* picture */, true /* isGuest */, isCurrent, false /* isAddUser */, false /* isRestricted */); } else if (info.supportsSwitchTo()) { } else if (info.supportsSwitchToByUser()) { Bitmap picture = bitmaps.get(info.id); if (picture == null) { picture = mUserManager.getUserIcon(info.id); Loading @@ -172,11 +176,13 @@ public class UserSwitcherController { } } boolean ownerCanCreateUsers = !mUserManager.hasUserRestriction( UserManager.DISALLOW_ADD_USER, UserHandle.OWNER); boolean currentUserCanCreateUsers = (currentId == UserHandle.USER_OWNER) && ownerCanCreateUsers; boolean anyoneCanCreateUsers = ownerCanCreateUsers && addUsersWhenLocked; boolean systemCanCreateUsers = !mUserManager.hasUserRestriction( UserManager.DISALLOW_ADD_USER, UserHandle.SYSTEM); boolean currentUserCanCreateUsers = currentUserInfo != null && (currentUserInfo.isAdmin() || currentUserInfo.id == UserHandle.USER_SYSTEM) && systemCanCreateUsers; boolean anyoneCanCreateUsers = systemCanCreateUsers && addUsersWhenLocked; boolean canCreateGuest = (currentUserCanCreateUsers || anyoneCanCreateUsers) && guestRecord == null; boolean canCreateUser = (currentUserCanCreateUsers || anyoneCanCreateUsers) Loading Loading @@ -284,10 +290,10 @@ public class UserSwitcherController { } private void exitGuest(int id) { int newId = UserHandle.USER_OWNER; if (mLastNonGuestUser != UserHandle.USER_OWNER) { int newId = UserHandle.USER_SYSTEM; if (mLastNonGuestUser != UserHandle.USER_SYSTEM) { UserInfo info = mUserManager.getUserInfo(mLastNonGuestUser); if (info != null && info.isEnabled() && info.supportsSwitchTo()) { if (info != null && info.isEnabled() && info.supportsSwitchToByUser()) { newId = info.id; } } Loading Loading @@ -325,6 +331,7 @@ public class UserSwitcherController { } final int currentId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); final UserInfo userInfo = mUserManager.getUserInfo(currentId); final int N = mUsers.size(); for (int i = 0; i < N; i++) { UserRecord record = mUsers.get(i); Loading @@ -336,7 +343,7 @@ public class UserSwitcherController { if (shouldBeCurrent && !record.isGuest) { mLastNonGuestUser = record.info.id; } if (currentId != UserHandle.USER_OWNER && record.isRestricted) { if ((userInfo == null || !userInfo.isAdmin()) && record.isRestricted) { // Immediately remove restricted records in case the AsyncTask is too slow. mUsers.remove(i); i--; Loading @@ -354,7 +361,7 @@ public class UserSwitcherController { private void showGuestNotification(int guestUserId) { PendingIntent removeGuestPI = PendingIntent.getBroadcastAsUser(mContext, 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.OWNER); 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.SYSTEM); Notification notification = new Notification.Builder(mContext) .setVisibility(Notification.VISIBILITY_SECRET) .setPriority(Notification.PRIORITY_MIN) Loading services/core/java/com/android/server/policy/GlobalActions.java +1 −1 Original line number Diff line number Diff line Loading @@ -534,7 +534,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac List<UserInfo> users = um.getUsers(); UserInfo currentUser = getCurrentUser(); for (final UserInfo user : users) { if (user.supportsSwitchTo()) { if (user.supportsSwitchToByUser()) { boolean isCurrentUser = currentUser == null ? user.id == 0 : (currentUser.id == user.id); Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) Loading services/core/java/com/android/server/trust/TrustManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ public class TrustManagerService extends SystemService { for (UserInfo userInfo : userInfos) { if (userInfo == null || userInfo.partial || !userInfo.isEnabled() || userInfo.guestToRemove) continue; if (!userInfo.supportsSwitchTo()) continue; if (!userInfo.supportsSwitchToByUser()) continue; if (!mActivityManager.isUserRunning(userInfo.id)) continue; if (!lockPatternUtils.isSecure(userInfo.id)) continue; if (!getUserHasAuthenticated(userInfo.id)) continue; Loading Loading @@ -316,7 +316,7 @@ public class TrustManagerService extends SystemService { UserInfo info = userInfos.get(i); if (info == null || info.partial || !info.isEnabled() || info.guestToRemove || !info.supportsSwitchTo()) { || !info.supportsSwitchToByUser()) { continue; } Loading Loading @@ -783,7 +783,7 @@ public class TrustManagerService extends SystemService { private void dumpUser(PrintWriter fout, UserInfo user, boolean isCurrent) { fout.printf(" User \"%s\" (id=%d, flags=%#x)", user.name, user.id, user.flags); if (!user.supportsSwitchTo()) { if (!user.supportsSwitchToByUser()) { fout.println("(managed profile)"); fout.println(" disabled because switching to this user is not possible."); return; Loading Loading
core/java/android/content/pm/UserInfo.java +10 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; /** * Per-user information. Loading Loading @@ -135,6 +136,15 @@ public class UserInfo implements Parcelable { return !isManagedProfile() || SystemProperties.getBoolean("fw.show_hidden_users", false); } /** * @return true if this user can be switched to by end user through UI. */ public boolean supportsSwitchToByUser() { // Hide the system user when it does not represent a human user. boolean hideSystemUser = UserManager.isSplitSystemUser(); return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); } public UserInfo() { } Loading
core/java/android/os/UserManager.java +13 −2 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package android.os; import android.annotation.Nullable; import android.annotation.SystemApi; import android.app.ActivityManager; import android.app.ActivityManagerNative; Loading Loading @@ -521,6 +522,16 @@ public class UserManager { Resources.getSystem().getBoolean(R.bool.config_enableMultiUserUI)); } /** * @hide * @return Whether the device is running with split system user. It means the system user and * primary user are two separate users. Previously system user and primary user are combined as * a single owner user. see @link {android.os.UserHandle#USER_OWNER} */ public static boolean isSplitSystemUser() { return SystemProperties.getBoolean("ro.fw.system_user_split", false); } /** * Returns the user handle for the user that this process is running under. * Loading Loading @@ -986,7 +997,7 @@ public class UserManager { * @return the Primary user, null if not found. * @hide */ public UserInfo getPrimaryUser() { public @Nullable UserInfo getPrimaryUser() { try { return mService.getPrimaryUser(); } catch (RemoteException re) { Loading Loading @@ -1293,7 +1304,7 @@ public class UserManager { } int switchableUserCount = 0; for (UserInfo user : users) { if (user.supportsSwitchTo()) { if (user.supportsSwitchToByUser()) { ++switchableUserCount; } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +20 −13 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ public class UserSwitcherController { private ArrayList<UserRecord> mUsers = new ArrayList<>(); private Dialog mExitGuestDialog; private Dialog mAddUserDialog; private int mLastNonGuestUser = UserHandle.USER_OWNER; private int mLastNonGuestUser = UserHandle.USER_SYSTEM; private boolean mSimpleUserSwitcher; private boolean mAddUsersWhenLocked; Loading @@ -95,7 +95,7 @@ public class UserSwitcherController { filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(Intent.ACTION_USER_STOPPING); filter.addAction(ACTION_REMOVE_GUEST); mContext.registerReceiverAsUser(mReceiver, UserHandle.OWNER, filter, mContext.registerReceiverAsUser(mReceiver, UserHandle.SYSTEM, filter, null /* permission */, null /* scheduler */); Loading Loading @@ -146,17 +146,21 @@ public class UserSwitcherController { } ArrayList<UserRecord> records = new ArrayList<>(infos.size()); int currentId = ActivityManager.getCurrentUser(); UserInfo currentUserInfo = null; UserRecord guestRecord = null; int avatarSize = mContext.getResources() .getDimensionPixelSize(R.dimen.max_avatar_size); for (UserInfo info : infos) { boolean isCurrent = currentId == info.id; if (isCurrent) { currentUserInfo = info; } if (info.isGuest()) { guestRecord = new UserRecord(info, null /* picture */, true /* isGuest */, isCurrent, false /* isAddUser */, false /* isRestricted */); } else if (info.supportsSwitchTo()) { } else if (info.supportsSwitchToByUser()) { Bitmap picture = bitmaps.get(info.id); if (picture == null) { picture = mUserManager.getUserIcon(info.id); Loading @@ -172,11 +176,13 @@ public class UserSwitcherController { } } boolean ownerCanCreateUsers = !mUserManager.hasUserRestriction( UserManager.DISALLOW_ADD_USER, UserHandle.OWNER); boolean currentUserCanCreateUsers = (currentId == UserHandle.USER_OWNER) && ownerCanCreateUsers; boolean anyoneCanCreateUsers = ownerCanCreateUsers && addUsersWhenLocked; boolean systemCanCreateUsers = !mUserManager.hasUserRestriction( UserManager.DISALLOW_ADD_USER, UserHandle.SYSTEM); boolean currentUserCanCreateUsers = currentUserInfo != null && (currentUserInfo.isAdmin() || currentUserInfo.id == UserHandle.USER_SYSTEM) && systemCanCreateUsers; boolean anyoneCanCreateUsers = systemCanCreateUsers && addUsersWhenLocked; boolean canCreateGuest = (currentUserCanCreateUsers || anyoneCanCreateUsers) && guestRecord == null; boolean canCreateUser = (currentUserCanCreateUsers || anyoneCanCreateUsers) Loading Loading @@ -284,10 +290,10 @@ public class UserSwitcherController { } private void exitGuest(int id) { int newId = UserHandle.USER_OWNER; if (mLastNonGuestUser != UserHandle.USER_OWNER) { int newId = UserHandle.USER_SYSTEM; if (mLastNonGuestUser != UserHandle.USER_SYSTEM) { UserInfo info = mUserManager.getUserInfo(mLastNonGuestUser); if (info != null && info.isEnabled() && info.supportsSwitchTo()) { if (info != null && info.isEnabled() && info.supportsSwitchToByUser()) { newId = info.id; } } Loading Loading @@ -325,6 +331,7 @@ public class UserSwitcherController { } final int currentId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); final UserInfo userInfo = mUserManager.getUserInfo(currentId); final int N = mUsers.size(); for (int i = 0; i < N; i++) { UserRecord record = mUsers.get(i); Loading @@ -336,7 +343,7 @@ public class UserSwitcherController { if (shouldBeCurrent && !record.isGuest) { mLastNonGuestUser = record.info.id; } if (currentId != UserHandle.USER_OWNER && record.isRestricted) { if ((userInfo == null || !userInfo.isAdmin()) && record.isRestricted) { // Immediately remove restricted records in case the AsyncTask is too slow. mUsers.remove(i); i--; Loading @@ -354,7 +361,7 @@ public class UserSwitcherController { private void showGuestNotification(int guestUserId) { PendingIntent removeGuestPI = PendingIntent.getBroadcastAsUser(mContext, 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.OWNER); 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.SYSTEM); Notification notification = new Notification.Builder(mContext) .setVisibility(Notification.VISIBILITY_SECRET) .setPriority(Notification.PRIORITY_MIN) Loading
services/core/java/com/android/server/policy/GlobalActions.java +1 −1 Original line number Diff line number Diff line Loading @@ -534,7 +534,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac List<UserInfo> users = um.getUsers(); UserInfo currentUser = getCurrentUser(); for (final UserInfo user : users) { if (user.supportsSwitchTo()) { if (user.supportsSwitchToByUser()) { boolean isCurrentUser = currentUser == null ? user.id == 0 : (currentUser.id == user.id); Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) Loading
services/core/java/com/android/server/trust/TrustManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -227,7 +227,7 @@ public class TrustManagerService extends SystemService { for (UserInfo userInfo : userInfos) { if (userInfo == null || userInfo.partial || !userInfo.isEnabled() || userInfo.guestToRemove) continue; if (!userInfo.supportsSwitchTo()) continue; if (!userInfo.supportsSwitchToByUser()) continue; if (!mActivityManager.isUserRunning(userInfo.id)) continue; if (!lockPatternUtils.isSecure(userInfo.id)) continue; if (!getUserHasAuthenticated(userInfo.id)) continue; Loading Loading @@ -316,7 +316,7 @@ public class TrustManagerService extends SystemService { UserInfo info = userInfos.get(i); if (info == null || info.partial || !info.isEnabled() || info.guestToRemove || !info.supportsSwitchTo()) { || !info.supportsSwitchToByUser()) { continue; } Loading Loading @@ -783,7 +783,7 @@ public class TrustManagerService extends SystemService { private void dumpUser(PrintWriter fout, UserInfo user, boolean isCurrent) { fout.printf(" User \"%s\" (id=%d, flags=%#x)", user.name, user.id, user.flags); if (!user.supportsSwitchTo()) { if (!user.supportsSwitchToByUser()) { fout.println("(managed profile)"); fout.println(" disabled because switching to this user is not possible."); return; Loading