diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/BiometricStatusRepository.kt b/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/BiometricStatusRepository.kt index ca03a00cca0c..da270c08f281 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/BiometricStatusRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/data/repository/BiometricStatusRepository.kt @@ -39,7 +39,6 @@ import com.android.systemui.biometrics.shared.model.AuthenticationReason import com.android.systemui.biometrics.shared.model.AuthenticationReason.SettingsOperations import com.android.systemui.biometrics.shared.model.AuthenticationState import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging -import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.keyguard.shared.model.AcquiredFingerprintAuthenticationStatus @@ -49,6 +48,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance @@ -85,7 +85,7 @@ constructor( * onAcquired in [FingerprintManager.EnrollmentCallback] and [FaceManager.EnrollmentCallback] */ private val authenticationState: Flow = - conflatedCallbackFlow { + callbackFlow { val updateAuthenticationState = { state: AuthenticationState -> Log.d(TAG, "authenticationState updated: $state") trySendWithFailureLogging(state, TAG, "Error sending AuthenticationState state") @@ -169,7 +169,9 @@ constructor( } } - updateAuthenticationState(AuthenticationState.Idle(AuthenticationReason.NotRunning)) + updateAuthenticationState( + AuthenticationState.Idle(requestReason = AuthenticationReason.NotRunning) + ) biometricManager?.registerAuthenticationStateListener(authenticationStateListener) awaitClose { biometricManager?.unregisterAuthenticationStateListener( @@ -180,23 +182,32 @@ constructor( .distinctUntilChanged() .shareIn(applicationScope, started = SharingStarted.Eagerly, replay = 1) - override val fingerprintAuthenticationReason: Flow = + private val fingerprintAuthenticationState: Flow = authenticationState .filter { - it is AuthenticationState.Idle || - (it is AuthenticationState.Started && - it.biometricSourceType == BiometricSourceType.FINGERPRINT) || - (it is AuthenticationState.Stopped && - it.biometricSourceType == BiometricSourceType.FINGERPRINT) + it.biometricSourceType == null || + it.biometricSourceType == BiometricSourceType.FINGERPRINT } + .onEach { Log.d(TAG, "fingerprintAuthenticationState updated: $it") } + + private val fingerprintRunningState: Flow = + fingerprintAuthenticationState + .filter { + it is AuthenticationState.Idle || + it is AuthenticationState.Started || + it is AuthenticationState.Stopped + } + .onEach { Log.d(TAG, "fingerprintRunningState updated: $it") } + + override val fingerprintAuthenticationReason: Flow = + fingerprintRunningState .map { it.requestReason } .onEach { Log.d(TAG, "fingerprintAuthenticationReason updated: $it") } override val fingerprintAcquiredStatus: Flow = - authenticationState - .filterIsInstance() - .filter { it.biometricSourceType == BiometricSourceType.FINGERPRINT } - .map { AcquiredFingerprintAuthenticationStatus(it.requestReason, it.acquiredInfo) } + fingerprintAuthenticationState.filterIsInstance().map { + AcquiredFingerprintAuthenticationStatus(it.requestReason, it.acquiredInfo) + } companion object { private const val TAG = "BiometricStatusRepositoryImpl" diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/shared/model/AuthenticationState.kt b/packages/SystemUI/src/com/android/systemui/biometrics/shared/model/AuthenticationState.kt index 5ceae36dadb6..81ea6a9c15b0 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/shared/model/AuthenticationState.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/shared/model/AuthenticationState.kt @@ -27,6 +27,9 @@ import android.hardware.biometrics.BiometricSourceType * authentication. */ sealed interface AuthenticationState { + /** Indicates [BiometricSourceType] of authentication state update, null in idle auth state. */ + val biometricSourceType: BiometricSourceType? + /** * Indicates [AuthenticationReason] from [BiometricRequestConstants.RequestReason] for * requesting auth @@ -43,7 +46,7 @@ sealed interface AuthenticationState { * message. */ data class Acquired( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, override val requestReason: AuthenticationReason, val acquiredInfo: Int ) : AuthenticationState @@ -59,7 +62,7 @@ sealed interface AuthenticationState { * @param requestReason reason from [BiometricRequestConstants.RequestReason] for authentication */ data class Error( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, val errString: String?, val errCode: Int, override val requestReason: AuthenticationReason, @@ -73,7 +76,7 @@ sealed interface AuthenticationState { * @param userId The user id for the requested authentication */ data class Failed( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, override val requestReason: AuthenticationReason, val userId: Int ) : AuthenticationState @@ -87,7 +90,7 @@ sealed interface AuthenticationState { * @param requestReason reason from [BiometricRequestConstants.RequestReason] for authentication */ data class Help( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, val helpString: String?, val helpCode: Int, override val requestReason: AuthenticationReason, @@ -96,9 +99,13 @@ sealed interface AuthenticationState { /** * Authentication state when no auth is running * + * @param biometricSourceType null * @param requestReason [AuthenticationReason.NotRunning] */ - data class Idle(override val requestReason: AuthenticationReason) : AuthenticationState + data class Idle( + override val biometricSourceType: BiometricSourceType? = null, + override val requestReason: AuthenticationReason + ) : AuthenticationState /** * AuthenticationState when auth is started @@ -107,7 +114,7 @@ sealed interface AuthenticationState { * @param requestReason reason from [BiometricRequestConstants.RequestReason] for authentication */ data class Started( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, override val requestReason: AuthenticationReason ) : AuthenticationState @@ -118,7 +125,7 @@ sealed interface AuthenticationState { * @param requestReason [AuthenticationReason.NotRunning] */ data class Stopped( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, override val requestReason: AuthenticationReason ) : AuthenticationState @@ -131,7 +138,7 @@ sealed interface AuthenticationState { * @param userId The user id for the requested authentication */ data class Succeeded( - val biometricSourceType: BiometricSourceType, + override val biometricSourceType: BiometricSourceType, val isStrongBiometric: Boolean, override val requestReason: AuthenticationReason, val userId: Int