Loading core/java/android/os/IUserManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ interface IUserManager { List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated); List<UserInfo> getProfiles(int userId, boolean enabledOnly); int[] getProfileIds(int userId, boolean enabledOnly); boolean canAddMoreUsersOfType(in String userType); boolean canAddMoreProfilesToUser(in String userType, int userId, boolean allowedToRemoveOne); boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne); UserInfo getProfileParent(int userId); Loading core/java/android/os/UserManager.java +28 −3 Original line number Diff line number Diff line Loading @@ -3854,13 +3854,19 @@ public class UserManager { } /** * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS * permission. * Checks whether it's possible to add more users. * * @return true if more users can be added, false if limit has been reached. * * @deprecated use {@link #canAddMoreUsers(String)} instead. * * @hide */ @RequiresPermission(android.Manifest.permission.MANAGE_USERS) @Deprecated @RequiresPermission(anyOf = { android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS }) public boolean canAddMoreUsers() { // TODO(b/142482943): UMS has different logic, excluding Demo and Profile from counting. Why // not here? The logic is inconsistent. See UMS.canAddMoreManagedProfiles Loading @@ -3876,6 +3882,25 @@ public class UserManager { return aliveUserCount < getMaxSupportedUsers(); } /** * Checks whether it is possible to add more users of the given user type. * * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_SECONDARY}. * @return true if more users of the given type can be added, otherwise false. * @hide */ @RequiresPermission(anyOf = { android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS }) public boolean canAddMoreUsers(@NonNull String userType) { try { return canAddMoreUsers() && mService.canAddMoreUsersOfType(userType); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } /** * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS * permission. Loading core/java/com/android/internal/app/ConfirmUserCreationActivity.java +4 −4 Original line number Diff line number Diff line Loading @@ -23,12 +23,10 @@ import android.accounts.AccountManager; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.PersistableBundle; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; Loading @@ -44,6 +42,8 @@ public class ConfirmUserCreationActivity extends AlertActivity private static final String TAG = "CreateUser"; private static final String USER_TYPE = UserManager.USER_TYPE_FULL_SECONDARY; private String mUserName; private String mAccountName; private String mAccountType; Loading Loading @@ -103,7 +103,7 @@ public class ConfirmUserCreationActivity extends AlertActivity boolean cantCreateUser = mUserManager.hasUserRestriction(UserManager.DISALLOW_ADD_USER) || !mUserManager.isAdminUser(); // Check the system state and user count boolean cantCreateAnyMoreUsers = !mUserManager.canAddMoreUsers(); boolean cantCreateAnyMoreUsers = !mUserManager.canAddMoreUsers(USER_TYPE); // Check the account existence final Account account = new Account(mAccountName, mAccountType); boolean accountExists = mAccountName != null && mAccountType != null Loading @@ -130,7 +130,7 @@ public class ConfirmUserCreationActivity extends AlertActivity setResult(RESULT_CANCELED); if (which == BUTTON_POSITIVE && mCanProceed) { Log.i(TAG, "Ok, creating user"); UserInfo user = mUserManager.createUser(mUserName, 0); UserInfo user = mUserManager.createUser(mUserName, USER_TYPE, 0); if (user == null) { Log.e(TAG, "Couldn't create user"); finish(); Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +1 −1 Original line number Diff line number Diff line Loading @@ -351,7 +351,7 @@ public class UserSwitcherController implements Dumpable { boolean canCreateGuest = (currentUserCanCreateUsers || anyoneCanCreateUsers) && guestRecord == null; boolean canCreateUser = (currentUserCanCreateUsers || anyoneCanCreateUsers) && mUserManager.canAddMoreUsers(); && mUserManager.canAddMoreUsers(UserManager.USER_TYPE_FULL_SECONDARY); boolean createIsRestricted = !addUsersWhenLocked; if (guestRecord == null) { Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/UserSwitcherControllerTest.kt +2 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { mContext.addMockSystemService(Context.FINGERPRINT_SERVICE, mock(FingerprintManager::class.java)) `when`(userManager.canAddMoreUsers()).thenReturn(true) `when`(userManager.canAddMoreUsers(eq(UserManager.USER_TYPE_FULL_SECONDARY))) .thenReturn(true) `when`(notificationShadeWindowView.context).thenReturn(context) userSwitcherController = UserSwitcherController( Loading Loading
core/java/android/os/IUserManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ interface IUserManager { List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated); List<UserInfo> getProfiles(int userId, boolean enabledOnly); int[] getProfileIds(int userId, boolean enabledOnly); boolean canAddMoreUsersOfType(in String userType); boolean canAddMoreProfilesToUser(in String userType, int userId, boolean allowedToRemoveOne); boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne); UserInfo getProfileParent(int userId); Loading
core/java/android/os/UserManager.java +28 −3 Original line number Diff line number Diff line Loading @@ -3854,13 +3854,19 @@ public class UserManager { } /** * Checks whether it's possible to add more users. Caller must hold the MANAGE_USERS * permission. * Checks whether it's possible to add more users. * * @return true if more users can be added, false if limit has been reached. * * @deprecated use {@link #canAddMoreUsers(String)} instead. * * @hide */ @RequiresPermission(android.Manifest.permission.MANAGE_USERS) @Deprecated @RequiresPermission(anyOf = { android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS }) public boolean canAddMoreUsers() { // TODO(b/142482943): UMS has different logic, excluding Demo and Profile from counting. Why // not here? The logic is inconsistent. See UMS.canAddMoreManagedProfiles Loading @@ -3876,6 +3882,25 @@ public class UserManager { return aliveUserCount < getMaxSupportedUsers(); } /** * Checks whether it is possible to add more users of the given user type. * * @param userType the type of user, such as {@link UserManager#USER_TYPE_FULL_SECONDARY}. * @return true if more users of the given type can be added, otherwise false. * @hide */ @RequiresPermission(anyOf = { android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS }) public boolean canAddMoreUsers(@NonNull String userType) { try { return canAddMoreUsers() && mService.canAddMoreUsersOfType(userType); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } /** * Checks whether it's possible to add more managed profiles. Caller must hold the MANAGE_USERS * permission. Loading
core/java/com/android/internal/app/ConfirmUserCreationActivity.java +4 −4 Original line number Diff line number Diff line Loading @@ -23,12 +23,10 @@ import android.accounts.AccountManager; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.UserInfo; import android.os.Bundle; import android.os.PersistableBundle; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; Loading @@ -44,6 +42,8 @@ public class ConfirmUserCreationActivity extends AlertActivity private static final String TAG = "CreateUser"; private static final String USER_TYPE = UserManager.USER_TYPE_FULL_SECONDARY; private String mUserName; private String mAccountName; private String mAccountType; Loading Loading @@ -103,7 +103,7 @@ public class ConfirmUserCreationActivity extends AlertActivity boolean cantCreateUser = mUserManager.hasUserRestriction(UserManager.DISALLOW_ADD_USER) || !mUserManager.isAdminUser(); // Check the system state and user count boolean cantCreateAnyMoreUsers = !mUserManager.canAddMoreUsers(); boolean cantCreateAnyMoreUsers = !mUserManager.canAddMoreUsers(USER_TYPE); // Check the account existence final Account account = new Account(mAccountName, mAccountType); boolean accountExists = mAccountName != null && mAccountType != null Loading @@ -130,7 +130,7 @@ public class ConfirmUserCreationActivity extends AlertActivity setResult(RESULT_CANCELED); if (which == BUTTON_POSITIVE && mCanProceed) { Log.i(TAG, "Ok, creating user"); UserInfo user = mUserManager.createUser(mUserName, 0); UserInfo user = mUserManager.createUser(mUserName, USER_TYPE, 0); if (user == null) { Log.e(TAG, "Couldn't create user"); finish(); Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +1 −1 Original line number Diff line number Diff line Loading @@ -351,7 +351,7 @@ public class UserSwitcherController implements Dumpable { boolean canCreateGuest = (currentUserCanCreateUsers || anyoneCanCreateUsers) && guestRecord == null; boolean canCreateUser = (currentUserCanCreateUsers || anyoneCanCreateUsers) && mUserManager.canAddMoreUsers(); && mUserManager.canAddMoreUsers(UserManager.USER_TYPE_FULL_SECONDARY); boolean createIsRestricted = !addUsersWhenLocked; if (guestRecord == null) { Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/UserSwitcherControllerTest.kt +2 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,8 @@ class UserSwitcherControllerTest : SysuiTestCase() { mContext.addMockSystemService(Context.FINGERPRINT_SERVICE, mock(FingerprintManager::class.java)) `when`(userManager.canAddMoreUsers()).thenReturn(true) `when`(userManager.canAddMoreUsers(eq(UserManager.USER_TYPE_FULL_SECONDARY))) .thenReturn(true) `when`(notificationShadeWindowView.context).thenReturn(context) userSwitcherController = UserSwitcherController( Loading