Loading core/java/android/os/UserManager.java +44 −6 Original line number Diff line number Diff line Loading @@ -5502,12 +5502,16 @@ public class UserManager { Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}, conditional = true) public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { return enabledOnly ? getEnabledProfileIds(userId) : getProfileIdsWithDisabled(userId); } else { try { return mService.getProfileIds(userId, enabledOnly); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } } /** * @see #getProfileIds(int, boolean) Loading @@ -5518,9 +5522,15 @@ public class UserManager { Manifest.permission.MANAGE_USERS, Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}, conditional = true) @CachedProperty(api = "user_manager_users") public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { return UserManagerCache.getProfileIdsWithDisabled( (Integer userIdentifuer) -> mService.getProfileIds(userIdentifuer, false), userId); } else { return getProfileIds(userId, false /* enabledOnly */); } } /** * @see #getProfileIds(int, boolean) Loading @@ -5530,9 +5540,22 @@ public class UserManager { Manifest.permission.MANAGE_USERS, Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}, conditional = true) @CachedProperty(api = "user_manager_users_enabled") public int[] getEnabledProfileIds(@UserIdInt int userId) { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { return UserManagerCache.getEnabledProfileIds( (Integer userIdentifuer) -> mService.getProfileIds(userIdentifuer, true), userId); } else { return getProfileIds(userId, true /* enabledOnly */); } } /** @hide */ public static final void invalidateEnabledProfileIds() { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { UserManagerCache.invalidateEnabledProfileIds(); } } /** * @return A list of ids of profiles associated with the specified user excluding those with Loading Loading @@ -6443,6 +6466,21 @@ public class UserManager { if (android.multiuser.Flags.cacheProfileParentReadOnly()) { UserManagerCache.invalidateProfileParent(); } invalidateEnabledProfileIds(); } /** * Invalidate caches when related to specific user info flags change. * * @param flag a combination of FLAG_ constants, from the list in * {@link UserInfo#UserInfoFlag}, whose value has changed and the associated * invalidations must therefore be performed. * @hide */ public static final void invalidateOnUserInfoFlagChange(@UserInfoFlag int flags) { if ((flags & UserInfo.FLAG_DISABLED) > 0) { invalidateEnabledProfileIds(); } } /** Loading services/core/java/com/android/server/pm/UserManagerService.java +36 −6 Original line number Diff line number Diff line Loading @@ -1222,7 +1222,7 @@ public class UserManagerService extends IUserManager.Stub { // Mark the user for removal. addRemovingUserIdLocked(ui.id); ui.partial = true; ui.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(ui, UserInfo.FLAG_DISABLED); } /* Prunes out any partially created or partially removed users. */ Loading Loading @@ -1264,7 +1264,7 @@ public class UserManagerService extends IUserManager.Stub { if (ui.preCreated) { preCreatedUsers.add(ui); addRemovingUserIdLocked(ui.id); ui.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(ui, UserInfo.FLAG_DISABLED); ui.partial = true; } } Loading Loading @@ -2120,7 +2120,7 @@ public class UserManagerService extends IUserManager.Stub { info = getUserInfoLU(userId); if (info != null && !info.isEnabled()) { wasUserDisabled = true; info.flags ^= UserInfo.FLAG_DISABLED; removeUserInfoFlags(info, UserInfo.FLAG_DISABLED); writeUserLP(getUserDataLU(info.id)); } } Loading @@ -2130,6 +2130,36 @@ public class UserManagerService extends IUserManager.Stub { } } /** * This method is for monitoring flag changes on users flags and invalidate cache relevant to * the change. The method add flags and invalidateOnUserInfoFlagChange for the flags which * has changed. * @param userInfo of existing user in mUsers list * @param flags to be added to userInfo */ private void addUserInfoFlags(UserInfo userInfo, @UserInfoFlag int flags) { int diff = ~userInfo.flags & flags; if (diff > 0) { userInfo.flags |= diff; UserManager.invalidateOnUserInfoFlagChange(diff); } } /** * This method is for monitoring flag changes on users flags and invalidate cache relevant to * the change. The method remove flags and invalidateOnUserInfoFlagChange for the flags which * has changed. * @param userInfo of existing user in mUsers list * @param flags to be removed from userInfo */ private void removeUserInfoFlags(UserInfo userInfo, @UserInfoFlag int flags) { int diff = userInfo.flags & flags; if (diff > 0) { userInfo.flags ^= diff; UserManager.invalidateOnUserInfoFlagChange(diff); } } @Override public void setUserAdmin(@UserIdInt int userId) { checkManageUserAndAcrossUsersFullPermission("set user admin"); Loading Loading @@ -6245,7 +6275,7 @@ public class UserManagerService extends IUserManager.Stub { userData.info.guestToRemove = true; // Mark it as disabled, so that it isn't returned any more when // profiles are queried. userData.info.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(userData.info, UserInfo.FLAG_DISABLED); writeUserLP(userData); } } finally { Loading Loading @@ -6390,7 +6420,7 @@ public class UserManagerService extends IUserManager.Stub { } // Mark it as disabled, so that it isn't returned any more when // profiles are queried. userData.info.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(userData.info, UserInfo.FLAG_DISABLED); writeUserLP(userData); } Loading Loading @@ -7789,7 +7819,7 @@ public class UserManagerService extends IUserManager.Stub { if (userInfo != null && userInfo.isEphemeral()) { // Do not allow switching back to the ephemeral user again as the user is going // to be deleted. userInfo.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(userInfo, UserInfo.FLAG_DISABLED); if (userInfo.isGuest()) { // Indicate that the guest will be deleted after it stops. userInfo.guestToRemove = true; Loading Loading
core/java/android/os/UserManager.java +44 −6 Original line number Diff line number Diff line Loading @@ -5502,12 +5502,16 @@ public class UserManager { Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}, conditional = true) public @NonNull int[] getProfileIds(@UserIdInt int userId, boolean enabledOnly) { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { return enabledOnly ? getEnabledProfileIds(userId) : getProfileIdsWithDisabled(userId); } else { try { return mService.getProfileIds(userId, enabledOnly); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } } } /** * @see #getProfileIds(int, boolean) Loading @@ -5518,9 +5522,15 @@ public class UserManager { Manifest.permission.MANAGE_USERS, Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}, conditional = true) @CachedProperty(api = "user_manager_users") public int[] getProfileIdsWithDisabled(@UserIdInt int userId) { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { return UserManagerCache.getProfileIdsWithDisabled( (Integer userIdentifuer) -> mService.getProfileIds(userIdentifuer, false), userId); } else { return getProfileIds(userId, false /* enabledOnly */); } } /** * @see #getProfileIds(int, boolean) Loading @@ -5530,9 +5540,22 @@ public class UserManager { Manifest.permission.MANAGE_USERS, Manifest.permission.CREATE_USERS, Manifest.permission.QUERY_USERS}, conditional = true) @CachedProperty(api = "user_manager_users_enabled") public int[] getEnabledProfileIds(@UserIdInt int userId) { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { return UserManagerCache.getEnabledProfileIds( (Integer userIdentifuer) -> mService.getProfileIds(userIdentifuer, true), userId); } else { return getProfileIds(userId, true /* enabledOnly */); } } /** @hide */ public static final void invalidateEnabledProfileIds() { if (android.multiuser.Flags.cacheProfileIdsReadOnly()) { UserManagerCache.invalidateEnabledProfileIds(); } } /** * @return A list of ids of profiles associated with the specified user excluding those with Loading Loading @@ -6443,6 +6466,21 @@ public class UserManager { if (android.multiuser.Flags.cacheProfileParentReadOnly()) { UserManagerCache.invalidateProfileParent(); } invalidateEnabledProfileIds(); } /** * Invalidate caches when related to specific user info flags change. * * @param flag a combination of FLAG_ constants, from the list in * {@link UserInfo#UserInfoFlag}, whose value has changed and the associated * invalidations must therefore be performed. * @hide */ public static final void invalidateOnUserInfoFlagChange(@UserInfoFlag int flags) { if ((flags & UserInfo.FLAG_DISABLED) > 0) { invalidateEnabledProfileIds(); } } /** Loading
services/core/java/com/android/server/pm/UserManagerService.java +36 −6 Original line number Diff line number Diff line Loading @@ -1222,7 +1222,7 @@ public class UserManagerService extends IUserManager.Stub { // Mark the user for removal. addRemovingUserIdLocked(ui.id); ui.partial = true; ui.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(ui, UserInfo.FLAG_DISABLED); } /* Prunes out any partially created or partially removed users. */ Loading Loading @@ -1264,7 +1264,7 @@ public class UserManagerService extends IUserManager.Stub { if (ui.preCreated) { preCreatedUsers.add(ui); addRemovingUserIdLocked(ui.id); ui.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(ui, UserInfo.FLAG_DISABLED); ui.partial = true; } } Loading Loading @@ -2120,7 +2120,7 @@ public class UserManagerService extends IUserManager.Stub { info = getUserInfoLU(userId); if (info != null && !info.isEnabled()) { wasUserDisabled = true; info.flags ^= UserInfo.FLAG_DISABLED; removeUserInfoFlags(info, UserInfo.FLAG_DISABLED); writeUserLP(getUserDataLU(info.id)); } } Loading @@ -2130,6 +2130,36 @@ public class UserManagerService extends IUserManager.Stub { } } /** * This method is for monitoring flag changes on users flags and invalidate cache relevant to * the change. The method add flags and invalidateOnUserInfoFlagChange for the flags which * has changed. * @param userInfo of existing user in mUsers list * @param flags to be added to userInfo */ private void addUserInfoFlags(UserInfo userInfo, @UserInfoFlag int flags) { int diff = ~userInfo.flags & flags; if (diff > 0) { userInfo.flags |= diff; UserManager.invalidateOnUserInfoFlagChange(diff); } } /** * This method is for monitoring flag changes on users flags and invalidate cache relevant to * the change. The method remove flags and invalidateOnUserInfoFlagChange for the flags which * has changed. * @param userInfo of existing user in mUsers list * @param flags to be removed from userInfo */ private void removeUserInfoFlags(UserInfo userInfo, @UserInfoFlag int flags) { int diff = userInfo.flags & flags; if (diff > 0) { userInfo.flags ^= diff; UserManager.invalidateOnUserInfoFlagChange(diff); } } @Override public void setUserAdmin(@UserIdInt int userId) { checkManageUserAndAcrossUsersFullPermission("set user admin"); Loading Loading @@ -6245,7 +6275,7 @@ public class UserManagerService extends IUserManager.Stub { userData.info.guestToRemove = true; // Mark it as disabled, so that it isn't returned any more when // profiles are queried. userData.info.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(userData.info, UserInfo.FLAG_DISABLED); writeUserLP(userData); } } finally { Loading Loading @@ -6390,7 +6420,7 @@ public class UserManagerService extends IUserManager.Stub { } // Mark it as disabled, so that it isn't returned any more when // profiles are queried. userData.info.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(userData.info, UserInfo.FLAG_DISABLED); writeUserLP(userData); } Loading Loading @@ -7789,7 +7819,7 @@ public class UserManagerService extends IUserManager.Stub { if (userInfo != null && userInfo.isEphemeral()) { // Do not allow switching back to the ephemeral user again as the user is going // to be deleted. userInfo.flags |= UserInfo.FLAG_DISABLED; addUserInfoFlags(userInfo, UserInfo.FLAG_DISABLED); if (userInfo.isGuest()) { // Indicate that the guest will be deleted after it stops. userInfo.guestToRemove = true; Loading