Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fd5b7744 authored by Xiaohui Chen's avatar Xiaohui Chen
Browse files

Add UM.isSameProfileGroup()

This optimizes the performance to check if two users are in the same
profile group.

Change-Id: I493a3475b848487836f4dbe01529c63165ace483
parent 3128c842
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ interface IUserManager {
    List<UserInfo> getProfiles(int userHandle, boolean enabledOnly);
    boolean canAddMoreManagedProfiles(int userId);
    UserInfo getProfileParent(int userHandle);
    boolean isSameProfileGroup(int userId, int otherUserId);
    UserInfo getUserInfo(int userHandle);
    long getUserCreationTime(int userHandle);
    boolean isRestricted();
+16 −0
Original line number Diff line number Diff line
@@ -1092,6 +1092,22 @@ public class UserManager {
        }
    }

    /**
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * @param userId one of the two user ids to check.
     * @param otherUserId one of the two user ids to check.
     * @return true if the two user ids are in the same profile group.
     * @hide
     */
    public boolean isSameProfileGroup(int userId, int otherUserId) {
        try {
            return mService.isSameProfileGroup(userId, otherUserId);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not get user list", re);
            return false;
        }
    }

    /**
     * Returns list of the profiles of userHandle including
     * userHandle itself.
+21 −0
Original line number Diff line number Diff line
@@ -355,6 +355,27 @@ public class UserManagerService extends IUserManager.Stub {
        return userHandle;
    }

    @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");