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

Commit 15a27cde authored by Aaron Liu's avatar Aaron Liu
Browse files

Do not refetch pin length

Make sure to use cached pin length to save on performance cost.

Fixes: 288308956
Test: authenticate via auto pin confirmation
Test: test auto pin confirmation with deleting one char and full deltion
Test: test non auto pin screen
Change-Id: I9bc97666cd431ed31f933ea6006957f76e9014dc
parent ce4653f7
Loading
Loading
Loading
Loading
+18 −23
Original line number Diff line number Diff line
@@ -43,6 +43,15 @@ public class KeyguardPinViewController
    private long mPinLength;

    private boolean mDisabledAutoConfirmation;
    /**
     * Responsible for identifying if PIN hinting is to be enabled or not
     */
    private boolean mIsPinHinting;

    /**
     * Responsible for identifying if auto confirm is enabled or not in Settings
     */
    private boolean mIsAutoPinConfirmEnabledInSettings;

    protected KeyguardPinViewController(KeyguardPINView view,
            KeyguardUpdateMonitor keyguardUpdateMonitor,
@@ -63,6 +72,9 @@ public class KeyguardPinViewController
        mFeatureFlags = featureFlags;
        mBackspaceKey = view.findViewById(R.id.delete_button);
        mPinLength = mLockPatternUtils.getPinLength(KeyguardUpdateMonitor.getCurrentUser());
        mIsPinHinting = mPinLength == DEFAULT_PIN_LENGTH;
        mIsAutoPinConfirmEnabledInSettings = mLockPatternUtils.isAutoPinConfirmEnabled(
                KeyguardUpdateMonitor.getCurrentUser());
    }

    @Override
@@ -82,7 +94,7 @@ public class KeyguardPinViewController

    protected void onUserInput() {
        super.onUserInput();
        if (isAutoPinConfirmEnabledInSettings()) {
        if (mIsAutoPinConfirmEnabledInSettings) {
            updateAutoConfirmationState();
            if (mPasswordEntry.getText().length() == mPinLength
                    && mOkButton.getVisibility() == View.INVISIBLE) {
@@ -130,7 +142,7 @@ public class KeyguardPinViewController
     * Updates the visibility of the OK button for auto confirm feature
     */
    private void updateOKButtonVisibility() {
        if (isAutoPinConfirmEnabledInSettings() && !mDisabledAutoConfirmation) {
        if (mIsPinHinting && !mDisabledAutoConfirmation) {
            mOkButton.setVisibility(View.INVISIBLE);
        } else {
            mOkButton.setVisibility(View.VISIBLE);
@@ -142,10 +154,9 @@ public class KeyguardPinViewController
     * Visibility changes are only for auto confirmation configuration.
     */
    private void updateBackSpaceVisibility() {
        boolean isAutoConfirmation = isAutoPinConfirmEnabledInSettings();
        mBackspaceKey.setTransparentMode(/* isTransparentMode= */
                isAutoConfirmation && !mDisabledAutoConfirmation);
        if (isAutoConfirmation) {
                mIsAutoPinConfirmEnabledInSettings && !mDisabledAutoConfirmation);
        if (mIsAutoPinConfirmEnabledInSettings) {
            if (mPasswordEntry.getText().length() > 0
                    || mDisabledAutoConfirmation) {
                mBackspaceKey.setVisibility(View.VISIBLE);
@@ -155,24 +166,8 @@ public class KeyguardPinViewController
        }
    }
    /** Updates whether to use pin hinting or not. */
    void updatePinHinting() {
        mPasswordEntry.setIsPinHinting(isAutoPinConfirmEnabledInSettings() && isPinHinting()
    private void updatePinHinting() {
        mPasswordEntry.setIsPinHinting(mIsAutoPinConfirmEnabledInSettings && mIsPinHinting
                && !mDisabledAutoConfirmation);
    }

    /**
     * Responsible for identifying if PIN hinting is to be enabled or not
     */
    private boolean isPinHinting() {
        return mLockPatternUtils.getPinLength(KeyguardUpdateMonitor.getCurrentUser())
                == DEFAULT_PIN_LENGTH;
    }

    /**
     * Responsible for identifying if auto confirm is enabled or not in Settings
     */
    private boolean isAutoPinConfirmEnabledInSettings() {
        //Checks if user has enabled the auto confirm in Settings
        return mLockPatternUtils.isAutoPinConfirmEnabled(KeyguardUpdateMonitor.getCurrentUser());
    }
}
+23 −15
Original line number Diff line number Diff line
@@ -97,21 +97,7 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
        `when`(keyguardPinView.findViewById<NumPadButton>(R.id.delete_button))
            .thenReturn(deleteButton)
        `when`(keyguardPinView.findViewById<View>(R.id.key_enter)).thenReturn(enterButton)
        pinViewController =
            KeyguardPinViewController(
                keyguardPinView,
                keyguardUpdateMonitor,
                securityMode,
                lockPatternUtils,
                mKeyguardSecurityCallback,
                keyguardMessageAreaControllerFactory,
                mLatencyTracker,
                liftToActivateListener,
                mEmergencyButtonController,
                falsingCollector,
                postureController,
                featureFlags
            )
        constructViewController()
    }

    @Test
@@ -135,8 +121,10 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
        `when`(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true)
        `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(3)
        `when`(passwordTextView.text).thenReturn("")
        constructViewController()

        pinViewController.startAppearAnimation()

        verify(deleteButton).visibility = View.INVISIBLE
        verify(enterButton).visibility = View.INVISIBLE
        verify(passwordTextView).setUsePinShapes(true)
@@ -150,8 +138,10 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
        `when`(lockPatternUtils.isAutoPinConfirmEnabled(anyInt())).thenReturn(true)
        `when`(lockPatternUtils.getCurrentFailedPasswordAttempts(anyInt())).thenReturn(6)
        `when`(passwordTextView.text).thenReturn("")
        constructViewController()

        pinViewController.startAppearAnimation()

        verify(deleteButton).visibility = View.VISIBLE
        verify(enterButton).visibility = View.VISIBLE
        verify(passwordTextView).setUsePinShapes(true)
@@ -163,4 +153,22 @@ class KeyguardPinViewControllerTest : SysuiTestCase() {
        pinViewController.handleAttemptLockout(0)
        verify(lockPatternUtils).getCurrentFailedPasswordAttempts(anyInt())
    }

    fun constructViewController() {
        pinViewController =
            KeyguardPinViewController(
                keyguardPinView,
                keyguardUpdateMonitor,
                securityMode,
                lockPatternUtils,
                mKeyguardSecurityCallback,
                keyguardMessageAreaControllerFactory,
                mLatencyTracker,
                liftToActivateListener,
                mEmergencyButtonController,
                falsingCollector,
                postureController,
                featureFlags
            )
    }
}