Search in sources :

Example 56 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project android_frameworks_base by ParanoidAndroid.

the class DevicePolicyManagerService method resetPassword.

public boolean resetPassword(String password, int flags, int userHandle) {
    enforceCrossUserPermission(userHandle);
    int quality;
    synchronized (this) {
        // This API can only be called by an active device admin,
        // so try to retrieve it to check that the caller is one.
        getActiveAdminForCallerLocked(null, DeviceAdminInfo.USES_POLICY_RESET_PASSWORD);
        quality = getPasswordQuality(null, userHandle);
        if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
            int realQuality = LockPatternUtils.computePasswordQuality(password);
            if (realQuality < quality && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
                Slog.w(TAG, "resetPassword: password quality 0x" + Integer.toHexString(realQuality) + " does not meet required quality 0x" + Integer.toHexString(quality));
                return false;
            }
            quality = Math.max(realQuality, quality);
        }
        int length = getPasswordMinimumLength(null, userHandle);
        if (password.length() < length) {
            Slog.w(TAG, "resetPassword: password length " + password.length() + " does not meet required length " + length);
            return false;
        }
        if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
            int letters = 0;
            int uppercase = 0;
            int lowercase = 0;
            int numbers = 0;
            int symbols = 0;
            int nonletter = 0;
            for (int i = 0; i < password.length(); i++) {
                char c = password.charAt(i);
                if (c >= 'A' && c <= 'Z') {
                    letters++;
                    uppercase++;
                } else if (c >= 'a' && c <= 'z') {
                    letters++;
                    lowercase++;
                } else if (c >= '0' && c <= '9') {
                    numbers++;
                    nonletter++;
                } else {
                    symbols++;
                    nonletter++;
                }
            }
            int neededLetters = getPasswordMinimumLetters(null, userHandle);
            if (letters < neededLetters) {
                Slog.w(TAG, "resetPassword: number of letters " + letters + " does not meet required number of letters " + neededLetters);
                return false;
            }
            int neededNumbers = getPasswordMinimumNumeric(null, userHandle);
            if (numbers < neededNumbers) {
                Slog.w(TAG, "resetPassword: number of numerical digits " + numbers + " does not meet required number of numerical digits " + neededNumbers);
                return false;
            }
            int neededLowerCase = getPasswordMinimumLowerCase(null, userHandle);
            if (lowercase < neededLowerCase) {
                Slog.w(TAG, "resetPassword: number of lowercase letters " + lowercase + " does not meet required number of lowercase letters " + neededLowerCase);
                return false;
            }
            int neededUpperCase = getPasswordMinimumUpperCase(null, userHandle);
            if (uppercase < neededUpperCase) {
                Slog.w(TAG, "resetPassword: number of uppercase letters " + uppercase + " does not meet required number of uppercase letters " + neededUpperCase);
                return false;
            }
            int neededSymbols = getPasswordMinimumSymbols(null, userHandle);
            if (symbols < neededSymbols) {
                Slog.w(TAG, "resetPassword: number of special symbols " + symbols + " does not meet required number of special symbols " + neededSymbols);
                return false;
            }
            int neededNonLetter = getPasswordMinimumNonLetter(null, userHandle);
            if (nonletter < neededNonLetter) {
                Slog.w(TAG, "resetPassword: number of non-letter characters " + nonletter + " does not meet required number of non-letter characters " + neededNonLetter);
                return false;
            }
        }
    }
    int callingUid = Binder.getCallingUid();
    DevicePolicyData policy = getUserData(userHandle);
    if (policy.mPasswordOwner >= 0 && policy.mPasswordOwner != callingUid) {
        Slog.w(TAG, "resetPassword: already set by another uid and not entered by user");
        return false;
    }
    // Don't do this with the lock held, because it is going to call
    // back in to the service.
    long ident = Binder.clearCallingIdentity();
    try {
        LockPatternUtils utils = new LockPatternUtils(mContext);
        utils.saveLockPassword(password, quality, false, userHandle);
        synchronized (this) {
            int newOwner = (flags & DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) != 0 ? callingUid : -1;
            if (policy.mPasswordOwner != newOwner) {
                policy.mPasswordOwner = newOwner;
                saveSettingsLocked(userHandle);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    return true;
}
Also used : LockPatternUtils(com.android.internal.widget.LockPatternUtils)

Example 57 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project platform_frameworks_base by android.

the class EmergencyButton method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mLockPatternUtils = new LockPatternUtils(mContext);
    mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            takeEmergencyCallAction();
        }
    });
    setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (!mLongPressWasDragged && mEmergencyAffordanceManager.needsEmergencyAffordance()) {
                mEmergencyAffordanceManager.performEmergencyCall();
                return true;
            }
            return false;
        }
    });
    updateEmergencyCallButton();
}
Also used : LockPatternUtils(com.android.internal.widget.LockPatternUtils) View(android.view.View)

