Search in sources :

Example 6 with DevicePolicyManager

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);
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) RemoteException(android.os.RemoteException)

Example 7 with DevicePolicyManager

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;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo)

Example 8 with DevicePolicyManager

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());
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 9 with DevicePolicyManager

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;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 10 with DevicePolicyManager

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;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)158 ComponentName (android.content.ComponentName)45 UserManager (android.os.UserManager)29 UserInfo (android.content.pm.UserInfo)25 RemoteException (android.os.RemoteException)24 LockPatternUtils (com.android.internal.widget.LockPatternUtils)19 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)14 PersistableBundle (android.os.PersistableBundle)8 PendingIntent (android.app.PendingIntent)6 IBinder (android.os.IBinder)6 UserHandle (android.os.UserHandle)6 IPackageManager (android.content.pm.IPackageManager)5 Uri (android.net.Uri)5 VrManagerInternal (com.android.server.vr.VrManagerInternal)5 ResolveInfo (android.content.pm.ResolveInfo)4 Point (android.graphics.Point)4 Binder (android.os.Binder)4 KeyStore (android.security.KeyStore)4 ArraySet (android.util.ArraySet)4