summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Beverly <beverlyt@google.com> 2024-06-20 19:33:21 +0000
committer Beverly Tai <beverlyt@google.com> 2024-06-21 10:54:03 +0000
commit1900fabcd25063c87a8205960fcff321a92ff4bc (patch)
tree11586d4b40126518381078a06af9ee2c8e150666
parentf8a9bb954489dc2c220e0a6d47cae4c10b9c3d7c (diff)
Send initial isFingerprintEnrolled when userChanges
So the state isn't stale on user switches. Bug: 342970807 Flag: EXEMPT bugfix Test: atest BiometricSettingsRepositoryTest Test: - Enroll UDFPS on primary and secondary users. - On the secondary user, set security to NONE. - Switch to primary user. - Observe alternate bouncer will appears when tapping on a notification or longpressing QS tiles Change-Id: I4f39debc5376ee8592c9a1ce3aa902d2dd702c40
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt24
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt50
2 files changed, 48 insertions, 26 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt
index 4587ea6dbdc8..c5ba02d0773a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepositoryTest.kt
@@ -528,6 +528,30 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
}
@Test
+ fun userChange_isFingerprintEnrolledAndEnabledUpdated() =
+ testScope.runTest {
+ createBiometricSettingsRepository()
+ whenever(authController.isFingerprintEnrolled(ANOTHER_USER_ID)).thenReturn(false)
+ whenever(authController.isFingerprintEnrolled(PRIMARY_USER_ID)).thenReturn(true)
+
+ verify(biometricManager)
+ .registerEnabledOnKeyguardCallback(biometricManagerCallback.capture())
+ val isFingerprintEnrolledAndEnabled =
+ collectLastValue(underTest.isFingerprintEnrolledAndEnabled)
+ biometricManagerCallback.value.onChanged(true, ANOTHER_USER_ID)
+ runCurrent()
+ userRepository.setSelectedUserInfo(ANOTHER_USER)
+ runCurrent()
+ assertThat(isFingerprintEnrolledAndEnabled()).isFalse()
+
+ biometricManagerCallback.value.onChanged(true, PRIMARY_USER_ID)
+ runCurrent()
+ userRepository.setSelectedUserInfo(PRIMARY_USER)
+ runCurrent()
+ assertThat(isFingerprintEnrolledAndEnabled()).isTrue()
+ }
+
+ @Test
fun userChange_biometricEnabledChange_handlesRaceCondition() =
testScope.runTest {
createBiometricSettingsRepository()
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt
index 882f2315f6e8..dd3e6190ceaf 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/BiometricSettingsRepository.kt
@@ -188,35 +188,33 @@ constructor(
)
private val isFingerprintEnrolled: Flow<Boolean> =
- selectedUserId
- .flatMapLatest { currentUserId ->
- conflatedCallbackFlow {
- val callback =
- object : AuthController.Callback {
- override fun onEnrollmentsChanged(
- sensorBiometricType: BiometricType,
- userId: Int,
- hasEnrollments: Boolean
- ) {
- if (sensorBiometricType.isFingerprint && userId == currentUserId) {
- trySendWithFailureLogging(
- hasEnrollments,
- TAG,
- "update fpEnrollment"
- )
- }
+ selectedUserId.flatMapLatest { currentUserId ->
+ conflatedCallbackFlow {
+ val callback =
+ object : AuthController.Callback {
+ override fun onEnrollmentsChanged(
+ sensorBiometricType: BiometricType,
+ userId: Int,
+ hasEnrollments: Boolean
+ ) {
+ if (sensorBiometricType.isFingerprint && userId == currentUserId) {
+ trySendWithFailureLogging(
+ hasEnrollments,
+ TAG,
+ "update fpEnrollment"
+ )
}
}
- authController.addCallback(callback)
- awaitClose { authController.removeCallback(callback) }
- }
+ }
+ authController.addCallback(callback)
+ trySendWithFailureLogging(
+ authController.isFingerprintEnrolled(currentUserId),
+ TAG,
+ "Initial value of fingerprint enrollment"
+ )
+ awaitClose { authController.removeCallback(callback) }
}
- .stateIn(
- scope,
- started = SharingStarted.Eagerly,
- initialValue =
- authController.isFingerprintEnrolled(userRepository.getSelectedUserInfo().id)
- )
+ }
private val isFaceEnrolled: Flow<Boolean> =
selectedUserId.flatMapLatest { selectedUserId: Int ->