Merge "Make sure SIM PIN screen shows" into sc-dev

This commit is contained in:
Matt Pietal
2021-07-29 14:41:41 +00:00
committed by Android (Google) Code Review
2 changed files with 52 additions and 3 deletions

View File

@@ -398,6 +398,12 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
*/ */
private boolean mPendingLock; 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 * 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. * 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() { 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 @Override
public void onUserSwitching(int userId) { public void onUserSwitching(int userId) {
if (DEBUG) Log.d(TAG, String.format("onUserSwitching %d", 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"); + "showing; need to show keyguard so user can enter sim pin");
doKeyguardLocked(null); doKeyguardLocked(null);
} else { } else {
mPendingPinLock = true;
resetStateLocked(); resetStateLocked();
} }
} }
@@ -739,6 +759,9 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable,
@Override @Override
public void onBouncerVisiblityChanged(boolean shown) { public void onBouncerVisiblityChanged(boolean shown) {
synchronized (KeyguardViewMediator.this) { synchronized (KeyguardViewMediator.this) {
if (shown) {
mPendingPinLock = false;
}
adjustStatusBarLocked(shown, 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 */); setShowingLocked(showing, false /* forceCallbacks */);
} }

View File

@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@@ -33,8 +34,9 @@ import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager; import android.app.trust.TrustManager;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper; import android.testing.TestableLooper;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
@@ -65,7 +67,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@RunWithLooper @TestableLooper.RunWithLooper(setAsMainLooper = true)
@SmallTest @SmallTest
public class KeyguardViewMediatorTest extends SysuiTestCase { public class KeyguardViewMediatorTest extends SysuiTestCase {
private KeyguardViewMediator mViewMediator; private KeyguardViewMediator mViewMediator;
@@ -124,6 +126,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
mUnlockedScreenOffAnimationController, mUnlockedScreenOffAnimationController,
() -> mNotificationShadeDepthController); () -> mNotificationShadeDepthController);
mViewMediator.start(); mViewMediator.start();
mViewMediator.onSystemReady();
} }
@Test @Test
@@ -160,4 +163,27 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
mViewMediator.onDozeAmountChanged(1f, 1f); mViewMediator.onDozeAmountChanged(1f, 1f);
assertFalse(mViewMediator.isAnimatingScreenOff()); 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);
}
} }