OSDN Git Service

Add method isManagedProfile and isSystemOnlyUser
authorMahaver Chopra <mahaver@google.com>
Wed, 11 Nov 2015 14:54:35 +0000 (14:54 +0000)
committerMahaver Chopra <mahaver@google.com>
Tue, 24 Nov 2015 15:00:18 +0000 (15:00 +0000)
Adding method isManagedProfile() and isSystemOnlyUser() for DPC to know
if running in a managed profile or system only user

Bug: 24464823
Change-Id: I79974fdfd60d2bfe52dee3b4c95becf47a5bf0b1

core/java/android/app/admin/DevicePolicyManager.java
core/java/android/app/admin/IDevicePolicyManager.aidl
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java

index f1a55f9..1c65c94 100644 (file)
@@ -4558,4 +4558,37 @@ public class DevicePolicyManager {
             return false;
         }
     }
+
+    /**
+     * @hide
+     * Return if this user is a managed profile of another user. An admin can become the profile
+     * owner of a managed profile with {@link #ACTION_PROVISION_MANAGED_PROFILE} and of a managed
+     * user with {@link #ACTION_PROVISION_MANAGED_USER}.
+     * @param admin Which profile owner this request is associated with.
+     * @return if this user is a managed profile of another user.
+     */
+    public boolean isManagedProfile(@NonNull ComponentName admin) {
+        try {
+            return mService.isManagedProfile(admin);
+        } catch (RemoteException re) {
+            Log.w(TAG, "Failed talking with device policy service", re);
+            return false;
+        }
+    }
+
+    /**
+     * @hide
+     * Return if this user is a system-only user. An admin can manage a device from a system only
+     * user by calling {@link #ACTION_PROVISION_MANAGED_SHAREABLE_DEVICE}.
+     * @param admin Which device owner this request is associated with.
+     * @return if this user is a system-only user.
+     */
+    public boolean isSystemOnlyUser(@NonNull ComponentName admin) {
+        try {
+            return mService.isSystemOnlyUser(admin);
+        } catch (RemoteException re) {
+            Log.w(TAG, "Failed talking with device policy service", re);
+            return false;
+        }
+    }
 }
index c6f8740..fc7c2b3 100644 (file)
@@ -233,4 +233,6 @@ interface IDevicePolicyManager {
     boolean isProvisioningAllowed(String action);
     void setKeepUninstalledPackages(in ComponentName admin,in List<String> packageList);
     List<String> getKeepUninstalledPackages(in ComponentName admin);
+    boolean isManagedProfile(in ComponentName admin);
+    boolean isSystemOnlyUser(in ComponentName admin);
 }
index 4b855ed..8beee73 100644 (file)
@@ -6841,4 +6841,30 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
         final int targetSdkVersion = ai == null ? 0 : ai.targetSdkVersion;
         return targetSdkVersion;
     }
+
+    @Override
+    public boolean isManagedProfile(ComponentName admin) {
+        synchronized (this) {
+            getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
+        }
+        final int callingUserId = mInjector.userHandleGetCallingUserId();
+        final UserInfo user;
+        long ident = mInjector.binderClearCallingIdentity();
+        try {
+            user = mUserManager.getUserInfo(callingUserId);
+        } finally {
+            mInjector.binderRestoreCallingIdentity(ident);
+        }
+        return user != null && user.isManagedProfile();
+    }
+
+    @Override
+    public boolean isSystemOnlyUser(ComponentName admin) {
+        synchronized (this) {
+            getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
+        }
+        final int callingUserId = mInjector.userHandleGetCallingUserId();
+        return UserManager.isSplitSystemUser() && callingUserId == UserHandle.USER_SYSTEM;
+    }
+
 }