Merge "Cleans up any stray instances of KeyguardUpdateMonitor that might still have listeners attached to system services." into tm-qpr-dev am: d5d35fb282

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19967845

Change-Id: I1b2dc31042020e004b4344364b8cdab63840f2b8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chandru S
2022-09-20 06:57:24 +00:00
committed by Automerger Merge Worker

View File

@@ -328,8 +328,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@After @After
public void tearDown() { public void tearDown() {
mMockitoSession.finishMocking(); mMockitoSession.finishMocking();
mKeyguardUpdateMonitor.removeCallback(mTestCallback); cleanupKeyguardUpdateMonitor();
mKeyguardUpdateMonitor.destroy();
} }
@Test @Test
@@ -351,6 +350,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test @Test
public void testSimStateInitialized() { public void testSimStateInitialized() {
cleanupKeyguardUpdateMonitor();
final int subId = 3; final int subId = 3;
final int state = TelephonyManager.SIM_STATE_ABSENT; final int state = TelephonyManager.SIM_STATE_ABSENT;
@@ -1205,7 +1205,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test @Test
public void testShouldListenForFace_whenFaceManagerNotAvailable_returnsFalse() { 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); mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
assertThat(mKeyguardUpdateMonitor.shouldListenForFace()).isFalse(); assertThat(mKeyguardUpdateMonitor.shouldListenForFace()).isFalse();
@@ -1258,6 +1260,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test @Test
public void testShouldListenForFace_whenUserIsNotPrimary_returnsFalse() throws RemoteException { public void testShouldListenForFace_whenUserIsNotPrimary_returnsFalse() throws RemoteException {
cleanupKeyguardUpdateMonitor();
// This disables face auth // This disables face auth
when(mUserManager.isPrimaryUser()).thenReturn(false); when(mUserManager.isPrimaryUser()).thenReturn(false);
mKeyguardUpdateMonitor = mKeyguardUpdateMonitor =
@@ -1587,9 +1590,9 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test @Test
public void testFingerAcquired_wakesUpPowerManager() { public void testFingerAcquired_wakesUpPowerManager() {
mContext.getOrCreateTestableResources().addOverride( cleanupKeyguardUpdateMonitor();
mSpiedContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.kg_wake_on_acquire_start, true); com.android.internal.R.bool.kg_wake_on_acquire_start, true);
mSpiedContext = spy(mContext);
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext); mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
fingerprintAcquireStart(); fingerprintAcquireStart();
@@ -1598,15 +1601,23 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
@Test @Test
public void testFingerAcquired_doesNotWakeUpPowerManager() { public void testFingerAcquired_doesNotWakeUpPowerManager() {
mContext.getOrCreateTestableResources().addOverride( cleanupKeyguardUpdateMonitor();
mSpiedContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.kg_wake_on_acquire_start, false); com.android.internal.R.bool.kg_wake_on_acquire_start, false);
mSpiedContext = spy(mContext);
mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext); mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(mSpiedContext);
fingerprintAcquireStart(); fingerprintAcquireStart();
verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString()); verify(mPowerManager, never()).wakeUp(anyLong(), anyInt(), anyString());
} }
private void cleanupKeyguardUpdateMonitor() {
if (mKeyguardUpdateMonitor != null) {
mKeyguardUpdateMonitor.removeCallback(mTestCallback);
mKeyguardUpdateMonitor.destroy();
mKeyguardUpdateMonitor = null;
}
}
private void faceAuthLockedOut() { private void faceAuthLockedOut() {
mKeyguardUpdateMonitor.mFaceAuthenticationCallback mKeyguardUpdateMonitor.mFaceAuthenticationCallback
.onAuthenticationError(FaceManager.FACE_ERROR_LOCKOUT_PERMANENT, ""); .onAuthenticationError(FaceManager.FACE_ERROR_LOCKOUT_PERMANENT, "");