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

Commit b81ff578 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Add a buffer to fingerprintAuthenticationStatuses" into main

parents cfe5d3b5 8a818d65
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticati
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runCurrent
@@ -214,6 +215,39 @@ class DeviceEntryFingerprintAuthRepositoryTest : SysuiTestCase() {
                .isInstanceOf(FailFingerprintAuthenticationStatus::class.java)
        }

    @Test
    fun onFingerprintFailed_failedAuthenticationStatusWithOtherStatuses() =
        testScope.runTest {
            val failStatus by
                collectLastValue(
                    underTest.authenticationStatus.filterIsInstance<
                        FailFingerprintAuthenticationStatus
                    >()
                )
            runCurrent()

            verify(keyguardUpdateMonitor).registerCallback(updateMonitorCallback.capture())
            updateMonitorCallback.value.onBiometricAcquired(
                BiometricSourceType.FINGERPRINT,
                /* acquireInfo */ 0,
            )
            updateMonitorCallback.value.onBiometricAuthFailed(
                BiometricSourceType.FINGERPRINT,
            )
            updateMonitorCallback.value.onBiometricHelp(
                /* msgId */ 7,
                /* errString */ "Not recognized.",
                BiometricSourceType.FINGERPRINT,
            )
            updateMonitorCallback.value.onBiometricError(
                /* msgId */ 7,
                /* errString */ "Too many attempts.",
                BiometricSourceType.FINGERPRINT,
            )

            assertThat(failStatus).isNotNull()
        }

    @Test
    fun onFingerprintError_errorAuthenticationStatus() =
        testScope.runTest {
+86 −78
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.shareIn
@@ -177,8 +178,14 @@ constructor(

    // TODO(b/322555228) Remove after consolidating device entry auth messages with BP auth messages
    //  in BiometricStatusRepository
    /**
     * FingerprintAuthenticationStatus Multiple statuses may arrive in immediate sequence (ie:
     * acquired, failed, help, error), so we use a buffer to ensure consumers receive each distinct
     * status.
     */
    override val authenticationStatus: Flow<FingerprintAuthenticationStatus>
        get() = conflatedCallbackFlow {
        get() =
            conflatedCallbackFlow {
                    val callback =
                        object : KeyguardUpdateMonitorCallback() {
                            override fun onBiometricAuthenticated(
@@ -263,6 +270,7 @@ constructor(
                    keyguardUpdateMonitor.registerCallback(callback)
                    awaitClose { keyguardUpdateMonitor.removeCallback(callback) }
                }
                .buffer(capacity = 4)

    override val shouldUpdateIndicatorVisibility: Flow<Boolean> =
        conflatedCallbackFlow {