From 7d938ee7f496c3502a3327021b78da5b19ceaaa5 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Wed, 28 Jul 2021 13:10:47 -0400 Subject: [PATCH] Make sure SIM PIN screen shows It is possible to receive SIM events that alert the keyguard to show the SIM PIN unlock screens. However, if these events are received after keyguard has been told to dismiss but before it is actually dismissed, this event gets ignored. The fix: add a flag to look for this state. If we get the keyguard dismissed event and the bouncer has not shown, bring back to the keyguard. Fixes: 192048149 Test: atest KeyguardViewMediatorTest Change-Id: I43de785252827d78a86d075ee7ec0861778e3360 --- .../keyguard/KeyguardViewMediator.java | 25 +++++++++++++++- .../keyguard/KeyguardViewMediatorTest.java | 30 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index c7c25903923a0..84cb12cf5e49a 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -398,6 +398,12 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, */ private boolean mPendingLock; + /** + * When starting to go away, flag a need to show the PIN lock so the keyguard can be brought + * back. + */ + private boolean mPendingPinLock = false; + /** * Whether a power button gesture (such as double tap for camera) has been detected. This is * delivered directly from {@link KeyguardService}, immediately upon the gesture being detected. @@ -471,6 +477,19 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { + @Override + public void onKeyguardVisibilityChanged(boolean showing) { + synchronized (KeyguardViewMediator.this) { + if (!showing && mPendingPinLock) { + Log.i(TAG, "PIN lock requested, starting keyguard"); + + // Bring the keyguard back in order to show the PIN lock + mPendingPinLock = false; + doKeyguardLocked(null); + } + } + } + @Override public void onUserSwitching(int userId) { if (DEBUG) Log.d(TAG, String.format("onUserSwitching %d", userId)); @@ -591,6 +610,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + "showing; need to show keyguard so user can enter sim pin"); doKeyguardLocked(null); } else { + mPendingPinLock = true; resetStateLocked(); } } @@ -739,6 +759,9 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, @Override public void onBouncerVisiblityChanged(boolean shown) { synchronized (KeyguardViewMediator.this) { + if (shown) { + mPendingPinLock = false; + } adjustStatusBarLocked(shown, false); } } @@ -2783,7 +2806,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, } } - private void setShowingLocked(boolean showing) { + void setShowingLocked(boolean showing) { setShowingLocked(showing, false /* forceCallbacks */); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java index 1dacc6245d841..ad08780316799 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -33,8 +34,9 @@ import android.app.admin.DevicePolicyManager; import android.app.trust.TrustManager; import android.os.PowerManager; import android.os.PowerManager.WakeLock; +import android.telephony.TelephonyManager; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper.RunWithLooper; +import android.testing.TestableLooper; import androidx.test.filters.SmallTest; @@ -65,7 +67,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; @RunWith(AndroidTestingRunner.class) -@RunWithLooper +@TestableLooper.RunWithLooper(setAsMainLooper = true) @SmallTest public class KeyguardViewMediatorTest extends SysuiTestCase { private KeyguardViewMediator mViewMediator; @@ -124,6 +126,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { mUnlockedScreenOffAnimationController, () -> mNotificationShadeDepthController); mViewMediator.start(); + mViewMediator.onSystemReady(); } @Test @@ -160,4 +163,27 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { mViewMediator.onDozeAmountChanged(1f, 1f); assertFalse(mViewMediator.isAnimatingScreenOff()); } + + @Test + public void restoreBouncerWhenSimLockedAndKeyguardIsGoingAway() { + // When showing and provisioned + when(mUpdateMonitor.isDeviceProvisioned()).thenReturn(true); + mViewMediator.setShowingLocked(true); + + // and a SIM becomes locked and requires a PIN + mViewMediator.mUpdateCallback.onSimStateChanged( + 1 /* subId */, + 0 /* slotId */, + TelephonyManager.SIM_STATE_PIN_REQUIRED); + + // and the keyguard goes away + mViewMediator.setShowingLocked(false); + when(mStatusBarKeyguardViewManager.isShowing()).thenReturn(false); + mViewMediator.mUpdateCallback.onKeyguardVisibilityChanged(false); + + TestableLooper.get(this).processAllMessages(); + + // then make sure it comes back + verify(mStatusBarKeyguardViewManager, atLeast(1)).show(null); + } }