summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModel.kt9
-rw-r--r--packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModel.kt17
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt35
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt36
4 files changed, 84 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModel.kt b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModel.kt
index 80a41ce672ec..d21479746744 100644
--- a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModel.kt
@@ -40,20 +40,21 @@ class PasswordBouncerViewModel(
/** Notifies that the UI has been shown to the user. */
fun onShown() {
+ _password.value = ""
interactor.resetMessage()
}
/** Notifies that the user has changed the password input. */
- fun onPasswordInputChanged(password: String) {
- if (this.password.value.isEmpty() && password.isNotEmpty()) {
+ fun onPasswordInputChanged(newPassword: String) {
+ if (this.password.value.isEmpty() && newPassword.isNotEmpty()) {
interactor.clearMessage()
}
- if (password.isNotEmpty()) {
+ if (newPassword.isNotEmpty()) {
interactor.onIntentionalUserInput()
}
- _password.value = password
+ _password.value = newPassword
}
/** Notifies that the user has pressed the key for attempting to authenticate the password. */
diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModel.kt b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModel.kt
index ebf939b264fa..dc5c5288df9f 100644
--- a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModel.kt
@@ -70,13 +70,7 @@ class PinBouncerViewModel(
/** Appearance of the confirm button. */
val confirmButtonAppearance: StateFlow<ActionButtonAppearance> =
interactor.isAutoConfirmEnabled
- .map {
- if (it) {
- ActionButtonAppearance.Hidden
- } else {
- ActionButtonAppearance.Shown
- }
- }
+ .map { if (it) ActionButtonAppearance.Hidden else ActionButtonAppearance.Shown }
.stateIn(
scope = applicationScope,
started = SharingStarted.Eagerly,
@@ -85,6 +79,7 @@ class PinBouncerViewModel(
/** Notifies that the UI has been shown to the user. */
fun onShown() {
+ clearPinInput()
interactor.resetMessage()
}
@@ -113,7 +108,7 @@ class PinBouncerViewModel(
/** Notifies that the user long-pressed the backspace button. */
fun onBackspaceButtonLongPressed() {
- mutablePinInput.value = mutablePinInput.value.clearAll()
+ clearPinInput()
}
/** Notifies that the user clicked the "enter" button. */
@@ -121,6 +116,10 @@ class PinBouncerViewModel(
tryAuthenticate(useAutoConfirm = false)
}
+ private fun clearPinInput() {
+ mutablePinInput.value = mutablePinInput.value.clearAll()
+ }
+
private fun tryAuthenticate(useAutoConfirm: Boolean) {
val pinCode = mutablePinInput.value.getPin()
@@ -133,7 +132,7 @@ class PinBouncerViewModel(
// TODO(b/291528545): this should not be cleared on success (at least until the view
// is animated away).
- mutablePinInput.value = mutablePinInput.value.clearAll()
+ clearPinInput()
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt
index 4380af80efbd..12090e5264df 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PasswordBouncerViewModelTest.kt
@@ -185,6 +185,41 @@ class PasswordBouncerViewModelTest : SysuiTestCase() {
assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Gone))
}
+ @Test
+ fun onShown_againAfterSceneChange_resetsPassword() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.desiredScene)
+ val password by collectLastValue(underTest.password)
+ utils.authenticationRepository.setAuthenticationMethod(
+ AuthenticationMethodModel.Password
+ )
+ utils.authenticationRepository.setUnlocked(false)
+ sceneInteractor.changeScene(SceneModel(SceneKey.Bouncer), "reason")
+ sceneInteractor.onSceneChanged(SceneModel(SceneKey.Bouncer), "reason")
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+ underTest.onShown()
+
+ // The user types a password.
+ underTest.onPasswordInputChanged("password")
+ assertThat(password).isEqualTo("password")
+
+ // The user doesn't confirm the password, but navigates back to the lockscreen instead.
+ sceneInteractor.changeScene(SceneModel(SceneKey.Lockscreen), "reason")
+ sceneInteractor.onSceneChanged(SceneModel(SceneKey.Lockscreen), "reason")
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Lockscreen))
+
+ // The user navigates to the bouncer again.
+ sceneInteractor.changeScene(SceneModel(SceneKey.Bouncer), "reason")
+ sceneInteractor.onSceneChanged(SceneModel(SceneKey.Bouncer), "reason")
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+
+ underTest.onShown()
+
+ // Ensure the previously-entered password is not shown.
+ assertThat(password).isEmpty()
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+ }
+
companion object {
private const val ENTER_YOUR_PASSWORD = "Enter your password"
private const val WRONG_PASSWORD = "Wrong password"
diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt
index 531f86abdfbc..a684221e1a78 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/ui/viewmodel/PinBouncerViewModelTest.kt
@@ -314,6 +314,42 @@ class PinBouncerViewModelTest : SysuiTestCase() {
}
@Test
+ fun onShown_againAfterSceneChange_resetsPin() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.desiredScene)
+ val pin by collectLastValue(underTest.pinInput.map { it.getPin() })
+ utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin)
+ utils.authenticationRepository.setUnlocked(false)
+ sceneInteractor.changeScene(SceneModel(SceneKey.Bouncer), "reason")
+ sceneInteractor.onSceneChanged(SceneModel(SceneKey.Bouncer), "reason")
+
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+ underTest.onShown()
+
+ // The user types a PIN.
+ FakeAuthenticationRepository.DEFAULT_PIN.forEach { digit ->
+ underTest.onPinButtonClicked(digit)
+ }
+ assertThat(pin).isNotEmpty()
+
+ // The user doesn't confirm the PIN, but navigates back to the lockscreen instead.
+ sceneInteractor.changeScene(SceneModel(SceneKey.Lockscreen), "reason")
+ sceneInteractor.onSceneChanged(SceneModel(SceneKey.Lockscreen), "reason")
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Lockscreen))
+
+ // The user navigates to the bouncer again.
+ sceneInteractor.changeScene(SceneModel(SceneKey.Bouncer), "reason")
+ sceneInteractor.onSceneChanged(SceneModel(SceneKey.Bouncer), "reason")
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+
+ underTest.onShown()
+
+ // Ensure the previously-entered PIN is not shown.
+ assertThat(pin).isEmpty()
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+ }
+
+ @Test
fun backspaceButtonAppearance_withoutAutoConfirm_alwaysShown() =
testScope.runTest {
val backspaceButtonAppearance by collectLastValue(underTest.backspaceButtonAppearance)