diff options
| author | 2015-11-11 14:54:35 +0000 | |
|---|---|---|
| committer | 2015-11-24 15:00:18 +0000 | |
| commit | 15a46b07c5734b14df60ea28ab7a7cd26df2fc17 (patch) | |
| tree | 7c533020f5bc9e8e94f823bd3df90a139fedccd2 | |
| parent | 1a3c1650ccc0b15668f44b2911f5daf93573c0e0 (diff) | |
Add method isManagedProfile and isSystemOnlyUser
Adding method isManagedProfile() and isSystemOnlyUser() for DPC to know
if running in a managed profile or system only user
Bug: 24464823
Change-Id: I79974fdfd60d2bfe52dee3b4c95becf47a5bf0b1
3 files changed, 61 insertions, 0 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index f1a55f915566..1c65c9400332 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -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; + } + } } diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index c6f87402909b..fc7c2b3b76b9 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -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); } diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 4b855ed92f29..8beee73628aa 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -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; + } + } |