diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index f1a55f9155660..1c65c94003323 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 c6f87402909b3..fc7c2b3b76b91 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 packageList); List 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 4b855ed92f294..8beee73628aa6 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; + } + }