Example 58 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project platform_frameworks_base by android.

the class RestrictedLockUtils method checkIfMaximumTimeToLockIsSet.

/**
     * Checks if any admin has set maximum time to lock.
     *
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} if no admin has set this restriction. If multiple admins has set this, then
     * the admin component will be set to {@code null} and userId to {@link UserHandle#USER_NULL}
     */
public static EnforcedAdmin checkIfMaximumTimeToLockIsSet(Context context) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    final int userId = UserHandle.myUserId();
    final UserManager um = UserManager.get(context);
    final List<UserInfo> profiles = um.getProfiles(userId);
    final int profilesSize = profiles.size();
    // enabled.
    for (int i = 0; i < profilesSize; i++) {
        final UserInfo userInfo = profiles.get(i);
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
        if (admins == null) {
            continue;
        }
        for (ComponentName admin : admins) {
            if (dpm.getMaximumTimeToLock(admin, userInfo.id) > 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.
                final DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                if (parentDpm.getMaximumTimeToLock(admin, userInfo.id) > 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) UserInfo(android.content.pm.UserInfo) ComponentName(android.content.ComponentName)

Example 59 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project platform_frameworks_base by android.

the class RestrictedLockUtils method checkIfPasswordQualityIsSet.

/**
     * Checks if an admin has enforced minimum password quality requirements on the given user.
     *
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} if no quality requirements are set. If the requirements are set by
     * multiple device admins, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     *
     */
public static EnforcedAdmin checkIfPasswordQualityIsSet(Context context, int userId) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    if (lockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {
        // userId is managed profile and has a separate challenge, only consider
        // the admins in that user.
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
        if (admins == null) {
            return null;
        }
        for (ComponentName admin : admins) {
            if (dpm.getPasswordQuality(admin, userId) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userId);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
            }
        }
    } else {
        // Return all admins for this user and the profiles that are visible from this
        // user that do not use a separate work challenge.
        final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
        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.getPasswordQuality(admin, userInfo.id) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                        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.getPasswordQuality(admin, userInfo.id) > DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
                        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)

Example 60 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project platform_frameworks_base by android.

the class SettingsBackupAgent method restoreLockSettings.

/**
     * Restores the owner info enabled and owner info settings in LockSettings.
     *
     * @param buffer
     * @param nBytes
     */
private void restoreLockSettings(byte[] buffer, int nBytes) {
    final LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
    ByteArrayInputStream bais = new ByteArrayInputStream(buffer, 0, nBytes);
    DataInputStream in = new DataInputStream(bais);
    try {
        String key;
        // Read until empty string marker
        while ((key = in.readUTF()).length() > 0) {
            final String value = in.readUTF();
            if (DEBUG_BACKUP) {
                Log.v(TAG, "Restoring lock_settings " + key + " = " + value);
            }
            switch(key) {
                case KEY_LOCK_SETTINGS_OWNER_INFO_ENABLED:
                    lockPatternUtils.setOwnerInfoEnabled("1".equals(value), UserHandle.myUserId());
                    break;
                case KEY_LOCK_SETTINGS_OWNER_INFO:
                    lockPatternUtils.setOwnerInfo(value, UserHandle.myUserId());
                    break;
            }
        }
        in.close();
    } catch (IOException ioe) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LockPatternUtils(com.android.internal.widget.LockPatternUtils) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

LockPatternUtils (com.android.internal.widget.LockPatternUtils)96 ComponentName (android.content.ComponentName)24 UserInfo (android.content.pm.UserInfo)24 DevicePolicyManager (android.app.admin.DevicePolicyManager)19 UserManager (android.os.UserManager)16 IOException (java.io.IOException)11 IntentFilter (android.content.IntentFilter)10 Intent (android.content.Intent)9 View (android.view.View)9 Cursor (android.database.Cursor)6 RemoteException (android.os.RemoteException)6 ArrayList (java.util.ArrayList)6 ContentResolver (android.content.ContentResolver)5 Configuration (android.content.res.Configuration)5 Rect (android.graphics.Rect)5 SoundPool (android.media.SoundPool)5 IBinder (android.os.IBinder)5 IVrManager (android.service.vr.IVrManager)5 StatusBarIcon (com.android.internal.statusbar.StatusBarIcon)5 KeyguardDisplayManager (com.android.keyguard.KeyguardDisplayManager)5