Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46f11389 authored by Beverly's avatar Beverly Committed by Android Build Coastguard Worker
Browse files

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
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:1900fabcd25063c87a8205960fcff321a92ff4bc)
Merged-In: I4f39debc5376ee8592c9a1ce3aa902d2dd702c40
Change-Id: I4f39debc5376ee8592c9a1ce3aa902d2dd702c40
parent 19108729
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -527,6 +527,30 @@ class BiometricSettingsRepositoryTest : SysuiTestCase() {
        whenever(authController.isFaceAuthEnrolled(userId)).thenReturn(true)
    }

    @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 {
+24 −26
Original line number Diff line number Diff line
@@ -188,8 +188,7 @@ constructor(
        )

    private val isFingerprintEnrolled: Flow<Boolean> =
        selectedUserId
            .flatMapLatest { currentUserId ->
        selectedUserId.flatMapLatest { currentUserId ->
            conflatedCallbackFlow {
                val callback =
                    object : AuthController.Callback {
@@ -208,15 +207,14 @@ constructor(
                        }
                    }
                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 ->