From 320701e45810d2887f45881bb6cf8a92589976ca Mon Sep 17 00:00:00 2001 From: Chandru S Date: Tue, 18 Jul 2023 15:52:52 -0700 Subject: [PATCH] Resolve face detection related issues 1. Add createdAt so that repeated updates are still propagated 2. Do not use detection cancellation signal to skip running detection. Unlike face auth, detection doesn't have a callback to indicate when detection is done cancelling. 3. Change KeyguardUpdateMonitor to run the same code it is running for the old face auth system Fixes: 285526875 Test: atest DeviceEntryFaceAuthRepositoryTest Test: manually 1. Enable Extend Unlock/Smart Unlock and add the current location as trusted location 2. Enroll face and fp, enable bypass lockscreen under face. 3. Go to sleep by pressing the power button 4. Wake up the device and go to the lockscreen. 5. Device should be unlocked based on current location and show the unlocked icon 6. Tap on the lockscreen while keeping the face in front of the screen 7. Face detection should run and dismiss the lockscreen. Change-Id: Ia4b541e0ec5c6e6f876f4a21e788691e96e38870 --- .../android/keyguard/KeyguardUpdateMonitor.java | 2 +- .../repository/DeviceEntryFaceAuthRepository.kt | 4 ++-- .../shared/model/FaceAuthenticationModels.kt | 15 +++++++++++---- .../DeviceEntryFaceAuthRepositoryTest.kt | 5 ++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 84f1da01c5c1d..f5022ab64add1 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1496,7 +1496,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab @Override public void onDetectionStatusChanged(@NonNull FaceDetectionStatus status) { - handleFaceAuthenticated(status.getUserId(), status.isStrongBiometric()); + handleBiometricDetected(status.getUserId(), FACE, status.isStrongBiometric()); } }; diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt index b6a296aec3617..d1f011ea4f9b3 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt @@ -545,11 +545,11 @@ constructor( faceAuthLogger.detectionNotSupported(faceManager, faceManager?.sensorPropertiesInternal) return } - if (_isAuthRunning.value || detectCancellationSignal != null) { + if (_isAuthRunning.value) { faceAuthLogger.skippingDetection(_isAuthRunning.value, detectCancellationSignal != null) return } - + detectCancellationSignal?.cancel() detectCancellationSignal = CancellationSignal() withContext(mainDispatcher) { // We always want to invoke face detect in the main thread. diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/FaceAuthenticationModels.kt b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/FaceAuthenticationModels.kt index dcd6ac4919c42..d9792cf704c8a 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/FaceAuthenticationModels.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/shared/model/FaceAuthenticationModels.kt @@ -23,7 +23,10 @@ import android.os.SystemClock.elapsedRealtime * Authentication status provided by * [com.android.systemui.keyguard.data.repository.DeviceEntryFaceAuthRepository] */ -sealed class FaceAuthenticationStatus +sealed class FaceAuthenticationStatus( + // present to break equality check if the same error occurs repeatedly. + val createdAt: Long = elapsedRealtime() +) /** Success authentication status. */ data class SuccessFaceAuthenticationStatus(val successResult: FaceManager.AuthenticationResult) : @@ -43,8 +46,6 @@ object FailedFaceAuthenticationStatus : FaceAuthenticationStatus() data class ErrorFaceAuthenticationStatus( val msgId: Int, val msg: String? = null, - // present to break equality check if the same error occurs repeatedly. - val createdAt: Long = elapsedRealtime() ) : FaceAuthenticationStatus() { /** * Method that checks if [msgId] is a lockout error. A lockout error means that face @@ -74,4 +75,10 @@ data class ErrorFaceAuthenticationStatus( } /** Face detection success message. */ -data class FaceDetectionStatus(val sensorId: Int, val userId: Int, val isStrongBiometric: Boolean) +data class FaceDetectionStatus( + val sensorId: Int, + val userId: Int, + val isStrongBiometric: Boolean, + // present to break equality check if the same error occurs repeatedly. + val createdAt: Long = elapsedRealtime() +) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt index a09f7b9e787e6..8127ac6257480 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt @@ -386,7 +386,10 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { detectionCallback.value.onFaceDetected(1, 1, true) - assertThat(detectStatus()).isEqualTo(FaceDetectionStatus(1, 1, true)) + val status = detectStatus()!! + assertThat(status.sensorId).isEqualTo(1) + assertThat(status.userId).isEqualTo(1) + assertThat(status.isStrongBiometric).isEqualTo(true) } @Test