Switch UM to internal isUserUnlockingOrUnlocked

Internal version of UMS maintains a self-locking data-structure of user
states that  is pushed from ActivityManager. Previously there could
be discrepancies between UMS.isUserUnlockingOrUnlocked and
UM.isUserUnlockingOrUnlocked, which is calling a blocking version
in ActivityManager.

Test: manual + UserManagerTests

Bug: 31995235
Bug: 31833240
Change-Id: Ibafe403f57cd32d9052bb55fe7273a861be1d037
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index c0de214..6498b0e 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -673,12 +673,6 @@
     public boolean isSameProfileGroup(int userId, int otherUserId) {
         if (userId == otherUserId) return true;
         checkManageUsersPermission("check if in the same profile group");
-        synchronized (mPackagesLock) {
-            return isSameProfileGroupLP(userId, otherUserId);
-        }
-    }
-
-    private boolean isSameProfileGroupLP(int userId, int otherUserId) {
         synchronized (mUsersLock) {
             UserInfo userInfo = getUserInfoLU(userId);
             if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
@@ -880,12 +874,10 @@
     public boolean isManagedProfile(int userId) {
         int callingUserId = UserHandle.getCallingUserId();
         if (callingUserId != userId && !hasManageUsersPermission()) {
-            synchronized (mPackagesLock) {
-                if (!isSameProfileGroupLP(callingUserId, userId)) {
-                    throw new SecurityException(
-                            "You need MANAGE_USERS permission to: check if specified user a " +
-                            "managed profile outside your profile group");
-                }
+            if (!isSameProfileGroup(callingUserId, userId)) {
+                throw new SecurityException(
+                        "You need MANAGE_USERS permission to: check if specified user a " +
+                        "managed profile outside your profile group");
             }
         }
         synchronized (mUsersLock) {
@@ -895,6 +887,18 @@
     }
 
     @Override
+    public boolean isUserUnlockingOrUnlocked(int userId) {
+        int callingUserId = UserHandle.getCallingUserId();
+        if (callingUserId != userId && !hasManageUsersPermission()) {
+            if (!isSameProfileGroup(callingUserId, userId)) {
+                throw new SecurityException(
+                        "You need MANAGE_USERS permission to: check isUserUnlockingOrUnlocked");
+            }
+        }
+        return mLocalService.isUserUnlockingOrUnlocked(userId);
+    }
+
+    @Override
     public boolean isDemoUser(int userId) {
         int callingUserId = UserHandle.getCallingUserId();
         if (callingUserId != userId && !hasManageUsersPermission()) {