OSDN Git Service

getUserInfo fail when app trying to get self user info
authorTony Mak <tonymak@google.com>
Wed, 16 Mar 2016 14:49:52 +0000 (14:49 +0000)
committerTony Mak <tonymak@google.com>
Wed, 16 Mar 2016 14:51:45 +0000 (14:51 +0000)
isSameProfileGroupLP return false when user has no profile, we should
check callingUserId != userId explictly.
Please notice that isSameProfileGroup handles this case, but we would like
to avoid the permission checking of isSameProfileGroup.

Change-Id: Ibb2d09eaaf7e8f099445490aa9ec287e86945125

services/core/java/com/android/server/pm/UserManagerService.java

index 5342f98..5fd196b 100644 (file)
@@ -641,12 +641,16 @@ public class UserManagerService extends IUserManager.Stub {
 
     @Override
     public UserInfo getUserInfo(int userId) {
-        if (!hasManageUsersPermission()
-                && !isSameProfileGroupLP(UserHandle.getCallingUserId(), userId)) {
-            throw new SecurityException(
-                    "You need MANAGE_USERS permission to: query users outside profile group");
+        int callingUserId = UserHandle.getCallingUserId();
+        if (callingUserId != userId && !hasManageUsersPermission()) {
+            synchronized (mPackagesLock) {
+                if (!isSameProfileGroupLP(callingUserId, userId)) {
+                    throw new SecurityException(
+                            "You need MANAGE_USERS permission to: query users outside profile" +
+                                    " group");
+                }
+            }
         }
-
         synchronized (mUsersLock) {
             return getUserInfoLU(userId);
         }