use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.
the class RestrictedLockUtils method checkIfRemoteContactSearchDisallowed.
/**
* @param context
* @param userId user id of a managed profile.
* @return is remote contacts search disallowed.
*/
public static EnforcedAdmin checkIfRemoteContactSearchDisallowed(Context context, int userId) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
EnforcedAdmin admin = getProfileOwner(context, userId);
if (admin == null) {
return null;
}
UserHandle userHandle = UserHandle.of(userId);
if (dpm.getCrossProfileContactsSearchDisabled(userHandle) && dpm.getCrossProfileCallerIdDisabled(userHandle)) {
return admin;
}
return null;
}
use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.
the class RestrictedLockUtils method checkIfInputMethodDisallowed.
public static EnforcedAdmin checkIfInputMethodDisallowed(Context context, String packageName, int userId) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
EnforcedAdmin admin = getProfileOrDeviceOwner(context, userId);
boolean permitted = true;
if (admin != null) {
permitted = dpm.isInputMethodPermittedByAdmin(admin.component, packageName, userId);
}
int managedProfileId = getManagedProfileId(context, userId);
EnforcedAdmin profileAdmin = getProfileOrDeviceOwner(context, managedProfileId);
boolean permittedByProfileAdmin = true;
if (profileAdmin != null) {
permittedByProfileAdmin = dpm.isInputMethodPermittedByAdmin(profileAdmin.component, packageName, managedProfileId);
}
if (!permitted && !permittedByProfileAdmin) {
return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
} else if (!permitted) {
return admin;
} else if (!permittedByProfileAdmin) {
return profileAdmin;
}
return null;
}
use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.
the class RestrictedLockUtils method checkIfAutoTimeRequired.
/**
* Checks if {@link android.app.admin.DevicePolicyManager#setAutoTimeRequired} is enforced
* on the device.
*
* @return EnforcedAdmin Object containing the device owner component and
* userId the device owner is running as, or {@code null} setAutoTimeRequired is not enforced.
*/
public static EnforcedAdmin checkIfAutoTimeRequired(Context context) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null || !dpm.getAutoTimeRequired()) {
return null;
}
ComponentName adminComponent = dpm.getDeviceOwnerComponentOnCallingUser();
return new EnforcedAdmin(adminComponent, UserHandle.myUserId());
}
use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.
the class RestrictedLockUtils method isAdminInCurrentUserOrProfile.
public static boolean isAdminInCurrentUserOrProfile(Context context, ComponentName admin) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
UserManager um = UserManager.get(context);
for (UserInfo userInfo : um.getProfiles(UserHandle.myUserId())) {
if (dpm.isAdminActiveAsUser(admin, userInfo.id)) {
return true;
}
}
return false;
}
use of android.app.admin.DevicePolicyManager in project android_frameworks_base by DirtyUnicorns.
the class RestrictedLockUtils method checkIfAccessibilityServiceDisallowed.
public static EnforcedAdmin checkIfAccessibilityServiceDisallowed(Context context, String packageName, int userId) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
EnforcedAdmin admin = getProfileOrDeviceOwner(context, userId);
boolean permitted = true;
if (admin != null) {
permitted = dpm.isAccessibilityServicePermittedByAdmin(admin.component, packageName, userId);
}
int managedProfileId = getManagedProfileId(context, userId);
EnforcedAdmin profileAdmin = getProfileOrDeviceOwner(context, managedProfileId);
boolean permittedByProfileAdmin = true;
if (profileAdmin != null) {
permittedByProfileAdmin = dpm.isAccessibilityServicePermittedByAdmin(profileAdmin.component, packageName, managedProfileId);
}
if (!permitted && !permittedByProfileAdmin) {
return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
} else if (!permitted) {
return admin;
} else if (!permittedByProfileAdmin) {
return profileAdmin;
}
return null;
}
Aggregations