Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76621cf2 authored by Pavel Grafov's avatar Pavel Grafov Committed by Android (Google) Code Review
Browse files

Merge "Password constraints cleanup."

parents 8357dd73 6f334843
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -2329,6 +2329,12 @@ public class DevicePolicyManager {
    public static final String ACTION_ADMIN_POLICY_COMPLIANCE =
            "android.app.action.ADMIN_POLICY_COMPLIANCE";

    /**
     * Maximum supported password length. Kind-of arbitrary.
     * @hide
     */
    public static final int MAX_PASSWORD_LENGTH = 16;

    /**
     * Return true if the given administrator component is currently active (enabled) in the system.
     *
@@ -3232,6 +3238,22 @@ public class DevicePolicyManager {
        return 0;
    }

    /**
     * Returns minimum PasswordMetrics that satisfies all admin policies.
     *
     * @hide
     */
    public PasswordMetrics getPasswordMinimumMetrics(@UserIdInt int userHandle) {
        if (mService != null) {
            try {
                return mService.getPasswordMinimumMetrics(userHandle);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return null;
    }

    /**
     * Called by an application that is administering the device to set the length of the password
     * history. After setting this, the user will not be able to enter a new password that is the
@@ -3415,8 +3437,7 @@ public class DevicePolicyManager {
        if (!pm.hasSystemFeature(PackageManager.FEATURE_SECURE_LOCK_SCREEN)) {
            return 0;
        }
        // Kind-of arbitrary.
        return 16;
        return MAX_PASSWORD_LENGTH;
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@ interface IDevicePolicyManager {
    void setPasswordMinimumNonLetter(in ComponentName who, int length, boolean parent);
    int getPasswordMinimumNonLetter(in ComponentName who, int userHandle, boolean parent);

    PasswordMetrics getPasswordMinimumMetrics(int userHandle);

    void setPasswordHistoryLength(in ComponentName who, int length, boolean parent);
    int getPasswordHistoryLength(in ComponentName who, int userHandle, boolean parent);

+465 −255

File changed.

Preview size limit exceeded, changes collapsed.

+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.admin;

import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;

import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_NONE;
import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PASSWORD;
import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTERN;

/**
 * {@hide}
 */
public class PasswordPolicy {
    public static final int DEF_MINIMUM_LENGTH = 0;
    public static final int DEF_MINIMUM_LETTERS = 1;
    public static final int DEF_MINIMUM_UPPER_CASE = 0;
    public static final int DEF_MINIMUM_LOWER_CASE = 0;
    public static final int DEF_MINIMUM_NUMERIC = 1;
    public static final int DEF_MINIMUM_SYMBOLS = 1;
    public static final int DEF_MINIMUM_NON_LETTER = 0;

    public int quality = PASSWORD_QUALITY_UNSPECIFIED;
    public int length = DEF_MINIMUM_LENGTH;
    public int letters = DEF_MINIMUM_LETTERS;
    public int upperCase = DEF_MINIMUM_UPPER_CASE;
    public int lowerCase = DEF_MINIMUM_LOWER_CASE;
    public int numeric = DEF_MINIMUM_NUMERIC;
    public int symbols = DEF_MINIMUM_SYMBOLS;
    public int nonLetter = DEF_MINIMUM_NON_LETTER;

    /**
     * Returns a minimum password metrics that the password should have to satisfy current policy.
     */
    public PasswordMetrics getMinMetrics() {
        if (quality == PASSWORD_QUALITY_UNSPECIFIED) {
            return new PasswordMetrics(CREDENTIAL_TYPE_NONE);
        } else if (quality == PASSWORD_QUALITY_BIOMETRIC_WEAK
                || quality == PASSWORD_QUALITY_SOMETHING) {
            return new PasswordMetrics(CREDENTIAL_TYPE_PATTERN);
        } // quality is NUMERIC or stronger.

        PasswordMetrics result = new PasswordMetrics(CREDENTIAL_TYPE_PASSWORD);
        result.length = length;

        if (quality == PASSWORD_QUALITY_NUMERIC_COMPLEX) {
            result.seqLength = PasswordMetrics.MAX_ALLOWED_SEQUENCE;
        } else if (quality == PASSWORD_QUALITY_ALPHABETIC) {
            result.nonNumeric = 1;
        } else if (quality == PASSWORD_QUALITY_ALPHANUMERIC) {
            result.numeric = 1;
            result.nonNumeric = 1;
        } else if (quality == PASSWORD_QUALITY_COMPLEX) {
            result.numeric = numeric;
            result.letters = letters;
            result.upperCase = upperCase;
            result.lowerCase = lowerCase;
            result.nonLetter = nonLetter;
            result.symbols = symbols;
        }
        return result;
    }
}
+8 −7
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.app.admin.DevicePolicyManager;
import android.app.admin.PasswordMetrics;
import android.app.trust.IStrongAuthTracker;
import android.app.trust.TrustManager;
import android.content.ComponentName;
@@ -58,10 +59,10 @@ import android.util.SparseLongArray;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;

import com.google.android.collect.Lists;

import libcore.util.HexEncoding;

import com.google.android.collect.Lists;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.security.MessageDigest;
@@ -77,7 +78,6 @@ import java.util.StringJoiner;
 * Utilities for the lock pattern and its settings.
 */
public class LockPatternUtils {

    private static final String TAG = "LockPatternUtils";
    private static final boolean FRP_CREDENTIAL_ENABLED = true;

@@ -114,6 +114,7 @@ public class LockPatternUtils {
     */
    public static final int MIN_PATTERN_REGISTER_FAIL = MIN_LOCK_PATTERN_SIZE;

    // NOTE: When modifying this, make sure credential sufficiency validation logic is intact.
    public static final int CREDENTIAL_TYPE_NONE = -1;
    public static final int CREDENTIAL_TYPE_PATTERN = 1;
    public static final int CREDENTIAL_TYPE_PASSWORD = 2;
@@ -289,10 +290,10 @@ public class LockPatternUtils {
        return getDevicePolicyManager().getPasswordMaximumLength(quality);
    }

    /**
     * Gets the device policy password mode. If the mode is non-specific, returns
     * MODE_PATTERN which allows the user to choose anything.
     */
    public PasswordMetrics getRequestedPasswordMetrics(int userId) {
        return getDevicePolicyManager().getPasswordMinimumMetrics(userId);
    }

    public int getRequestedPasswordQuality(int userId) {
        return getDevicePolicyManager().getPasswordQuality(null, userId);
    }
Loading