Loading core/java/android/content/pm/UserInfo.java +11 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,17 @@ public class UserInfo implements Parcelable { return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); } /* @hide */ public boolean canHaveProfile() { if (isManagedProfile() || isGuest() || isRestricted()) { return false; } if (UserManager.isSplitSystemUser()) { return id != UserHandle.USER_SYSTEM; } return id == UserHandle.USER_OWNER; } public UserInfo() { } Loading core/java/android/os/IUserManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ interface IUserManager { UserInfo getPrimaryUser(); List<UserInfo> getUsers(boolean excludeDying); List<UserInfo> getProfiles(int userHandle, boolean enabledOnly); boolean canAddMoreManagedProfiles(); boolean canAddMoreManagedProfiles(int userId); UserInfo getProfileParent(int userHandle); UserInfo getUserInfo(int userHandle); long getUserCreationTime(int userHandle); Loading core/java/android/os/UserManager.java +2 −2 Original line number Diff line number Diff line Loading @@ -1024,9 +1024,9 @@ public class UserManager { * @return true if more managed profiles can be added, false if limit has been reached. * @hide */ public boolean canAddMoreManagedProfiles() { public boolean canAddMoreManagedProfiles(int userId) { try { return mService.canAddMoreManagedProfiles(); return mService.canAddMoreManagedProfiles(userId); } catch (RemoteException re) { Log.w(TAG, "Could not check if we can add more managed profiles", re); return false; Loading services/core/java/com/android/server/pm/UserManagerService.java +11 −10 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ public class UserManagerService extends IUserManager.Stub { private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms // Maximum number of managed profiles permitted is 1. This cannot be increased // Maximum number of managed profiles permitted per user is 1. This cannot be increased // without first making sure that the rest of the framework is prepared for it. private static final int MAX_MANAGED_PROFILES = 1; Loading Loading @@ -627,7 +627,7 @@ public class UserManagerService extends IUserManager.Stub { } @Override public boolean canAddMoreManagedProfiles() { public boolean canAddMoreManagedProfiles(int userId) { checkManageUsersPermission("check if more managed profiles can be added."); if (ActivityManager.isLowRamDeviceStatic()) { return false; Loading @@ -636,10 +636,14 @@ public class UserManagerService extends IUserManager.Stub { PackageManager.FEATURE_MANAGED_USERS)) { return false; } synchronized(mPackagesLock) { // Limit number of managed profiles that can be created if (numberOfUsersOfTypeLocked(UserInfo.FLAG_MANAGED_PROFILE, true) >= MAX_MANAGED_PROFILES) { int managedProfilesCount = getProfiles(userId, true).size() - 1; if (managedProfilesCount >= MAX_MANAGED_PROFILES) { return false; } synchronized(mPackagesLock) { UserInfo userInfo = getUserInfoLocked(userId); if (!userInfo.canHaveProfile()) { return false; } int usersCount = getAliveUsersExcludingGuestsCountLocked(); Loading Loading @@ -1238,10 +1242,6 @@ public class UserManagerService extends IUserManager.Stub { @Override public UserInfo createProfileForUser(String name, int flags, int userId) { checkManageUsersPermission("Only the system can create users"); if (userId != UserHandle.USER_OWNER) { Slog.w(LOG_TAG, "Only user owner can have profiles"); return null; } return createUserInternal(name, flags, userId); } Loading Loading @@ -1273,7 +1273,8 @@ public class UserManagerService extends IUserManager.Stub { parent = getUserInfoLocked(parentId); if (parent == null) return null; } if (isManagedProfile && !canAddMoreManagedProfiles()) { if (isManagedProfile && !canAddMoreManagedProfiles(parentId)) { Log.e(LOG_TAG, "Cannot add more managed profiles for user " + parentId); return null; } if (!isGuest && !isManagedProfile && isUserLimitReachedLocked()) { Loading Loading
core/java/android/content/pm/UserInfo.java +11 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,17 @@ public class UserInfo implements Parcelable { return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); } /* @hide */ public boolean canHaveProfile() { if (isManagedProfile() || isGuest() || isRestricted()) { return false; } if (UserManager.isSplitSystemUser()) { return id != UserHandle.USER_SYSTEM; } return id == UserHandle.USER_OWNER; } public UserInfo() { } Loading
core/java/android/os/IUserManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ interface IUserManager { UserInfo getPrimaryUser(); List<UserInfo> getUsers(boolean excludeDying); List<UserInfo> getProfiles(int userHandle, boolean enabledOnly); boolean canAddMoreManagedProfiles(); boolean canAddMoreManagedProfiles(int userId); UserInfo getProfileParent(int userHandle); UserInfo getUserInfo(int userHandle); long getUserCreationTime(int userHandle); Loading
core/java/android/os/UserManager.java +2 −2 Original line number Diff line number Diff line Loading @@ -1024,9 +1024,9 @@ public class UserManager { * @return true if more managed profiles can be added, false if limit has been reached. * @hide */ public boolean canAddMoreManagedProfiles() { public boolean canAddMoreManagedProfiles(int userId) { try { return mService.canAddMoreManagedProfiles(); return mService.canAddMoreManagedProfiles(userId); } catch (RemoteException re) { Log.w(TAG, "Could not check if we can add more managed profiles", re); return false; Loading
services/core/java/com/android/server/pm/UserManagerService.java +11 −10 Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ public class UserManagerService extends IUserManager.Stub { private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms // Maximum number of managed profiles permitted is 1. This cannot be increased // Maximum number of managed profiles permitted per user is 1. This cannot be increased // without first making sure that the rest of the framework is prepared for it. private static final int MAX_MANAGED_PROFILES = 1; Loading Loading @@ -627,7 +627,7 @@ public class UserManagerService extends IUserManager.Stub { } @Override public boolean canAddMoreManagedProfiles() { public boolean canAddMoreManagedProfiles(int userId) { checkManageUsersPermission("check if more managed profiles can be added."); if (ActivityManager.isLowRamDeviceStatic()) { return false; Loading @@ -636,10 +636,14 @@ public class UserManagerService extends IUserManager.Stub { PackageManager.FEATURE_MANAGED_USERS)) { return false; } synchronized(mPackagesLock) { // Limit number of managed profiles that can be created if (numberOfUsersOfTypeLocked(UserInfo.FLAG_MANAGED_PROFILE, true) >= MAX_MANAGED_PROFILES) { int managedProfilesCount = getProfiles(userId, true).size() - 1; if (managedProfilesCount >= MAX_MANAGED_PROFILES) { return false; } synchronized(mPackagesLock) { UserInfo userInfo = getUserInfoLocked(userId); if (!userInfo.canHaveProfile()) { return false; } int usersCount = getAliveUsersExcludingGuestsCountLocked(); Loading Loading @@ -1238,10 +1242,6 @@ public class UserManagerService extends IUserManager.Stub { @Override public UserInfo createProfileForUser(String name, int flags, int userId) { checkManageUsersPermission("Only the system can create users"); if (userId != UserHandle.USER_OWNER) { Slog.w(LOG_TAG, "Only user owner can have profiles"); return null; } return createUserInternal(name, flags, userId); } Loading Loading @@ -1273,7 +1273,8 @@ public class UserManagerService extends IUserManager.Stub { parent = getUserInfoLocked(parentId); if (parent == null) return null; } if (isManagedProfile && !canAddMoreManagedProfiles()) { if (isManagedProfile && !canAddMoreManagedProfiles(parentId)) { Log.e(LOG_TAG, "Cannot add more managed profiles for user " + parentId); return null; } if (!isGuest && !isManagedProfile && isUserLimitReachedLocked()) { Loading