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

Commit b933e574 authored by Avinash Vadlamudi's avatar Avinash Vadlamudi
Browse files

[Auto Pin Confirm]: Create a setting to determine Auto Pin Confirm behaviour

- pin_auto_confirm setting will determine whether the entered pin should auto confirm after entering the exact digits or not.

Bug: 262936381
Test: Manual Test
Change-Id: I618fae69b0b7f54598940347e86927b64b591808
parent 7603e4fe
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -165,9 +166,17 @@ public class LockPatternUtils {
    private static final String KNOWN_TRUST_AGENTS = "lockscreen.knowntrustagents";
    private static final String IS_TRUST_USUALLY_MANAGED = "lockscreen.istrustusuallymanaged";

    private static final String AUTO_PIN_CONFIRM = "lockscreen.auto_pin_confirm";

    public static final String CURRENT_LSKF_BASED_PROTECTOR_ID_KEY = "sp-handle";
    public static final String PASSWORD_HISTORY_DELIMITER = ",";

    /**
     * drives the pin auto confirmation feature availability in code logic.
     */
    public static final String FLAG_ENABLE_AUTO_PIN_CONFIRMATION =
            "AutoPinConfirmation__enable_auto_pin_confirmation";

    @UnsupportedAppUsage
    private final Context mContext;
    @UnsupportedAppUsage
@@ -647,6 +656,38 @@ public class LockPatternUtils {
                || isDemoUser;
    }

    /**
     * Sets the pin auto confirm capability to enabled or disabled
     * @param enabled enables pin auto confirm capability when true
     * @param userId user ID of the user this has effect on
     */
    public void setAutoPinConfirm(boolean enabled, int userId) {
        setBoolean(AUTO_PIN_CONFIRM, enabled, userId);
    }

    /**
     * Determines if the auto pin confirmation feature is enabled or not for current user
     * If setting is not available, the default behaviour is disabled
     * @param userId user ID of the user this has effect on
     *
     * @return true, if the entered pin should be auto confirmed
     */
    public boolean isAutoPinConfirmEnabled(int userId) {
        return getBoolean(AUTO_PIN_CONFIRM, /* defaultValue= */ false, userId);
    }

    /**
     * Whether the auto pin feature logic is available or not.
     * @return true, if deviceConfig flag is set to true or the flag is not propagated and
     * defaultValue is true.
     */
    public boolean isAutoPinConfirmFeatureAvailable() {
        return DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_AUTO_PIN_CONFIRMATION,
                FLAG_ENABLE_AUTO_PIN_CONFIRMATION,
                /* defaultValue= */ false);
    }

    /** Returns if the given quality maps to an alphabetic password */
    public static boolean isQualityAlphabeticPassword(int quality) {
        return quality >= PASSWORD_QUALITY_ALPHABETIC;