summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chandru S <chandruis@google.com> 2022-09-20 06:36:58 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-09-20 06:36:58 +0000
commitd5d35fb282d5b8cefebeb2c51fc164faf5590e1c (patch)
treeef7dafae636b603c6e953a05b0e05586d3c99429
parent03ef589f1d05581805303237dde734ad743c2649 (diff)
parent1c1f58ca75f648c6c7c06ebdd354183881425ea4 (diff)
Merge "Cleans up any stray instances of KeyguardUpdateMonitor that might still have listeners attached to system services." into tm-qpr-dev
-rw-r--r--packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java25
1 files changed, 18 insertions, 7 deletions
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
index 0275152c680e..ae980f58cb3f 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java
@@ -328,8 +328,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@After
public void tearDown() {
mMockitoSession.finishMocking();
- mKeyguardUpdateMonitor.removeCallback(mTestCallback);
- mKeyguardUpdateMonitor.destroy();
+ cleanupKeyguardUpdateMonitor();
}
@Test
@@ -351,6 +350,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test
public void testSimStateInitialized() {
+ cleanupKeyguardUpdateMonitor();
final int subId = 3;
final int state = TelephonyManager.SIM_STATE_ABSENT;
@@ -1205,7 +1205,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test
public void testShouldListenForFace_whenFaceManagerNotAvailable_returnsFalse() {
- mFaceManager = null;
+ cleanupKeyguardUpdateMonitor();
+ mSpiedContext.addMockSystemService(FaceManager.class, null);
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(false);
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
assertThat(mKeyguardUpdateMonitor.shouldListenForFace()).isFalse();
@@ -1258,6 +1260,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test
public void testShouldListenForFace_whenUserIsNotPrimary_returnsFalse() throws RemoteException {
+ cleanupKeyguardUpdateMonitor();
// This disables face auth
when(mUserManager.isPrimaryUser()).thenReturn(false);
mKeyguardUpdateMonitor =
@@ -1587,9 +1590,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test
public void testFingerAcquired_wakesUpPowerManager() {
- mContext.getOrCreateTestableResources().addOverride(
+ cleanupKeyguardUpdateMonitor();
+ mSpiedContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.kg_wake_on_acquire_start, true);
- mSpiedContext = spy(mContext);
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
fingerprintAcquireStart();
@@ -1598,15 +1601,23 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test
public void testFingerAcquired_doesNotWakeUpPowerManager() {
- mContext.getOrCreateTestableResources().addOverride(
+ cleanupKeyguardUpdateMonitor();
+ mSpiedContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.kg_wake_on_acquire_start, false);
- mSpiedContext = spy(mContext);
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
fingerprintAcquireStart();
verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
}
+ private void cleanupKeyguardUpdateMonitor() {
+ if (mKeyguardUpdateMonitor != null) {
+ mKeyguardUpdateMonitor.removeCallback(mTestCallback);
+ mKeyguardUpdateMonitor.destroy();
+ mKeyguardUpdateMonitor = null;
+ }
+ }
+
private void faceAuthLockedOut() {
mKeyguardUpdateMonitor.mFaceAuthenticationCallback
.onAuthenticationError(FaceManager.FACE_ERROR_LOCKOUT_PERMANENT, "");