Skip to content

Commit 63f9b81

Browse files
author
Jim Miller
committed
Fix inoperative "Forgot pattern" button when face unlock enabled
This fixes a bug where the forgot pattern button wasn't working because the logic for face unlock was interfering with determining the proper backup to use. The fix: - adds a new state to SecurityMode so we have an initial condition we can check for. - passes the current mode to SecurityModel.getBackupSecurityMode() so it relies on the current state. - prevents face unlock from invoking callbacks that change state once we're no longer showing face unlock. Fixes bug 7346989 Change-Id: I4e64515efbbad712f11c820e690b458f352bf46c
1 parent a30d969 commit 63f9b81

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class KeyguardHostView extends KeyguardViewBase {
7979
private boolean mEnableMenuKey;
8080
private boolean mIsVerifyUnlockOnly;
8181
private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView
82-
private SecurityMode mCurrentSecuritySelection = SecurityMode.None;
82+
private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;
8383

8484
protected Runnable mLaunchRunnable;
8585

@@ -433,7 +433,8 @@ void showPrimarySecurityScreen(boolean turningOff) {
433433
*/
434434
private void showBackupSecurityScreen() {
435435
if (DEBUG) Log.d(TAG, "showBackupSecurity()");
436-
showSecurityScreen(mSecurityModel.getBackupSecurityMode());
436+
SecurityMode backup = mSecurityModel.getBackupSecurityMode(mCurrentSecuritySelection);
437+
showSecurityScreen(backup);
437438
}
438439

439440
public boolean showNextSecurityScreenIfPresent() {
@@ -543,6 +544,45 @@ public void run() {
543544

544545
private KeyguardStatusViewManager mKeyguardStatusViewManager;
545546

547+
// Used to ignore callbacks from methods that are no longer current (e.g. face unlock).
548+
// This avoids unwanted asynchronous events from messing with the state.
549+
private KeyguardSecurityCallback mNullCallback = new KeyguardSecurityCallback() {
550+
551+
@Override
552+
public void userActivity(long timeout) {
553+
}
554+
555+
@Override
556+
public void showBackupSecurity() {
557+
}
558+
559+
@Override
560+
public void setOnDismissRunnable(Runnable runnable) {
561+
}
562+
563+
@Override
564+
public void reportSuccessfulUnlockAttempt() {
565+
}
566+
567+
@Override
568+
public void reportFailedUnlockAttempt() {
569+
}
570+
571+
@Override
572+
public boolean isVerifyUnlockOnly() {
573+
return false;
574+
}
575+
576+
@Override
577+
public int getFailedAttempts() {
578+
return 0;
579+
}
580+
581+
@Override
582+
public void dismiss(boolean securityVerified) {
583+
}
584+
};
585+
546586
@Override
547587
public void reset() {
548588
mIsVerifyUnlockOnly = false;
@@ -568,9 +608,10 @@ private KeyguardSecurityView getSecurityView(SecurityMode securityMode) {
568608
}
569609
}
570610
boolean simPukFullScreen = getResources().getBoolean(R.bool.kg_sim_puk_account_full_screen);
571-
if (view == null) {
611+
int layoutId = getLayoutIdFor(securityMode);
612+
if (view == null && layoutId != 0) {
572613
final LayoutInflater inflater = LayoutInflater.from(mContext);
573-
View v = inflater.inflate(getLayoutIdFor(securityMode), this, false);
614+
View v = inflater.inflate(layoutId, this, false);
574615
mSecurityViewContainer.addView(v);
575616
updateSecurityView(v);
576617

@@ -617,8 +658,12 @@ private void showSecurityScreen(SecurityMode securityMode) {
617658
KeyguardSecurityView newView = getSecurityView(securityMode);
618659

619660
// Emulate Activity life cycle
620-
oldView.onPause();
661+
if (oldView != null) {
662+
oldView.onPause();
663+
oldView.setKeyguardCallback(mNullCallback); // ignore requests from old view
664+
}
621665
newView.onResume();
666+
newView.setKeyguardCallback(mCallback);
622667

623668
final boolean needsInput = newView.needsInput();
624669
if (mViewMediatorCallback != null) {
@@ -749,7 +794,7 @@ private int getLayoutIdFor(SecurityMode securityMode) {
749794
case SimPin: return R.layout.keyguard_sim_pin_view;
750795
case SimPuk: return R.layout.keyguard_sim_puk_view;
751796
default:
752-
throw new RuntimeException("No layout for securityMode " + securityMode);
797+
return 0;
753798
}
754799
}
755800

policy/src/com/android/internal/policy/impl/keyguard/KeyguardSecurityModel.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class KeyguardSecurityModel {
2828
* @see com.android.internal.policy.impl.LockPatternKeyguardView#getUnlockMode()
2929
*/
3030
enum SecurityMode {
31+
Invalid, // NULL state
3132
None, // No security enabled
3233
Pattern, // Unlock by drawing a pattern.
3334
Password, // Unlock by entering a password or PIN
@@ -53,7 +54,7 @@ void setLockPatternUtils(LockPatternUtils utils) {
5354
* Returns true if biometric unlock is installed and selected. If this returns false there is
5455
* no need to even construct the biometric unlock.
5556
*/
56-
private boolean isBiometricUnlockEnabled() {
57+
boolean isBiometricUnlockEnabled() {
5758
return mLockPatternUtils.usingBiometricWeak()
5859
&& mLockPatternUtils.isBiometricWeakInstalled();
5960
}
@@ -128,15 +129,7 @@ SecurityMode getAlternateFor(SecurityMode mode) {
128129
*
129130
* @return backup method or current security mode
130131
*/
131-
SecurityMode getBackupSecurityMode() {
132-
SecurityMode mode = getSecurityMode();
133-
134-
// Note that getAlternateFor() cannot be called here because we want to get the backup for
135-
// biometric unlock even if it's suppressed; it just has to be enabled.
136-
if (isBiometricUnlockEnabled()
137-
&& (mode == SecurityMode.Password || mode == SecurityMode.Pattern)) {
138-
mode = SecurityMode.Biometric;
139-
}
132+
SecurityMode getBackupSecurityMode(SecurityMode mode) {
140133
switch(mode) {
141134
case Biometric:
142135
return getSecurityMode();

0 commit comments

Comments
 (0)