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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user