From 2e482ce2349379e1d2160a8dae0f26256ecebb37 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Wed, 9 Nov 2022 12:15:36 -0800 Subject: [PATCH] [Bouncer] Set message for dismiss api. Message being set to error message from viewmediator callback and prompt reason from view mediator callback are overridden from the setText that is called in #appear. Only set message when text is empty. Additionally, for the modern bouncer, the prompt reason was not updating properly. This is because the old bouncer has a prepare method that udpates the prompt reason. Test: patched in http://ag/20257883 and did dock setup. Observe with MODERN_BOUNCER flag on and off. Both update the message. Test: Add fingerprint auth and restart device to activate REQUIRES_HARD_ATUH. Observe with MODERN_BOUNCER flag on and off. Both prompt to unlock the device before using auth. Fixes 254841665 Change-Id: I8db831bfec4f6ac28f07049669469fdbb896de06 --- .../keyguard/KeyguardInputViewController.java | 5 +++- .../KeyguardMessageAreaController.java | 5 ++++ .../repository/KeyguardBouncerRepository.kt | 24 ++----------------- .../ui/binder/KeyguardBouncerViewBinder.kt | 16 ++++--------- .../ui/viewmodel/KeyguardBouncerViewModel.kt | 8 ------- .../KeyguardMessageAreaControllerTest.java | 10 ++++++++ .../KeyguardPasswordViewControllerTest.kt | 11 +++++++++ .../KeyguardPatternViewControllerTest.kt | 11 +++++++++ .../keyguard/KeyguardPinViewControllerTest.kt | 8 +++++++ 9 files changed, 55 insertions(+), 43 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java index 73229c3210797..faaba63938bf6 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardInputViewController.java @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.content.res.ColorStateList; import android.content.res.Resources; import android.telephony.TelephonyManager; +import android.text.TextUtils; import android.util.Log; import android.view.inputmethod.InputMethodManager; @@ -152,7 +153,9 @@ public abstract class KeyguardInputViewController } public void startAppearAnimation() { - mMessageAreaController.setMessage(getInitialMessageResId()); + if (TextUtils.isEmpty(mMessageAreaController.getMessage())) { + mMessageAreaController.setMessage(getInitialMessageResId()); + } mView.startAppearAnimation(); } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java index 2bd3ca59b7408..db986e0a631ae 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardMessageAreaController.java @@ -103,6 +103,11 @@ public class KeyguardMessageAreaController mView.setNextMessageColor(colorState); } + /** Returns the message of the underlying TextView. */ + public CharSequence getMessage() { + return mView.getText(); + } + /** * Reload colors from resources. **/ 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 d4514c5cb7aac..783f752cbd205 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 @@ -16,9 +16,7 @@ package com.android.systemui.keyguard.data.repository -import android.hardware.biometrics.BiometricSourceType import com.android.keyguard.KeyguardUpdateMonitor -import com.android.keyguard.KeyguardUpdateMonitorCallback import com.android.keyguard.ViewMediatorCallback import com.android.systemui.dagger.SysUISingleton import com.android.systemui.keyguard.shared.model.BouncerShowMessageModel @@ -70,33 +68,15 @@ constructor( private val _keyguardAuthenticated = MutableStateFlow(null) /** Determines if user is already unlocked */ val keyguardAuthenticated = _keyguardAuthenticated.asStateFlow() - - var bouncerPromptReason: Int? = null private val _showMessage = MutableStateFlow(null) val showMessage = _showMessage.asStateFlow() private val _resourceUpdateRequests = MutableStateFlow(false) val resourceUpdateRequests = _resourceUpdateRequests.asStateFlow() - + val bouncerPromptReason: Int + get() = viewMediatorCallback.bouncerPromptReason val bouncerErrorMessage: CharSequence? get() = viewMediatorCallback.consumeCustomMessage() - init { - val callback = - object : KeyguardUpdateMonitorCallback() { - override fun onStrongAuthStateChanged(userId: Int) { - bouncerPromptReason = viewMediatorCallback.bouncerPromptReason - } - - override fun onLockedOutStateChanged(type: BiometricSourceType) { - if (type == BiometricSourceType.FINGERPRINT) { - bouncerPromptReason = viewMediatorCallback.bouncerPromptReason - } - } - } - - keyguardUpdateMonitor.registerCallback(callback) - } - fun setPrimaryScrimmed(isScrimmed: Boolean) { _primaryBouncerScrimmed.value = isScrimmed } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBouncerViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBouncerViewBinder.kt index a22958b74bb94..7739a456fcb7a 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBouncerViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBouncerViewBinder.kt @@ -94,6 +94,10 @@ object KeyguardBouncerViewBinder { viewModel.setBouncerViewDelegate(delegate) launch { viewModel.show.collect { + hostViewController.showPromptReason(it.promptReason) + it.errorMessage?.let { errorMessage -> + hostViewController.showErrorMessage(errorMessage) + } hostViewController.showPrimarySecurityScreen() hostViewController.appear( SystemBarUtils.getStatusBarHeight(view.context) @@ -101,18 +105,6 @@ object KeyguardBouncerViewBinder { } } - launch { - viewModel.showPromptReason.collect { prompt -> - hostViewController.showPromptReason(prompt) - } - } - - launch { - viewModel.showBouncerErrorMessage.collect { errorMessage -> - hostViewController.showErrorMessage(errorMessage) - } - } - launch { viewModel.showWithFullExpansion.collect { model -> hostViewController.resetSecurityContainer() diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBouncerViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBouncerViewModel.kt index 07816001f45cf..526ae741793c4 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBouncerViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBouncerViewModel.kt @@ -26,7 +26,6 @@ import com.android.systemui.statusbar.phone.KeyguardBouncer.EXPANSION_VISIBLE import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filter -import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map /** Models UI state for the lock screen bouncer; handles user input. */ @@ -45,13 +44,6 @@ constructor( /** Observe whether bouncer is showing. */ val show: Flow = interactor.show - /** Observe bouncer prompt when bouncer is showing. */ - val showPromptReason: Flow = interactor.show.map { it.promptReason } - - /** Observe bouncer error message when bouncer is showing. */ - val showBouncerErrorMessage: Flow = - interactor.show.map { it.errorMessage }.filterNotNull() - /** Observe visible expansion when bouncer is showing. */ val showWithFullExpansion: Flow = interactor.show.filter { it.expansionAmount == EXPANSION_VISIBLE } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaControllerTest.java index 5d2b0ca4e7eaf..829008403e02a 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardMessageAreaControllerTest.java @@ -16,8 +16,11 @@ package com.android.keyguard; +import static com.google.common.truth.Truth.assertThat; + import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; @@ -90,4 +93,11 @@ public class KeyguardMessageAreaControllerTest extends SysuiTestCase { mMessageAreaController.setIsVisible(true); verify(mKeyguardMessageArea).setIsVisible(true); } + + @Test + public void testGetMessage() { + String msg = "abc"; + when(mKeyguardMessageArea.getText()).thenReturn(msg); + assertThat(mMessageAreaController.getMessage()).isEqualTo(msg); + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt index b369098cafc03..ffd95f4041f96 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPasswordViewControllerTest.kt @@ -31,6 +31,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito +import org.mockito.Mockito.`when` import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @@ -118,4 +119,14 @@ class KeyguardPasswordViewControllerTest : SysuiTestCase() { keyguardPasswordViewController.startAppearAnimation() verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_password) } + + @Test + fun startAppearAnimation_withExistingMessage() { + `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.") + keyguardPasswordViewController.startAppearAnimation() + verify( + mKeyguardMessageAreaController, + never() + ).setMessage(R.string.keyguard_enter_your_password) + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt index 9eff70487c74e..b3d1c8f909d8b 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPatternViewControllerTest.kt @@ -33,6 +33,7 @@ import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.verify import org.mockito.Mockito.`when` +import org.mockito.Mockito.never import org.mockito.MockitoAnnotations @SmallTest @@ -112,4 +113,14 @@ class KeyguardPatternViewControllerTest : SysuiTestCase() { mKeyguardPatternViewController.startAppearAnimation() verify(mKeyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pattern) } + + @Test + fun startAppearAnimation_withExistingMessage() { + `when`(mKeyguardMessageAreaController.message).thenReturn("Unlock to continue.") + mKeyguardPatternViewController.startAppearAnimation() + verify( + mKeyguardMessageAreaController, + never() + ).setMessage(R.string.keyguard_enter_your_password) + } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt index d9efdeaea04c9..8bcfe6f2b6f51 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardPinViewControllerTest.kt @@ -100,4 +100,12 @@ class KeyguardPinViewControllerTest : SysuiTestCase() { pinViewController.startAppearAnimation() verify(keyguardMessageAreaController).setMessage(R.string.keyguard_enter_your_pin) } + + @Test + fun startAppearAnimation_withExistingMessage() { + Mockito.`when`(keyguardMessageAreaController.message).thenReturn("Unlock to continue.") + pinViewController.startAppearAnimation() + verify(keyguardMessageAreaController, Mockito.never()) + .setMessage(R.string.keyguard_enter_your_password) + } }