Loading core/java/android/os/UserManager.java +31 −15 Original line number Diff line number Diff line Loading @@ -5326,7 +5326,9 @@ public class UserManager { } /** * Returns list of the profiles of userId including userId itself. * Returns a list of the users that are associated with userId, including userId itself. This * includes the user, its profiles, its parent, and its parent's other profiles, as applicable. * * Note that this returns both enabled and not enabled profiles. See * {@link #getEnabledProfiles(int)} if you need only the enabled ones. * <p>Note that this includes all profile types (not including Restricted profiles). Loading @@ -5334,7 +5336,7 @@ public class UserManager { * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} or * {@link android.Manifest.permission#CREATE_USERS} or * {@link android.Manifest.permission#QUERY_USERS} if userId is not the calling user. * @param userId profiles of this user will be returned. * @param userId profiles associated with this user (including itself) will be returned. * @return the list of profiles. * @hide */ Loading @@ -5358,12 +5360,13 @@ public class UserManager { } /** * Returns list of the profiles of the given user, including userId itself, as well as the * communal profile, if there is one. * Returns a list of the users that are associated with userId, including userId itself, * as well as the communal profile, if there is one. * * <p>Note that this returns both enabled and not enabled profiles. * <p>Note that this includes all profile types (not including Restricted profiles). * * @see #getProfiles(int) * @hide */ @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE) Loading Loading @@ -5419,7 +5422,10 @@ public class UserManager { } /** * Returns list of the profiles of userId including userId itself. * Returns a list of the enabled users that are associated with userId, including userId itself. * This includes the user, its profiles, its parent, and its parent's other profiles, as * applicable. * * Note that this returns only {@link UserInfo#isEnabled() enabled} profiles. * <p>Note that this includes all profile types (not including Restricted profiles). * Loading Loading @@ -5447,8 +5453,10 @@ public class UserManager { } /** * Returns a list of UserHandles for profiles associated with the context user, including the * user itself. * Returns a list of the users that are associated with the context user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @return A non-empty list of UserHandles associated with the context user. Loading @@ -5465,8 +5473,10 @@ public class UserManager { } /** * Returns a list of ids for enabled profiles associated with the context user including the * user itself. * Returns a list of the enabled users that are associated with the context user, including the * user itself. This includes the user, its profiles, its parent, and its parent's other * profiles, as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @return A non-empty list of UserHandles associated with the context user. Loading @@ -5483,8 +5493,10 @@ public class UserManager { } /** * Returns a list of ids for all profiles associated with the context user including the user * itself. * Returns a list of all users that are associated with the context user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @return A non-empty list of UserHandles associated with the context user. Loading @@ -5501,8 +5513,10 @@ public class UserManager { } /** * Returns a list of ids for profiles associated with the context user including the user * itself. * Returns a list of the users that are associated with the context user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, as * applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @param enabledOnly whether to return only {@link UserInfo#isEnabled() enabled} profiles Loading @@ -5528,8 +5542,10 @@ public class UserManager { } /** * Returns a list of ids for profiles associated with the specified user including the user * itself. * Returns a list of the users that are associated with the specified user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @param userId id of the user to return profiles for Loading services/core/java/com/android/server/pm/UserManagerInternal.java +4 −2 Original line number Diff line number Diff line Loading @@ -353,8 +353,10 @@ public abstract class UserManagerInternal { boolean excludePreCreated); /** * Returns an array of ids for profiles associated with the specified user including the user * itself. * Returns a list of the users that are associated with the specified user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @param userId id of the user to return profiles for Loading services/core/java/com/android/server/pm/UserManagerService.java +26 −24 Original line number Diff line number Diff line Loading @@ -1636,7 +1636,7 @@ public class UserManagerService extends IUserManager.Stub { final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo profile = mUsers.valueAt(i).info; if (!isProfileOf(user, profile)) { if (!isSameProfileGroup(user, profile)) { continue; } if (enabledOnly && !profile.isEnabled()) { Loading Loading @@ -1704,22 +1704,18 @@ public class UserManagerService extends IUserManager.Stub { return isSameProfileGroupNoChecks(userId, otherUserId); } /** * Returns whether users are in the same non-empty profile group. * Currently, false if empty profile group, even if they are the same user, for whatever reason. */ /** Returns whether users are in the same profile group. */ private boolean isSameProfileGroupNoChecks(@UserIdInt int userId, int otherUserId) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { if (userInfo == null) { return false; } UserInfo otherUserInfo = getUserInfoLU(otherUserId); if (otherUserInfo == null || otherUserInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { if (otherUserInfo == null) { return false; } return userInfo.profileGroupId == otherUserInfo.profileGroupId; return isSameProfileGroup(userInfo, otherUserInfo); } } Loading Loading @@ -1778,10 +1774,10 @@ public class UserManagerService extends IUserManager.Stub { } } private static boolean isProfileOf(UserInfo user, UserInfo profile) { return user.id == profile.id || (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID && user.profileGroupId == profile.profileGroupId); private static boolean isSameProfileGroup(@NonNull UserInfo user1, @NonNull UserInfo user2) { return user1.id == user2.id || (user1.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID && user1.profileGroupId == user2.profileGroupId); } private String getAvailabilityIntentAction(boolean enableQuietMode, boolean useManagedActions) { Loading Loading @@ -8411,22 +8407,28 @@ public class UserManagerService extends IUserManager.Stub { } /** * Checks if the given user has a profile associated with it. * @param userId The parent user * @return * Formerly: Checks if the given user has a profile associated with it. * Now: Just throws. Do not use it. * @param userId The parent user (passing in a profile user is not supported) * @deprecated */ boolean hasProfile(@UserIdInt int userId) { if (!android.content.pm.Flags.removeCrossUserPermissionHack()) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo profile = mUsers.valueAt(i).info; if (userId != profile.id && isProfileOf(userInfo, profile)) { if (userId != profile.id && isSameProfileGroup(userInfo, profile)) { return true; } } return false; } } else { // TODO(b/332664521): Remove this method entirely. It is no longer used. throw new UnsupportedOperationException(); } } /** Loading Loading
core/java/android/os/UserManager.java +31 −15 Original line number Diff line number Diff line Loading @@ -5326,7 +5326,9 @@ public class UserManager { } /** * Returns list of the profiles of userId including userId itself. * Returns a list of the users that are associated with userId, including userId itself. This * includes the user, its profiles, its parent, and its parent's other profiles, as applicable. * * Note that this returns both enabled and not enabled profiles. See * {@link #getEnabledProfiles(int)} if you need only the enabled ones. * <p>Note that this includes all profile types (not including Restricted profiles). Loading @@ -5334,7 +5336,7 @@ public class UserManager { * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} or * {@link android.Manifest.permission#CREATE_USERS} or * {@link android.Manifest.permission#QUERY_USERS} if userId is not the calling user. * @param userId profiles of this user will be returned. * @param userId profiles associated with this user (including itself) will be returned. * @return the list of profiles. * @hide */ Loading @@ -5358,12 +5360,13 @@ public class UserManager { } /** * Returns list of the profiles of the given user, including userId itself, as well as the * communal profile, if there is one. * Returns a list of the users that are associated with userId, including userId itself, * as well as the communal profile, if there is one. * * <p>Note that this returns both enabled and not enabled profiles. * <p>Note that this includes all profile types (not including Restricted profiles). * * @see #getProfiles(int) * @hide */ @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE) Loading Loading @@ -5419,7 +5422,10 @@ public class UserManager { } /** * Returns list of the profiles of userId including userId itself. * Returns a list of the enabled users that are associated with userId, including userId itself. * This includes the user, its profiles, its parent, and its parent's other profiles, as * applicable. * * Note that this returns only {@link UserInfo#isEnabled() enabled} profiles. * <p>Note that this includes all profile types (not including Restricted profiles). * Loading Loading @@ -5447,8 +5453,10 @@ public class UserManager { } /** * Returns a list of UserHandles for profiles associated with the context user, including the * user itself. * Returns a list of the users that are associated with the context user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @return A non-empty list of UserHandles associated with the context user. Loading @@ -5465,8 +5473,10 @@ public class UserManager { } /** * Returns a list of ids for enabled profiles associated with the context user including the * user itself. * Returns a list of the enabled users that are associated with the context user, including the * user itself. This includes the user, its profiles, its parent, and its parent's other * profiles, as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @return A non-empty list of UserHandles associated with the context user. Loading @@ -5483,8 +5493,10 @@ public class UserManager { } /** * Returns a list of ids for all profiles associated with the context user including the user * itself. * Returns a list of all users that are associated with the context user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @return A non-empty list of UserHandles associated with the context user. Loading @@ -5501,8 +5513,10 @@ public class UserManager { } /** * Returns a list of ids for profiles associated with the context user including the user * itself. * Returns a list of the users that are associated with the context user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, as * applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @param enabledOnly whether to return only {@link UserInfo#isEnabled() enabled} profiles Loading @@ -5528,8 +5542,10 @@ public class UserManager { } /** * Returns a list of ids for profiles associated with the specified user including the user * itself. * Returns a list of the users that are associated with the specified user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @param userId id of the user to return profiles for Loading
services/core/java/com/android/server/pm/UserManagerInternal.java +4 −2 Original line number Diff line number Diff line Loading @@ -353,8 +353,10 @@ public abstract class UserManagerInternal { boolean excludePreCreated); /** * Returns an array of ids for profiles associated with the specified user including the user * itself. * Returns a list of the users that are associated with the specified user, including the user * itself. This includes the user, its profiles, its parent, and its parent's other profiles, * as applicable. * * <p>Note that this includes all profile types (not including Restricted profiles). * * @param userId id of the user to return profiles for Loading
services/core/java/com/android/server/pm/UserManagerService.java +26 −24 Original line number Diff line number Diff line Loading @@ -1636,7 +1636,7 @@ public class UserManagerService extends IUserManager.Stub { final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo profile = mUsers.valueAt(i).info; if (!isProfileOf(user, profile)) { if (!isSameProfileGroup(user, profile)) { continue; } if (enabledOnly && !profile.isEnabled()) { Loading Loading @@ -1704,22 +1704,18 @@ public class UserManagerService extends IUserManager.Stub { return isSameProfileGroupNoChecks(userId, otherUserId); } /** * Returns whether users are in the same non-empty profile group. * Currently, false if empty profile group, even if they are the same user, for whatever reason. */ /** Returns whether users are in the same profile group. */ private boolean isSameProfileGroupNoChecks(@UserIdInt int userId, int otherUserId) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { if (userInfo == null) { return false; } UserInfo otherUserInfo = getUserInfoLU(otherUserId); if (otherUserInfo == null || otherUserInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { if (otherUserInfo == null) { return false; } return userInfo.profileGroupId == otherUserInfo.profileGroupId; return isSameProfileGroup(userInfo, otherUserInfo); } } Loading Loading @@ -1778,10 +1774,10 @@ public class UserManagerService extends IUserManager.Stub { } } private static boolean isProfileOf(UserInfo user, UserInfo profile) { return user.id == profile.id || (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID && user.profileGroupId == profile.profileGroupId); private static boolean isSameProfileGroup(@NonNull UserInfo user1, @NonNull UserInfo user2) { return user1.id == user2.id || (user1.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID && user1.profileGroupId == user2.profileGroupId); } private String getAvailabilityIntentAction(boolean enableQuietMode, boolean useManagedActions) { Loading Loading @@ -8411,22 +8407,28 @@ public class UserManagerService extends IUserManager.Stub { } /** * Checks if the given user has a profile associated with it. * @param userId The parent user * @return * Formerly: Checks if the given user has a profile associated with it. * Now: Just throws. Do not use it. * @param userId The parent user (passing in a profile user is not supported) * @deprecated */ boolean hasProfile(@UserIdInt int userId) { if (!android.content.pm.Flags.removeCrossUserPermissionHack()) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo profile = mUsers.valueAt(i).info; if (userId != profile.id && isProfileOf(userInfo, profile)) { if (userId != profile.id && isSameProfileGroup(userInfo, profile)) { return true; } } return false; } } else { // TODO(b/332664521): Remove this method entirely. It is no longer used. throw new UnsupportedOperationException(); } } /** Loading