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

Commit 51e3a672 authored by Jim Miller's avatar Jim Miller
Browse files

Don't wipe device because of short PIN, patterns or passwords

This fixes a bug where we were counting short PIN, patterns and
passwords as attempts. For devices with a device policy admin,
this would cause devices to get wiped after a short amount of
interaction with the UI.

Fixes bug 22844609

Change-Id: I7616b38d954f89d4a2cee23f9aec1b898041b1f2
parent 0ca1e98f
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -53,15 +53,18 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
        super(context, attrs);
    }

    @Override
    public void setKeyguardCallback(KeyguardSecurityCallback callback) {
        mCallback = callback;
    }

    @Override
    public void setLockPatternUtils(LockPatternUtils utils) {
        mLockPatternUtils = utils;
        mEnableHaptics = mLockPatternUtils.isTactileFeedbackEnabled();
    }

    @Override
    public void reset() {
        // start fresh
        resetPasswordText(false /* animate */);
@@ -95,6 +98,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
        }
    }

    @Override
    public void onEmergencyButtonClickedWhenInCall() {
        mCallback.reset();
    }
@@ -115,11 +119,11 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
            mPendingLockCheck.cancel(false);
        }

        if (entry.length() < MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT) {
        if (entry.length() <= MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT) {
            // to avoid accidental lockout, only count attempts that are long enough to be a
            // real password. This may require some tweaking.
            setPasswordEntryInputEnabled(true);
            onPasswordChecked(entry, false, 0);
            onPasswordChecked(false /* matched */, 0, false /* not valid - too short */);
            return;
        }

@@ -132,25 +136,28 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
                    public void onChecked(boolean matched, int timeoutMs) {
                        setPasswordEntryInputEnabled(true);
                        mPendingLockCheck = null;
                        onPasswordChecked(entry, matched, timeoutMs);
                        onPasswordChecked(matched, timeoutMs, true /* isValidPassword */);
                    }
                });
    }

    private void onPasswordChecked(String entry, boolean matched, int timeoutMs) {
    private void onPasswordChecked(boolean matched, int timeoutMs, boolean isValidPassword) {
        if (matched) {
            mCallback.reportUnlockAttempt(true, 0);
            mCallback.dismiss(true);
        } else {
            if (isValidPassword) {
                mCallback.reportUnlockAttempt(false, timeoutMs);
            int attempts = KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts();
                if (timeoutMs > 0) {
                    long deadline = mLockPatternUtils.setLockoutAttemptDeadline(
                            KeyguardUpdateMonitor.getCurrentUser(), timeoutMs);
                    handleAttemptLockout(deadline);
                }
            }
            if (timeoutMs == 0) {
                mSecurityMessageDisplay.setMessage(getWrongPasswordStringId(), true);
            }
        }
        resetPasswordText(true /* animate */);
    }

+24 −14
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
     * Useful for clearing out the wrong pattern after a delay
     */
    private Runnable mCancelPatternRunnable = new Runnable() {
        @Override
        public void run() {
            mLockPatternView.clearPattern();
        }
@@ -117,10 +118,12 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
                R.dimen.disappear_y_translation);
    }

    @Override
    public void setKeyguardCallback(KeyguardSecurityCallback callback) {
        mCallback = callback;
    }

    @Override
    public void setLockPatternUtils(LockPatternUtils utils) {
        mLockPatternUtils = utils;
    }
@@ -153,6 +156,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        }
    }

    @Override
    public void onEmergencyButtonClickedWhenInCall() {
        mCallback.reset();
    }
@@ -174,6 +178,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
        return result;
    }

    @Override
    public void reset() {
        // reset lock pattern
        mLockPatternView.enableInput();
@@ -207,18 +212,22 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit

    private class UnlockPatternListener implements LockPatternView.OnPatternListener {

        @Override
        public void onPatternStart() {
            mLockPatternView.removeCallbacks(mCancelPatternRunnable);
            mSecurityMessageDisplay.setMessage("", false);
        }

        @Override
        public void onPatternCleared() {
        }

        @Override
        public void onPatternCellAdded(List<LockPatternView.Cell> pattern) {
            mCallback.userActivity();
        }

        @Override
        public void onPatternDetected(final List<LockPatternView.Cell> pattern) {
            mLockPatternView.disableInput();
            if (mPendingLockCheck != null) {
@@ -227,7 +236,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit

            if (pattern.size() < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) {
                mLockPatternView.enableInput();
                onPatternChecked(pattern, false, 0);
                onPatternChecked(false, 0, false /* not valid - too short */);
                return;
            }

@@ -240,29 +249,30 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
                        public void onChecked(boolean matched, int timeoutMs) {
                            mLockPatternView.enableInput();
                            mPendingLockCheck = null;
                            onPatternChecked(pattern, matched, timeoutMs);
                            onPatternChecked(matched, timeoutMs, true);
                        }
                    });
            if (pattern.size() > MIN_PATTERN_BEFORE_POKE_WAKELOCK) {
                mCallback.userActivity();
            }
        }

        private void onPatternChecked(List<LockPatternView.Cell> pattern, boolean matched,
                int timeoutMs) {
        private void onPatternChecked(boolean matched, int timeoutMs, boolean isValidPattern) {
            if (matched) {
                mCallback.reportUnlockAttempt(true, 0);
                mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct);
                mCallback.dismiss(true);
            } else {
                if (pattern.size() > MIN_PATTERN_BEFORE_POKE_WAKELOCK) {
                    mCallback.userActivity();
                }
                mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
                if (isValidPattern) {
                    mCallback.reportUnlockAttempt(false, timeoutMs);
                int attempts = mKeyguardUpdateMonitor.getFailedUnlockAttempts();
                    if (timeoutMs > 0) {
                        long deadline = mLockPatternUtils.setLockoutAttemptDeadline(
                                KeyguardUpdateMonitor.getCurrentUser(), timeoutMs);
                        handleAttemptLockout(deadline);
                } else {
                    }
                }
                if (timeoutMs == 0) {
                    mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern, true);
                    mLockPatternView.postDelayed(mCancelPatternRunnable, PATTERN_CLEAR_TIMEOUT_MS);
                }