Move haptic from authenticated to confirmed (when required).

Fix: 272832355
Test: atest PromptViewModelTest
Change-Id: I8d9324384680367af7991eab9b5ce42bf378e8bc
This commit is contained in:
Joe Bolinger
2023-07-08 00:04:30 +00:00
parent f9a99625e4
commit e072fe34e4
2 changed files with 19 additions and 12 deletions

View File

@@ -372,7 +372,9 @@ constructor(
AuthBiometricView.STATE_AUTHENTICATED
}
vibrator.success(modality)
if (!needsUserConfirmation) {
vibrator.success(modality)
}
messageJob?.cancel()
messageJob = null
@@ -418,6 +420,8 @@ constructor(
_message.value = PromptMessage.Empty
_legacyState.value = AuthBiometricView.STATE_AUTHENTICATED
vibrator.success(authState.authenticatedModality)
messageJob?.cancel()
messageJob = null
}

View File

@@ -49,6 +49,7 @@ import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.mockito.Mock
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit
@@ -131,20 +132,22 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
}
@Test
fun plays_haptic_on_authenticated() = runGenericTest {
viewModel.showAuthenticated(testCase.authenticatedModality, 1000L)
fun play_haptic_on_confirm_when_confirmation_required_otherwise_on_authenticated() =
runGenericTest {
val expectConfirmation = testCase.expectConfirmation(atLeastOneFailure = false)
verify(vibrator).vibrateAuthSuccess(any())
verify(vibrator, never()).vibrateAuthError(any())
}
viewModel.showAuthenticated(testCase.authenticatedModality, 1_000L)
@Test
fun plays_no_haptic_on_confirm() = runGenericTest {
viewModel.confirmAuthenticated()
verify(vibrator, if (expectConfirmation) never() else times(1))
.vibrateAuthSuccess(any())
verify(vibrator, never()).vibrateAuthSuccess(any())
verify(vibrator, never()).vibrateAuthError(any())
}
if (expectConfirmation) {
viewModel.confirmAuthenticated()
}
verify(vibrator).vibrateAuthSuccess(any())
verify(vibrator, never()).vibrateAuthError(any())
}
private suspend fun TestScope.showAuthenticated(
authenticatedModality: BiometricModality,