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

Commit 2dfb5509 authored by Bhavuk Jain's avatar Bhavuk Jain Committed by Aaron Liu
Browse files

Changes for storing the PIN length

This CL aims at making changes for storing the PIN length in device
encrypted storage. This would happen in two places, one when user
successfuly unlocks the device and other when user is updating the PIN
on their device.

Test: Tested by building and flashing on local, and checking if PIN length is stored by printing the value using logcat. Disabled feature flag to make sure that if it's disabled, the PIN length isn't stored.
Bug: b/262929169
Change-Id: I1ea2b07688e1486f2ef47513218409b7f7fe4a7d
parent 030b6286
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
package com.android.internal.widget;

import static android.provider.DeviceConfig.NAMESPACE_AUTO_PIN_CONFIRMATION;

import android.annotation.NonNull;
import android.os.AsyncTask;
import android.provider.DeviceConfig;

import com.android.internal.widget.LockPatternUtils.RequestThrottledException;

@@ -117,6 +120,10 @@ public final class LockPatternChecker {
            @Override
            protected void onPostExecute(Boolean result) {
                callback.onChecked(result, mThrottleTimeout);
                if (DeviceConfig.getBoolean(NAMESPACE_AUTO_PIN_CONFIRMATION,
                        "enable_auto_pin_confirmation", false)) {
                    utils.setPinLength(userId, credentialCopy.size());
                }
                credentialCopy.zeroize();
            }

+20 −0
Original line number Diff line number Diff line
@@ -151,6 +151,8 @@ public class LockPatternUtils {
    @Deprecated
    public final static String LOCKSCREEN_WIDGETS_ENABLED = "lockscreen.widgets_enabled";

    public static final String PIN_LENGTH = "lockscreen.pin_length";

    public final static String PASSWORD_HISTORY_KEY = "lockscreen.passwordhistory";

    private static final String LOCK_SCREEN_OWNER_INFO = Settings.Secure.LOCK_SCREEN_OWNER_INFO;
@@ -565,6 +567,24 @@ public class LockPatternUtils {
        return getBoolean(PATTERN_EVER_CHOSEN_KEY, false, userId);
    }

    /**
     * Used for setting the length of the PIN set by a particular user.
     * @param userId user id of the user whose pin length we save
     * @param val value of length of pin
     */
    public void setPinLength(int userId, long val) {
        setLong(PIN_LENGTH, val, userId);
    }

    /**
     * Returns the length of the PIN set by a particular user.
     * @param userId user id of the user whose pin length we have to return
     * @return the length of the pin set by user and -1 if nothing
     */
    public long getPinLength(int userId) {
        return getLong(PIN_LENGTH, -1, userId);
    }

    /**
     * Records that the user has chosen a pattern at some time, even if the pattern is
     * currently cleared.
+8 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.app.admin.DevicePolicyResources.Strings.Core.PROFILE_ENCRY
import static android.content.Context.KEYGUARD_SERVICE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.UserHandle.USER_ALL;
import static android.provider.DeviceConfig.NAMESPACE_AUTO_PIN_CONFIRMATION;

import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_NONE;
import static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PASSWORD;
@@ -1689,6 +1690,13 @@ public class LockSettingsService extends ILockSettings.Stub {
        if (newCredential.isPattern()) {
            setBoolean(LockPatternUtils.PATTERN_EVER_CHOSEN_KEY, true, userHandle);
        }
        if (DeviceConfig.getBoolean(NAMESPACE_AUTO_PIN_CONFIRMATION,
                "enable_auto_pin_confirmation", /* defaultValue= */ false)) {
            if (newCredential.isPin()) {
                setLong(LockPatternUtils.PIN_LENGTH, newCredential.size(), userHandle);
            }
        }

        updatePasswordHistory(newCredential, userHandle);
        mContext.getSystemService(TrustManager.class).reportEnabledTrustAgentsChanged(userHandle);
    }