From e2f011c87d9249069f3e32eb188dae8effbe330e Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Tue, 8 Nov 2022 12:04:56 -0800 Subject: [PATCH] [Bouncer] Change message to shared flow. Change to a shared flow so that the flow is not conflated. This will allow the flow to emit values that are the same as the previous value. Test: Add face unlock with someone not my face. Fail and disable face unlock on bouncer. Fixes: 258160993 Change-Id: Ibc68a23243a5ea88460199de1ea3ee876d658ea1 --- .../data/repository/KeyguardBouncerRepository.kt | 13 ++++++++++--- .../domain/interactor/PrimaryBouncerInteractor.kt | 1 - .../interactor/PrimaryBouncerInteractorTest.kt | 1 - 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt index 783f752cbd205..9a90fe7e60bd0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBouncerRepository.kt @@ -23,7 +23,10 @@ import com.android.systemui.keyguard.shared.model.BouncerShowMessageModel import com.android.systemui.keyguard.shared.model.KeyguardBouncerModel import com.android.systemui.statusbar.phone.KeyguardBouncer import javax.inject.Inject +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow /** Encapsulates app state for the lock screen primary and alternate bouncer. */ @@ -68,8 +71,12 @@ constructor( private val _keyguardAuthenticated = MutableStateFlow(null) /** Determines if user is already unlocked */ val keyguardAuthenticated = _keyguardAuthenticated.asStateFlow() - private val _showMessage = MutableStateFlow(null) - val showMessage = _showMessage.asStateFlow() + private val _showMessage = + MutableSharedFlow( + replay = 1, + onBufferOverflow = BufferOverflow.DROP_OLDEST + ) + val showMessage = _showMessage.asSharedFlow() private val _resourceUpdateRequests = MutableStateFlow(false) val resourceUpdateRequests = _resourceUpdateRequests.asStateFlow() val bouncerPromptReason: Int @@ -118,7 +125,7 @@ constructor( } fun setShowMessage(bouncerShowMessageModel: BouncerShowMessageModel?) { - _showMessage.value = bouncerShowMessageModel + _showMessage.tryEmit(bouncerShowMessageModel) } fun setKeyguardAuthenticated(keyguardAuthenticated: Boolean?) { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractor.kt index c22f4e7a26343..9b5def3a3c945 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractor.kt @@ -117,7 +117,6 @@ constructor( @JvmOverloads fun show(isScrimmed: Boolean) { // Reset some states as we show the bouncer. - repository.setShowMessage(null) repository.setOnScreenTurnedOff(false) repository.setKeyguardAuthenticated(null) repository.setPrimaryHide(false) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractorTest.kt index c85f7b9e6885c..30c72dde29f94 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/PrimaryBouncerInteractorTest.kt @@ -93,7 +93,6 @@ class PrimaryBouncerInteractorTest : SysuiTestCase() { @Test fun testShow_isScrimmed() { mPrimaryBouncerInteractor.show(true) - verify(repository).setShowMessage(null) verify(repository).setOnScreenTurnedOff(false) verify(repository).setKeyguardAuthenticated(null) verify(repository).setPrimaryHide(false)