Loading core/java/android/os/UserManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -1637,6 +1637,16 @@ public class UserManager { /** @hide */ public static final String SYSTEM_USER_MODE_EMULATION_HEADLESS = "headless"; /** * System Property used to override whether users can be created even if their type is disabled * or their limit is reached. Set value to 1 to enable. * * <p>Only used on non-user builds. * * @hide */ public static final String DEV_CREATE_OVERRIDE_PROPERTY = "debug.user.creation_override"; private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; /** Loading services/core/java/com/android/server/pm/UserManagerService.java +30 −27 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.pm; import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.os.UserManager.DEV_CREATE_OVERRIDE_PROPERTY; import static android.os.UserManager.DISALLOW_USER_SWITCH; import static android.os.UserManager.SYSTEM_USER_MODE_EMULATION_PROPERTY; Loading Loading @@ -2814,7 +2815,8 @@ public class UserManagerService extends IUserManager.Stub { synchronized (mUsersLock) { count = getAliveUsersExcludingGuestsCountLU(); } return count >= UserManager.getMaxSupportedUsers(); return count >= UserManager.getMaxSupportedUsers() && !isCreationOverrideEnabled(); } /** Loading @@ -2824,15 +2826,16 @@ public class UserManagerService extends IUserManager.Stub { * <p>For checking whether more profiles can be added to a particular parent use * {@link #canAddMoreProfilesToUser}. */ private boolean canAddMoreUsersOfType(UserTypeDetails userTypeDetails) { if (!userTypeDetails.isEnabled()) { private boolean canAddMoreUsersOfType(@NonNull UserTypeDetails userTypeDetails) { if (!isUserTypeEnabled(userTypeDetails)) { return false; } final int max = userTypeDetails.getMaxAllowed(); if (max == UserTypeDetails.UNLIMITED_NUMBER_OF_USERS) { return true; // Indicates that there is no max. } return getNumberOfUsersOfType(userTypeDetails.getName()) < max; return getNumberOfUsersOfType(userTypeDetails.getName()) < max || isCreationOverrideEnabled(); } /** Loading @@ -2843,7 +2846,7 @@ public class UserManagerService extends IUserManager.Stub { public int getRemainingCreatableUserCount(String userType) { checkQueryOrCreateUsersPermission("get the remaining number of users that can be added."); final UserTypeDetails type = mUserTypes.get(userType); if (type == null || !type.isEnabled()) { if (type == null || !isUserTypeEnabled(type)) { return 0; } synchronized (mUsersLock) { Loading Loading @@ -2917,7 +2920,21 @@ public class UserManagerService extends IUserManager.Stub { public boolean isUserTypeEnabled(String userType) { checkCreateUsersPermission("check if user type is enabled."); final UserTypeDetails userTypeDetails = mUserTypes.get(userType); return userTypeDetails != null && userTypeDetails.isEnabled(); return userTypeDetails != null && isUserTypeEnabled(userTypeDetails); } /** Returns whether the creation of users of the given user type is enabled on this device. */ private boolean isUserTypeEnabled(@NonNull UserTypeDetails userTypeDetails) { return userTypeDetails.isEnabled() || isCreationOverrideEnabled(); } /** * Returns whether to almost-always allow creating users even beyond their limit or if disabled. * For Debug builds only. */ private boolean isCreationOverrideEnabled() { return Build.isDebuggable() && SystemProperties.getBoolean(DEV_CREATE_OVERRIDE_PROPERTY, false); } @Override Loading @@ -2930,7 +2947,8 @@ public class UserManagerService extends IUserManager.Stub { @Override public boolean canAddMoreProfilesToUser(String userType, @UserIdInt int userId, boolean allowedToRemoveOne) { return 0 < getRemainingCreatableProfileCount(userType, userId, allowedToRemoveOne); return 0 < getRemainingCreatableProfileCount(userType, userId, allowedToRemoveOne) || isCreationOverrideEnabled(); } @Override Loading @@ -2948,7 +2966,7 @@ public class UserManagerService extends IUserManager.Stub { checkQueryOrCreateUsersPermission( "get the remaining number of profiles that can be added to the given user."); final UserTypeDetails type = mUserTypes.get(userType); if (type == null || !type.isEnabled()) { if (type == null || !isUserTypeEnabled(type)) { return 0; } // Managed profiles have their own specific rules. Loading Loading @@ -4407,7 +4425,7 @@ public class UserManagerService extends IUserManager.Stub { + ") indicated SYSTEM user, which cannot be created."); return null; } if (!userTypeDetails.isEnabled()) { if (!isUserTypeEnabled(userTypeDetails)) { throwCheckedUserOperationException( "Cannot add a user of disabled type " + userType + ".", UserManager.USER_OPERATION_ERROR_MAX_USERS); Loading Loading @@ -4479,27 +4497,12 @@ public class UserManagerService extends IUserManager.Stub { + " for user " + parentId, UserManager.USER_OPERATION_ERROR_MAX_USERS); } // In legacy mode, restricted profile's parent can only be the owner user if (isRestricted && !UserManager.isSplitSystemUser() && (parentId != UserHandle.USER_SYSTEM)) { if (isRestricted && (parentId != UserHandle.USER_SYSTEM) && !isCreationOverrideEnabled()) { throwCheckedUserOperationException( "Cannot add restricted profile - parent user must be owner", "Cannot add restricted profile - parent user must be system", UserManager.USER_OPERATION_ERROR_UNKNOWN); } if (isRestricted && UserManager.isSplitSystemUser()) { if (parent == null) { throwCheckedUserOperationException( "Cannot add restricted profile - parent user must be specified", UserManager.USER_OPERATION_ERROR_UNKNOWN); } if (!parent.info.canHaveProfile()) { throwCheckedUserOperationException( "Cannot add restricted profile - profiles cannot be created for " + "the specified parent user id " + parentId, UserManager.USER_OPERATION_ERROR_UNKNOWN); } } userId = getNextAvailableId(); Slog.i(LOG_TAG, "Creating user " + userId + " of type " + userType); Loading Loading
core/java/android/os/UserManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -1637,6 +1637,16 @@ public class UserManager { /** @hide */ public static final String SYSTEM_USER_MODE_EMULATION_HEADLESS = "headless"; /** * System Property used to override whether users can be created even if their type is disabled * or their limit is reached. Set value to 1 to enable. * * <p>Only used on non-user builds. * * @hide */ public static final String DEV_CREATE_OVERRIDE_PROPERTY = "debug.user.creation_override"; private static final String ACTION_CREATE_USER = "android.os.action.CREATE_USER"; /** Loading
services/core/java/com/android/server/pm/UserManagerService.java +30 −27 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.pm; import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.os.UserManager.DEV_CREATE_OVERRIDE_PROPERTY; import static android.os.UserManager.DISALLOW_USER_SWITCH; import static android.os.UserManager.SYSTEM_USER_MODE_EMULATION_PROPERTY; Loading Loading @@ -2814,7 +2815,8 @@ public class UserManagerService extends IUserManager.Stub { synchronized (mUsersLock) { count = getAliveUsersExcludingGuestsCountLU(); } return count >= UserManager.getMaxSupportedUsers(); return count >= UserManager.getMaxSupportedUsers() && !isCreationOverrideEnabled(); } /** Loading @@ -2824,15 +2826,16 @@ public class UserManagerService extends IUserManager.Stub { * <p>For checking whether more profiles can be added to a particular parent use * {@link #canAddMoreProfilesToUser}. */ private boolean canAddMoreUsersOfType(UserTypeDetails userTypeDetails) { if (!userTypeDetails.isEnabled()) { private boolean canAddMoreUsersOfType(@NonNull UserTypeDetails userTypeDetails) { if (!isUserTypeEnabled(userTypeDetails)) { return false; } final int max = userTypeDetails.getMaxAllowed(); if (max == UserTypeDetails.UNLIMITED_NUMBER_OF_USERS) { return true; // Indicates that there is no max. } return getNumberOfUsersOfType(userTypeDetails.getName()) < max; return getNumberOfUsersOfType(userTypeDetails.getName()) < max || isCreationOverrideEnabled(); } /** Loading @@ -2843,7 +2846,7 @@ public class UserManagerService extends IUserManager.Stub { public int getRemainingCreatableUserCount(String userType) { checkQueryOrCreateUsersPermission("get the remaining number of users that can be added."); final UserTypeDetails type = mUserTypes.get(userType); if (type == null || !type.isEnabled()) { if (type == null || !isUserTypeEnabled(type)) { return 0; } synchronized (mUsersLock) { Loading Loading @@ -2917,7 +2920,21 @@ public class UserManagerService extends IUserManager.Stub { public boolean isUserTypeEnabled(String userType) { checkCreateUsersPermission("check if user type is enabled."); final UserTypeDetails userTypeDetails = mUserTypes.get(userType); return userTypeDetails != null && userTypeDetails.isEnabled(); return userTypeDetails != null && isUserTypeEnabled(userTypeDetails); } /** Returns whether the creation of users of the given user type is enabled on this device. */ private boolean isUserTypeEnabled(@NonNull UserTypeDetails userTypeDetails) { return userTypeDetails.isEnabled() || isCreationOverrideEnabled(); } /** * Returns whether to almost-always allow creating users even beyond their limit or if disabled. * For Debug builds only. */ private boolean isCreationOverrideEnabled() { return Build.isDebuggable() && SystemProperties.getBoolean(DEV_CREATE_OVERRIDE_PROPERTY, false); } @Override Loading @@ -2930,7 +2947,8 @@ public class UserManagerService extends IUserManager.Stub { @Override public boolean canAddMoreProfilesToUser(String userType, @UserIdInt int userId, boolean allowedToRemoveOne) { return 0 < getRemainingCreatableProfileCount(userType, userId, allowedToRemoveOne); return 0 < getRemainingCreatableProfileCount(userType, userId, allowedToRemoveOne) || isCreationOverrideEnabled(); } @Override Loading @@ -2948,7 +2966,7 @@ public class UserManagerService extends IUserManager.Stub { checkQueryOrCreateUsersPermission( "get the remaining number of profiles that can be added to the given user."); final UserTypeDetails type = mUserTypes.get(userType); if (type == null || !type.isEnabled()) { if (type == null || !isUserTypeEnabled(type)) { return 0; } // Managed profiles have their own specific rules. Loading Loading @@ -4407,7 +4425,7 @@ public class UserManagerService extends IUserManager.Stub { + ") indicated SYSTEM user, which cannot be created."); return null; } if (!userTypeDetails.isEnabled()) { if (!isUserTypeEnabled(userTypeDetails)) { throwCheckedUserOperationException( "Cannot add a user of disabled type " + userType + ".", UserManager.USER_OPERATION_ERROR_MAX_USERS); Loading Loading @@ -4479,27 +4497,12 @@ public class UserManagerService extends IUserManager.Stub { + " for user " + parentId, UserManager.USER_OPERATION_ERROR_MAX_USERS); } // In legacy mode, restricted profile's parent can only be the owner user if (isRestricted && !UserManager.isSplitSystemUser() && (parentId != UserHandle.USER_SYSTEM)) { if (isRestricted && (parentId != UserHandle.USER_SYSTEM) && !isCreationOverrideEnabled()) { throwCheckedUserOperationException( "Cannot add restricted profile - parent user must be owner", "Cannot add restricted profile - parent user must be system", UserManager.USER_OPERATION_ERROR_UNKNOWN); } if (isRestricted && UserManager.isSplitSystemUser()) { if (parent == null) { throwCheckedUserOperationException( "Cannot add restricted profile - parent user must be specified", UserManager.USER_OPERATION_ERROR_UNKNOWN); } if (!parent.info.canHaveProfile()) { throwCheckedUserOperationException( "Cannot add restricted profile - profiles cannot be created for " + "the specified parent user id " + parentId, UserManager.USER_OPERATION_ERROR_UNKNOWN); } } userId = getNextAvailableId(); Slog.i(LOG_TAG, "Creating user " + userId + " of type " + userType); Loading