Search in sources :

Example 21 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by ResurrectionRemix.

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.");
        }
        setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
        getLockSettings().setLockPattern(patternToString(pattern, userId), 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, userId);
                updateEncryptionPassword(StorageManager.CRYPT_TYPE_PATTERN, stringPattern);
            }
        }
        setBoolean(PATTERN_EVER_CHOSEN_KEY, true, 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 22 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by ResurrectionRemix.

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 23 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by ResurrectionRemix.

the class RestrictedLockUtils method getProfileOrDeviceOwner.

public static EnforcedAdmin getProfileOrDeviceOwner(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);
    }
    if (dpm.getDeviceOwnerUserId() == userId) {
        adminComponent = dpm.getDeviceOwnerComponentOnAnyUser();
        if (adminComponent != null) {
            return new EnforcedAdmin(adminComponent, userId);
        }
    }
    return null;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ComponentName(android.content.ComponentName)

Example 24 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by ResurrectionRemix.

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 25 with DevicePolicyManager

use of android.app.admin.DevicePolicyManager in project android_frameworks_base by ResurrectionRemix.

the class RestrictedLockUtils method checkIfKeyguardFeaturesDisabled.

/**
     * Checks if keyguard features are disabled by policy.
     *
     * @param keyguardFeatures Could be any of keyguard features that can be
     * disabled by {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures}.
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} If the notification features are not disabled. If the restriction is set by
     * multiple admins, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     */
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context, int keyguardFeatures, int userId) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    if (um.getUserInfo(userId).isManagedProfile()) {
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
        if (admins == null) {
            return null;
        }
        for (ComponentName admin : admins) {
            if ((dpm.getKeyguardDisabledFeatures(admin, userId) & keyguardFeatures) != 0) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userId);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
            }
        }
    } else {
        // user that do not use a separate work challenge.
        for (UserInfo userInfo : um.getProfiles(userId)) {
            final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
            if (admins == null) {
                continue;
            }
            final boolean isSeparateProfileChallengeEnabled = lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id);
            for (ComponentName admin : admins) {
                if (!isSeparateProfileChallengeEnabled) {
                    if ((dpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                        // has set policy on the parent admin.
                        continue;
                    }
                }
                if (userInfo.isManagedProfile()) {
                    // If userInfo.id is a managed profile, we also need to look at
                    // the policies set on the parent.
                    DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                    if ((parentDpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                    }
                }
            }
        }
    }
    return enforcedAdmin;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) ComponentName(android.content.ComponentName) UserInfo(android.content.pm.UserInfo)

Aggregations

DevicePolicyManager (android.app.admin.DevicePolicyManager)159 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