Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ecbed81

Browse files
mpietal79Android Build Coastguard Worker
authored andcommitted
Do not dismiss keyguard after SIM PUK unlock
After PUK unlock, multiple calls to KeyguardSecurityContainerController#dismiss() were being called from the KeyguardSimPukViewController, which begins the transition to the next security screen, if any. At the same time, other parts of the system, also listening to SIM events, recognize the PUK unlock and call KeyguardSecurityContainer#showSecurityScreen, which updates which security method comes next. After boot, this should be one of PIN, Password, Pattern, assuming they have a security method. If one of the first dismiss() calls comes AFTER the security method changes, this is incorrectly recognized by the code as a successful PIN/pattern/password unlock. This causes the keyguard to be marked as done, causing screen flickers and incorrect system state. The solution: every call to dismiss() should include a new parameter for the security method used. If there is a difference between this parameter and the current value in KeyguardSecurityContainerCallback, ignore the request, as the system state has changed. Fixes: 238804980 Bug: 218500036 Test: atest KeyguardSecurityContainerTest AdminSecondaryLockScreenControllerTest KeyguardHostViewControllerTest KeyguardSecurityContainerControllerTest Change-Id: I7c8714a177bc85fbce92f6e8fe911f74ca2ac243 Merged-In: I7c8714a177bc85fbce92f6e8fe911f74ca2ac243 (cherry picked from commit 37aeb26) (cherry picked from commit 3d89cc5) Merged-In: I7c8714a177bc85fbce92f6e8fe911f74ca2ac243
1 parent 71bbded commit ecbed81

12 files changed

+102
-26
lines changed

packages/SystemUI/src/com/android/keyguard/AdminSecondaryLockScreenController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.view.ViewGroup;
3434

3535
import com.android.internal.annotations.VisibleForTesting;
36+
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
3637
import com.android.keyguard.dagger.KeyguardBouncerScope;
3738
import com.android.systemui.dagger.qualifiers.Main;
3839

@@ -208,7 +209,7 @@ private void dismiss(int userId) {
208209
hide();
209210
if (mKeyguardCallback != null) {
210211
mKeyguardCallback.dismiss(/* securityVerified= */ true, userId,
211-
/* bypassSecondaryLockScreen= */true);
212+
/* bypassSecondaryLockScreen= */true, SecurityMode.Invalid);
212213
}
213214
}
214215
}

packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputViewController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void onPasswordChecked(int userId, boolean matched, int timeoutMs, boolean isVal
179179
if (dismissKeyguard) {
180180
mDismissing = true;
181181
mLatencyTracker.onActionStart(LatencyTracker.ACTION_LOCKSCREEN_UNLOCK);
182-
getKeyguardSecurityCallback().dismiss(true, userId);
182+
getKeyguardSecurityCallback().dismiss(true, userId, getSecurityMode());
183183
}
184184
} else {
185185
if (isValidPassword) {

packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void onTrustGrantedWithFlags(int flags, int userId) {
9090
Log.i(TAG, "TrustAgent dismissed Keyguard.");
9191
}
9292
mSecurityCallback.dismiss(false /* authenticated */, userId,
93-
/* bypassSecondaryLockScreen */ false);
93+
/* bypassSecondaryLockScreen */ false, SecurityMode.Invalid);
9494
} else {
9595
mViewMediatorCallback.playTrustedSound();
9696
}
@@ -102,9 +102,9 @@ public void onTrustGrantedWithFlags(int flags, int userId) {
102102

103103
@Override
104104
public boolean dismiss(boolean authenticated, int targetUserId,
105-
boolean bypassSecondaryLockScreen) {
105+
boolean bypassSecondaryLockScreen, SecurityMode expectedSecurityMode) {
106106
return mKeyguardSecurityContainerController.showNextSecurityScreenOrFinish(
107-
authenticated, targetUserId, bypassSecondaryLockScreen);
107+
authenticated, targetUserId, bypassSecondaryLockScreen, expectedSecurityMode);
108108
}
109109

