From 29ef9fcca694f782f2182021665c322b5c5bed02 Mon Sep 17 00:00:00 2001 From: Chandru Date: Wed, 10 Aug 2022 13:59:15 +0000 Subject: [PATCH] Avoid IPCs to check for checking enrollment status of face and fp. This was introduced in the previous change that stops face auth on bouncer. This uses cached enrollment status for face and fp. Bug: 242022358 Bug: 241631135 Test: atest KeyguardUpdateMonitorTest Change-Id: Ic46266a89adc7a7548a164dee244ac5746ae8ffd --- .../android/keyguard/KeyguardUpdateMonitor.java | 9 ++++++--- .../keyguard/KeyguardUpdateMonitorTest.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 6bac7dc5fb944..6976e3e772deb 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -2580,8 +2580,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab } private boolean isOnlyFaceEnrolled() { - return isFaceAuthEnabledForUser(getCurrentUser()) - && !isUnlockWithFingerprintPossible(getCurrentUser()); + return isFaceEnrolled() + && !getCachedIsUnlockWithFingerprintPossible(sCurrentUser); } private void maybeLogListenerModelData(KeyguardListenModel model) { @@ -2696,7 +2696,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab return isUnlockWithFacePossible(userId) || isUnlockWithFingerprintPossible(userId); } - private boolean isUnlockWithFingerprintPossible(int userId) { + @VisibleForTesting + boolean isUnlockWithFingerprintPossible(int userId) { + // TODO (b/242022358), make this rely on onEnrollmentChanged event and update it only once. mIsUnlockWithFingerprintPossible.put(userId, mFpm != null && mFpm.isHardwareDetected() && !isFingerprintDisabled(userId) && mFpm.hasEnrolledTemplates(userId)); return mIsUnlockWithFingerprintPossible.get(userId); @@ -2718,6 +2720,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab * If face hardware is available, user has enrolled and enabled auth via setting. */ public boolean isFaceAuthEnabledForUser(int userId) { + // TODO (b/242022358), make this rely on onEnrollmentChanged event and update it only once. updateFaceEnrolled(userId); return mIsFaceEnrolled; } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index c67737136b3b2..c281965550e4b 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -581,6 +581,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { @Test public void testTriesToAuthenticate_whenBouncer() { fingerprintIsNotEnrolled(); + faceAuthEnabled(); setKeyguardBouncerVisibility(true); verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt(), anyBoolean()); @@ -1218,6 +1219,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { public void testShouldListenForFace_whenFaceIsAlreadyAuthenticated_returnsFalse() throws RemoteException { // Face auth should run when the following is true. + faceAuthEnabled(); bouncerFullyVisibleAndNotGoingToSleep(); fingerprintIsNotEnrolled(); keyguardNotGoingAway(); @@ -1284,6 +1286,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { public void testShouldListenForFace_whenBiometricsDisabledForUser_returnsFalse() throws RemoteException { // Preconditions for face auth to run + faceAuthEnabled(); keyguardNotGoingAway(); bouncerFullyVisibleAndNotGoingToSleep(); fingerprintIsNotEnrolled(); @@ -1307,6 +1310,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { public void testShouldListenForFace_whenUserCurrentlySwitching_returnsFalse() throws RemoteException { // Preconditions for face auth to run + faceAuthEnabled(); keyguardNotGoingAway(); bouncerFullyVisibleAndNotGoingToSleep(); fingerprintIsNotEnrolled(); @@ -1329,6 +1333,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { public void testShouldListenForFace_whenSecureCameraLaunched_returnsFalse() throws RemoteException { // Preconditions for face auth to run + faceAuthEnabled(); keyguardNotGoingAway(); bouncerFullyVisibleAndNotGoingToSleep(); fingerprintIsNotEnrolled(); @@ -1374,6 +1379,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { public void testShouldListenForFace_whenBouncerShowingAndDeviceIsAwake_returnsTrue() throws RemoteException { // Preconditions for face auth to run + faceAuthEnabled(); keyguardNotGoingAway(); currentUserIsPrimary(); currentUserDoesNotHaveTrust(); @@ -1539,8 +1545,19 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { assertThat(mKeyguardUpdateMonitor.shouldListenForFingerprint(anyBoolean())).isEqualTo(true); } + private void faceAuthEnabled() { + // this ensures KeyguardUpdateMonitor updates the cached mIsFaceEnrolled flag using the + // face manager mock wire-up in setup() + mKeyguardUpdateMonitor.isFaceAuthEnabledForUser(mCurrentUserId); + } + private void fingerprintIsNotEnrolled() { when(mFingerprintManager.hasEnrolledTemplates(mCurrentUserId)).thenReturn(false); + // This updates the cached fingerprint state. + // There is no straightforward API to update the fingerprint state. + // It currently works updates after enrollment changes because something else invokes + // startListeningForFingerprint(), which internally calls this method. + mKeyguardUpdateMonitor.isUnlockWithFingerprintPossible(mCurrentUserId); } private void statusBarShadeIsNotLocked() {