use of android.app.admin.DevicePolicyManager in project platform_frameworks_base by android.
the class LockPatternUtils method saveLockPattern.
/**
* Save a lock pattern.
* @param pattern The new pattern to save.
* @param savedPattern The previously saved pattern, converted to String format
* @param userId the user whose pattern is to be saved.
*/
public void saveLockPattern(List<LockPatternView.Cell> pattern, String savedPattern, int userId) {
try {
if (pattern == null || pattern.size() < MIN_LOCK_PATTERN_SIZE) {
throw new IllegalArgumentException("pattern must not be null and at least " + MIN_LOCK_PATTERN_SIZE + " dots long.");
}
getLockSettings().setLockPattern(patternToString(pattern), savedPattern, userId);
DevicePolicyManager dpm = getDevicePolicyManager();
// Update the device encryption password.
if (userId == UserHandle.USER_SYSTEM && LockPatternUtils.isDeviceEncryptionEnabled()) {
if (!shouldEncryptWithCredentials(true)) {
clearEncryptionPassword();
} else {
String stringPattern = patternToString(pattern);
updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
}
}
setBoolean(PATTERN_EVER_CHOSEN_KEY, true, userId);
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, pattern.size(), 0, 0, 0, 0, 0, 0, userId);
onAfterChangingPassword(userId);
} catch (RemoteException re) {
Log.e(TAG, "Couldn't save lock pattern " + re);
}
}
use of android.app.admin.DevicePolicyManager in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class RestrictedLockUtils method getProfileOwner.
private static EnforcedAdmin getProfileOwner(Context context, int userId) {
if (userId == UserHandle.USER_NULL) {
return null;
}
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
ComponentName adminComponent = dpm.getProfileOwnerAsUser(userId);
if (adminComponent != null) {
return new EnforcedAdmin(adminComponent, userId);
}
return null;
}
use of android.app.admin.DevicePolicyManager in project platform_frameworks_base by android.
the class RestrictedLockUtils method checkIfRestrictionEnforced.
/**
* Checks if a restriction is enforced on a user and returns the enforced admin and
* admin userId.
*
* @param userRestriction Restriction to check
* @param userId User which we need to check if restriction is enforced on.
* @return EnforcedAdmin Object containing the enforced admin component and admin user details,
* or {@code null} If the restriction is not set. If the restriction is set by both device owner
* and profile owner, then the admin component will be set to {@code null} and userId to
* {@link UserHandle#USER_NULL}.
*/
public static EnforcedAdmin checkIfRestrictionEnforced(Context context, String userRestriction, int userId) {
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
UserManager um = UserManager.get(context);
int restrictionSource = um.getUserRestrictionSource(userRestriction, UserHandle.of(userId));
// If the restriction is not enforced or enforced only by system then return null
if (restrictionSource == UserManager.RESTRICTION_NOT_SET || restrictionSource == UserManager.RESTRICTION_SOURCE_SYSTEM) {
return null;
}
final boolean enforcedByProfileOwner = (restrictionSource & UserManager.RESTRICTION_SOURCE_PROFILE_OWNER) != 0;
final boolean enforcedByDeviceOwner = (restrictionSource & UserManager.RESTRICTION_SOURCE_DEVICE_OWNER) != 0;
if (enforcedByProfileOwner) {
return getProfileOwner(context, userId);
} else if (enforcedByDeviceOwner) {
// When the restriction is enforced by device owner, return the device owner admin only
// if the admin is for the {@param userId} otherwise return a default EnforcedAdmin.
final EnforcedAdmin deviceOwner = getDeviceOwner(context);
return deviceOwner.userId == userId ? deviceOwner : EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
}
return null;
}
Aggregations