Add UM.isSameProfileGroup()
This optimizes the performance to check if two users are in the same
profile group.
Change-Id: I493a3475b848487836f4dbe01529c63165ace483
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 341410d..80697ed 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -356,6 +356,27 @@
}
@Override
+ public boolean isSameProfileGroup(int userId, int otherUserId) {
+ if (userId == otherUserId) return true;
+ checkManageUsersPermission("check if in the same profile group");
+ synchronized (mPackagesLock) {
+ return isSameProfileGroupLocked(userId, otherUserId);
+ }
+ }
+
+ private boolean isSameProfileGroupLocked(int userId, int otherUserId) {
+ UserInfo userInfo = getUserInfoLocked(userId);
+ if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
+ return false;
+ }
+ UserInfo otherUserInfo = getUserInfoLocked(otherUserId);
+ if (otherUserInfo == null || otherUserInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
+ return false;
+ }
+ return userInfo.profileGroupId == otherUserInfo.profileGroupId;
+ }
+
+ @Override
public UserInfo getProfileParent(int userHandle) {
checkManageUsersPermission("get the profile parent");
synchronized (mPackagesLock) {