diff options
author | Andres Morales <anmorales@google.com> | 2015-05-27 18:37:21 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-27 18:37:32 +0000 |
commit | 5ccfe51d8b9ae4f73a3b0fdb553b807cf5691582 (patch) | |
tree | 93187b35ac868eec08498685ad91c2a5ee5272cd /packages | |
parent | 77aa9afe0c67ca7285ed81664571f3d6f567eb9b (diff) | |
parent | 2397427cb1a0bad8a42e6a342dcf29b31e40a234 (diff) | |
download | frameworks_base-5ccfe51d8b9ae4f73a3b0fdb553b807cf5691582.zip frameworks_base-5ccfe51d8b9ae4f73a3b0fdb553b807cf5691582.tar.gz frameworks_base-5ccfe51d8b9ae4f73a3b0fdb553b807cf5691582.tar.bz2 |
Merge "[LockSettings] migrate password attempt throttling to hardware" into mnc-dev
Diffstat (limited to 'packages')
4 files changed, 44 insertions, 47 deletions
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java index 6295de4..4edc1c9 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java @@ -114,35 +114,40 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout if (mPendingLockCheck != null) { mPendingLockCheck.cancel(false); } + + 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); + return; + } + mPendingLockCheck = LockPatternChecker.checkPassword( mLockPatternUtils, entry, KeyguardUpdateMonitor.getCurrentUser(), new LockPatternChecker.OnCheckCallback() { @Override - public void onChecked(boolean matched) { + public void onChecked(boolean matched, int timeoutMs) { setPasswordEntryInputEnabled(true); mPendingLockCheck = null; - onPasswordChecked(entry, matched); + onPasswordChecked(entry, matched, timeoutMs); } }); } - private void onPasswordChecked(String entry, boolean matched) { + private void onPasswordChecked(String entry, boolean matched, int timeoutMs) { if (matched) { - mCallback.reportUnlockAttempt(true); + mCallback.reportUnlockAttempt(true, 0); mCallback.dismiss(true); } else { - 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. - mCallback.reportUnlockAttempt(false); - int attempts = KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(); - if (0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) { - long deadline = mLockPatternUtils.setLockoutAttemptDeadline( - KeyguardUpdateMonitor.getCurrentUser()); - handleAttemptLockout(deadline); - } + mCallback.reportUnlockAttempt(false, timeoutMs); + int attempts = KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(); + if (timeoutMs > 0) { + long deadline = mLockPatternUtils.setLockoutAttemptDeadline( + KeyguardUpdateMonitor.getCurrentUser(), timeoutMs); + handleAttemptLockout(deadline); } mSecurityMessageDisplay.setMessage(getWrongPasswordStringId(), true); } diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java index 35c6873..ed595c0 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java @@ -224,23 +224,30 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mPendingLockCheck.cancel(false); } + if (pattern.size() < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) { + mLockPatternView.enableInput(); + onPatternChecked(pattern, false, 0); + return; + } + mPendingLockCheck = LockPatternChecker.checkPattern( mLockPatternUtils, pattern, KeyguardUpdateMonitor.getCurrentUser(), new LockPatternChecker.OnCheckCallback() { @Override - public void onChecked(boolean matched) { + public void onChecked(boolean matched, int timeoutMs) { mLockPatternView.enableInput(); mPendingLockCheck = null; - onPatternChecked(pattern, matched); + onPatternChecked(pattern, matched, timeoutMs); } }); } - private void onPatternChecked(List<LockPatternView.Cell> pattern, boolean matched) { + private void onPatternChecked(List<LockPatternView.Cell> pattern, boolean matched, + int timeoutMs) { if (matched) { - mCallback.reportUnlockAttempt(true); + mCallback.reportUnlockAttempt(true, 0); mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct); mCallback.dismiss(true); } else { @@ -248,16 +255,11 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mCallback.userActivity(); } mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong); - boolean registeredAttempt = - pattern.size() >= LockPatternUtils.MIN_PATTERN_REGISTER_FAIL; - if (registeredAttempt) { - mCallback.reportUnlockAttempt(false); - } + mCallback.reportUnlockAttempt(false, timeoutMs); int attempts = mKeyguardUpdateMonitor.getFailedUnlockAttempts(); - if (registeredAttempt && - 0 == (attempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT)) { + if (timeoutMs > 0) { long deadline = mLockPatternUtils.setLockoutAttemptDeadline( - KeyguardUpdateMonitor.getCurrentUser()); + KeyguardUpdateMonitor.getCurrentUser(), timeoutMs); handleAttemptLockout(deadline); } else { mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern, true); diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityCallback.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityCallback.java index 5877bc8..836c195 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityCallback.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityCallback.java @@ -37,8 +37,10 @@ public interface KeyguardSecurityCallback { /** * Call to report an unlock attempt. * @param success set to 'true' if user correctly entered security credentials. + * @param timeoutMs timeout in milliseconds to wait before reattempting an unlock. + * Only nonzero if 'success' is false */ - void reportUnlockAttempt(boolean success); + void reportUnlockAttempt(boolean success, int timeoutMs); /** * Resets the keyguard view. diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java index 4d89a8d..d17b25a 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -176,8 +176,8 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe dialog.show(); } - private void showTimeoutDialog() { - int timeoutInSeconds = (int) LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS / 1000; + private void showTimeoutDialog(int timeoutMs) { + int timeoutInSeconds = (int) timeoutMs / 1000; int messageId = 0; switch (mSecurityModel.getSecurityMode()) { @@ -244,16 +244,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe showDialog(null, message); } - private void showAlmostAtAccountLoginDialog() { - final int timeoutInSeconds = (int) LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS / 1000; - final int count = LockPatternUtils.FAILED_ATTEMPTS_BEFORE_RESET - - LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT; - String message = mContext.getString(R.string.kg_failed_attempts_almost_at_login, - count, LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT, timeoutInSeconds); - showDialog(null, message); - } - - private void reportFailedUnlockAttempt() { + private void reportFailedUnlockAttempt(int timeoutMs) { final KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext); final int failedAttempts = monitor.getFailedUnlockAttempts() + 1; // +1 for this time @@ -290,14 +281,11 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe Slog.i(TAG, "Too many unlock attempts; user " + expiringUser + " will be wiped!"); showWipeDialog(failedAttempts, userType); } - } else { - showTimeout = - (failedAttempts % LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) == 0; } monitor.reportFailedUnlockAttempt(); mLockPatternUtils.reportFailedPasswordAttempt(KeyguardUpdateMonitor.getCurrentUser()); - if (showTimeout) { - showTimeoutDialog(); + if (timeoutMs > 0) { + showTimeoutDialog(timeoutMs); } } @@ -425,14 +413,14 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe return mIsVerifyUnlockOnly; } - public void reportUnlockAttempt(boolean success) { + public void reportUnlockAttempt(boolean success, int timeoutMs) { KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext); if (success) { monitor.clearFailedUnlockAttempts(); mLockPatternUtils.reportSuccessfulPasswordAttempt( KeyguardUpdateMonitor.getCurrentUser()); } else { - KeyguardSecurityContainer.this.reportFailedUnlockAttempt(); + KeyguardSecurityContainer.this.reportFailedUnlockAttempt(timeoutMs); } } @@ -448,7 +436,7 @@ public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSe @Override public void userActivity() { } @Override - public void reportUnlockAttempt(boolean success) { } + public void reportUnlockAttempt(boolean success, int timeoutMs) { } @Override public boolean isVerifyUnlockOnly() { return false; } @Override |