110110
@Override
@@ -212,7 +212,8 @@ public void resetSecurityContainer() {
212212
* @return True if the keyguard is done.
213213
*/
214214
public boolean dismiss(int targetUserId) {
215-
return mSecurityCallback.dismiss(false, targetUserId, false);
215+
return mSecurityCallback.dismiss(false, targetUserId, false,
216+
getCurrentSecurityMode());
216217
}
217218

218219
/**
@@ -355,10 +356,10 @@ public int getTop() {
355356
}
356357

357358
public boolean handleBackKey() {
358-
if (mKeyguardSecurityContainerController.getCurrentSecurityMode()
359-
!= SecurityMode.None) {
359+
SecurityMode securityMode = mKeyguardSecurityContainerController.getCurrentSecurityMode();
360+
if (securityMode != SecurityMode.None) {
360361
mKeyguardSecurityContainerController.dismiss(
361-
false, KeyguardUpdateMonitor.getCurrentUser());
362+
false, KeyguardUpdateMonitor.getCurrentUser(), securityMode);
362363
return true;
363364
}
364365
return false;

packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ public boolean isVerifyUnlockOnly() {
5959
return false;
6060
}
6161
@Override
62-
public void dismiss(boolean securityVerified, int targetUserId) { }
62+
public void dismiss(boolean securityVerified, int targetUserId,
63+
SecurityMode expectedSecurityMode) { }
6364
@Override
6465
public void dismiss(boolean authenticated, int targetId,
65-
boolean bypassSecondaryLockScreen) { }
66+
boolean bypassSecondaryLockScreen, SecurityMode expectedSecurityMode) { }
6667
@Override
6768
public void onUserInput() { }
6869
@Override

packages/SystemUI/src/com/android/keyguard/KeyguardPatternViewController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private void onPatternChecked(int userId, boolean matched, int timeoutMs,
171171
if (dismissKeyguard) {
172172
mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Correct);
173173
mLatencyTracker.onActionStart(LatencyTracker.ACTION_LOCKSCREEN_UNLOCK);
174-
getKeyguardSecurityCallback().dismiss(true, userId);
174+
getKeyguardSecurityCallback().dismiss(true, userId, SecurityMode.Pattern);
175175
}
176176
} else {
177177
mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);

packages/SystemUI/src/com/android/keyguard/KeyguardSecurityCallback.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@
1515
*/
1616
package com.android.keyguard;
1717

18+
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
19+
1820
public interface KeyguardSecurityCallback {
1921

2022
/**
2123
* Dismiss the given security screen.
2224
* @param securityVerified true if the user correctly entered credentials for the given screen.
2325
* @param targetUserId a user that needs to be the foreground user at the dismissal completion.
26+
* @param expectedSecurityMode The security mode that is invoking this dismiss.
2427
*/
25-
void dismiss(boolean securityVerified, int targetUserId);
28+
void dismiss(boolean securityVerified, int targetUserId, SecurityMode expectedSecurityMode);
2629

2730
/**
2831
* Dismiss the given security screen.
2932
* @param securityVerified true if the user correctly entered credentials for the given screen.
3033
* @param targetUserId a user that needs to be the foreground user at the dismissal completion.
3134
* @param bypassSecondaryLockScreen true if the user can bypass the secondary lock screen,
3235
* if any, during this dismissal.
36+
* @param expectedSecurityMode The security mode that is invoking this dismiss.
3337
*/
34-
void dismiss(boolean securityVerified, int targetUserId, boolean bypassSecondaryLockScreen);
38+
void dismiss(boolean securityVerified, int targetUserId, boolean bypassSecondaryLockScreen,
39+
SecurityMode expectedSecurityMode);
3540

3641
/**
3742
* Manually report user activity to keep the device awake.

packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,12 @@ private void updateChildren(int translationY, float alpha) {
233233

234234
// Used to notify the container when something interesting happens.
235235
public interface SecurityCallback {
236-
boolean dismiss(boolean authenticated, int targetUserId, boolean bypassSecondaryLockScreen);
236+
/**
237+
* Potentially dismiss the current security screen, after validating that all device
238+
* security has been unlocked. Otherwise show the next screen.
239+
*/
240+
boolean dismiss(boolean authenticated, int targetUserId, boolean bypassSecondaryLockScreen,
241+
SecurityMode expectedSecurityMode);
237242

238243
void userActivity();
239244

packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,17 @@ public void onUserInput() {
153153
}
154154

155155
@Override
156-
public void dismiss(boolean authenticated, int targetId) {
157-
dismiss(authenticated, targetId, /* bypassSecondaryLockScreen */ false);
156+
public void dismiss(boolean authenticated, int targetId,
157+
SecurityMode expectedSecurityMode) {
158+
dismiss(authenticated, targetId, /* bypassSecondaryLockScreen */ false,
159+
expectedSecurityMode);
158160
}
159161

160162
@Override
161163
public void dismiss(boolean authenticated, int targetId,
162-
boolean bypassSecondaryLockScreen) {
163-
mSecurityCallback.dismiss(authenticated, targetId, bypassSecondaryLockScreen);
164+
boolean bypassSecondaryLockScreen, SecurityMode expectedSecurityMode) {
165+
mSecurityCallback.dismiss(authenticated, targetId, bypassSecondaryLockScreen,
166+
expectedSecurityMode);
164167
}
165168

166169
public boolean isVerifyUnlockOnly() {
@@ -350,8 +353,13 @@ public SecurityMode getCurrentSecurityMode() {
350353
return mCurrentSecurityMode;
351354
}
352355

353-
public void dismiss(boolean authenticated, int targetUserId) {
354-
mKeyguardSecurityCallback.dismiss(authenticated, targetUserId);
356+
/**
357+
* Potentially dismiss the current security screen, after validating that all device
358+
* security has been unlocked. Otherwise show the next screen.
359+
*/
360+
public void dismiss(boolean authenticated, int targetUserId,
361+
SecurityMode expectedSecurityMode) {
362+
mKeyguardSecurityCallback.dismiss(authenticated, targetUserId, expectedSecurityMode);
355363
}
356364

357365
public void reset() {
@@ -410,12 +418,21 @@ public void onStartingToHide() {
410418
* completion.
411419
* @param bypassSecondaryLockScreen true if the user is allowed to bypass the secondary
412420
* secondary lock screen requirement, if any.
421+
* @param expectedSecurityMode SecurityMode that is invoking this request. SecurityMode.Invalid
422+
* indicates that no check should be done
413423
* @return true if keyguard is done
414424
*/
415425
public boolean showNextSecurityScreenOrFinish(boolean authenticated, int targetUserId,
416-
boolean bypassSecondaryLockScreen) {
426+
boolean bypassSecondaryLockScreen, SecurityMode expectedSecurityMode) {
417427

418428
if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")");
429+
if (expectedSecurityMode != SecurityMode.Invalid
430+
&& expectedSecurityMode != getCurrentSecurityMode()) {
431+
Log.w(TAG, "Attempted to invoke showNextSecurityScreenOrFinish with securityMode "
432+
+ expectedSecurityMode + ", but current mode is " + getCurrentSecurityMode());
433+
return false;
434+
}
435+
419436
boolean finish = false;
420437
boolean strongAuth = false;
421438
int eventSubtype = -1;

packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void onSimCheckResponse(final PinResult result) {
168168
mRemainingAttempts = -1;
169169
mShowDefaultMessage = true;
170170
getKeyguardSecurityCallback().dismiss(
171-
true, KeyguardUpdateMonitor.getCurrentUser());
171+
true, KeyguardUpdateMonitor.getCurrentUser(),
172+
SecurityMode.SimPin);
172173
} else {
173174
mShowDefaultMessage = false;
174175
if (result.getResult() == PinResult.PIN_RESULT_TYPE_INCORRECT) {

packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public void onSimStateChanged(int subId, int slotId, int simState) {
6969
if (simState == TelephonyManager.SIM_STATE_READY) {
7070
mRemainingAttempts = -1;
7171
mShowDefaultMessage = true;
72-
getKeyguardSecurityCallback().dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
72+
getKeyguardSecurityCallback().dismiss(true, KeyguardUpdateMonitor.getCurrentUser(),
73+
SecurityMode.SimPuk);
7374
} else {
7475
resetState();
7576
}
@@ -278,7 +279,8 @@ void onSimLockChangedResponse(final PinResult result) {
278279
mShowDefaultMessage = true;
279280

280281
getKeyguardSecurityCallback().dismiss(
281-
true, KeyguardUpdateMonitor.getCurrentUser());
282+
true, KeyguardUpdateMonitor.getCurrentUser(),
283+
SecurityMode.SimPuk);
282284
} else {
283285
mShowDefaultMessage = false;
284286
if (result.getResult() == PinResult.PIN_RESULT_TYPE_INCORRECT) {

0 commit comments

Comments
 (0)