Fix PIN/password lock UI update when locked out.

The ConfirmLockPassword screen (responsible for both PIN and password
locks) should not accept any input during the lock-out period after
consecutive incorrect unlock attempts. However, this is broken if the
activity is resumed from a paused state (e.g. from Recents).

In this CL, we clean up the logic around updating the UI controls, which
fixes the issue above and also hopefully simplifies potential future
work.

Bug: 63277910
Test: make RunSettingsRoboTests
Test: manual, both unified and separate work challenge
Change-Id: I752a5911d4445bf0caeea299ca3eb182e1defc62
This commit is contained in:
Charles He
2017-07-05 15:59:49 +01:00
parent 159461569d
commit 170801b6f8

View File

@@ -109,7 +109,6 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
private boolean mUsingFingerprint = false; private boolean mUsingFingerprint = false;
private AppearAnimationUtils mAppearAnimationUtils; private AppearAnimationUtils mAppearAnimationUtils;
private DisappearAnimationUtils mDisappearAnimationUtils; private DisappearAnimationUtils mDisappearAnimationUtils;
private boolean mBlockImm;
// required constructor for fragments // required constructor for fragments
public ConfirmLockPasswordFragment() { public ConfirmLockPasswordFragment() {
@@ -241,8 +240,8 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
mDetailsTextView.setAlpha(0f); mDetailsTextView.setAlpha(0f);
mCancelButton.setAlpha(0f); mCancelButton.setAlpha(0f);
mPasswordEntry.setAlpha(0f); mPasswordEntry.setAlpha(0f);
mErrorTextView.setAlpha(0f);
mFingerprintIcon.setAlpha(0f); mFingerprintIcon.setAlpha(0f);
mBlockImm = true;
} }
private View[] getActiveViews() { private View[] getActiveViews() {
@@ -253,6 +252,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
result.add(mCancelButton); result.add(mCancelButton);
} }
result.add(mPasswordEntry); result.add(mPasswordEntry);
result.add(mErrorTextView);
if (mFingerprintIcon.getVisibility() == View.VISIBLE) { if (mFingerprintIcon.getVisibility() == View.VISIBLE) {
result.add(mFingerprintIcon); result.add(mFingerprintIcon);
} }
@@ -262,13 +262,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
@Override @Override
public void startEnterAnimation() { public void startEnterAnimation() {
super.startEnterAnimation(); super.startEnterAnimation();
mAppearAnimationUtils.startAnimation(getActiveViews(), new Runnable() { mAppearAnimationUtils.startAnimation(getActiveViews(), this::updatePasswordEntry);
@Override
public void run() {
mBlockImm = false;
resetState();
}
});
} }
@Override @Override
@@ -294,7 +288,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
mCredentialCheckResultTracker.clearResult(); mCredentialCheckResultTracker.clearResult();
handleAttemptLockout(deadline); handleAttemptLockout(deadline);
} else { } else {
resetState(); updatePasswordEntry();
mErrorTextView.setText(""); mErrorTextView.setText("");
updateErrorMessage( updateErrorMessage(
mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId)); mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
@@ -312,36 +306,24 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
mUsingFingerprint = visible; mUsingFingerprint = visible;
} }
private void resetState() { private void updatePasswordEntry() {
if (mBlockImm) return; final boolean isLockedOut =
mPasswordEntry.setEnabled(true); mLockPatternUtils.getLockoutAttemptDeadline(mEffectiveUserId) != 0;
mPasswordEntryInputDisabler.setInputEnabled(true); mPasswordEntry.setEnabled(!isLockedOut);
if (shouldAutoShowSoftKeyboard()) { mPasswordEntryInputDisabler.setInputEnabled(!isLockedOut);
if (isLockedOut || mUsingFingerprint) {
mImm.hideSoftInputFromWindow(mPasswordEntry.getWindowToken(), 0 /*flags*/);
} else {
mPasswordEntry.scheduleShowSoftInput(); mPasswordEntry.scheduleShowSoftInput();
} }
} }
private boolean shouldAutoShowSoftKeyboard() {
return mPasswordEntry.isEnabled() && !mUsingFingerprint;
}
public void onWindowFocusChanged(boolean hasFocus) { public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus || mBlockImm) { if (!hasFocus) {
return; return;
} }
// Post to let window focus logic to finish to allow soft input show/hide properly. // Post to let window focus logic to finish to allow soft input show/hide properly.
mPasswordEntry.post(new Runnable() { mPasswordEntry.post(this::updatePasswordEntry);
@Override
public void run() {
if (shouldAutoShowSoftKeyboard()) {
resetState();
return;
}
mImm.hideSoftInputFromWindow(mPasswordEntry.getWindowToken(),
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
});
} }
private void handleNext() { private void handleNext() {
@@ -396,7 +378,7 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
} }
} }
mCredentialCheckResultTracker.setResult(matched, intent, timeoutMs, mCredentialCheckResultTracker.setResult(matched, intent, timeoutMs,
localUserId); localEffectiveUserId);
} }
}; };
mPendingLockCheck = (localEffectiveUserId == localUserId) mPendingLockCheck = (localEffectiveUserId == localUserId)
@@ -491,10 +473,8 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
} }
private void handleAttemptLockout(long elapsedRealtimeDeadline) { private void handleAttemptLockout(long elapsedRealtimeDeadline) {
long elapsedRealtime = SystemClock.elapsedRealtime();
mPasswordEntry.setEnabled(false);
mCountdownTimer = new CountDownTimer( mCountdownTimer = new CountDownTimer(
elapsedRealtimeDeadline - elapsedRealtime, elapsedRealtimeDeadline - SystemClock.elapsedRealtime(),
LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) { LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) {
@Override @Override
@@ -507,12 +487,13 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
@Override @Override
public void onFinish() { public void onFinish() {
resetState(); updatePasswordEntry();
mErrorTextView.setText(""); mErrorTextView.setText("");
updateErrorMessage( updateErrorMessage(
mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId)); mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
} }
}.start(); }.start();
updatePasswordEntry();
} }
public void onClick(View v) { public void onClick(View v) {