Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35d7187a authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge changes I0b1b7285,I32d3b9af into main

* changes:
  Fix lockout not happening when auto confirm is enabled.
  Fix stale isAutoConfirmEnabled setting state.
parents 17ac0de0 fca11eff
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -179,10 +179,14 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                setAutoConfirmFeatureEnabled(true)
            }
            assertThat(isAutoConfirmEnabled).isTrue()
            val shorterPin =
                FakeAuthenticationRepository.DEFAULT_PIN.toMutableList().apply { removeLast() }
            val defaultPin = FakeAuthenticationRepository.DEFAULT_PIN.toMutableList()

            assertSkipped(underTest.authenticate(shorterPin, tryAutoConfirm = true))
            assertSkipped(
                underTest.authenticate(
                    defaultPin.subList(0, defaultPin.size - 1),
                    tryAutoConfirm = true
                )
            )
            assertThat(underTest.lockoutEndTimestamp).isNull()
            assertThat(kosmos.fakeAuthenticationRepository.lockoutStartedReportCount).isEqualTo(0)
        }
@@ -201,7 +205,6 @@ class AuthenticationInteractorTest : SysuiTestCase() {

            assertFailed(
                underTest.authenticate(wrongPin, tryAutoConfirm = true),
                assertNoResultEvents = true,
            )
        }

@@ -219,7 +222,6 @@ class AuthenticationInteractorTest : SysuiTestCase() {

            assertFailed(
                underTest.authenticate(longerPin, tryAutoConfirm = true),
                assertNoResultEvents = true,
            )
        }

@@ -547,15 +549,10 @@ class AuthenticationInteractorTest : SysuiTestCase() {

    private fun assertFailed(
        authenticationResult: AuthenticationResult,
        assertNoResultEvents: Boolean = false,
    ) {
        assertThat(authenticationResult).isEqualTo(AuthenticationResult.FAILED)
        if (assertNoResultEvents) {
            assertThat(onAuthenticationResult).isNull()
        } else {
        assertThat(onAuthenticationResult).isFalse()
    }
    }

    private fun assertSkipped(
        authenticationResult: AuthenticationResult,
+15 −0
Original line number Diff line number Diff line
@@ -252,7 +252,14 @@ class PinBouncerViewModelTest : SysuiTestCase() {
    @Test
    fun onAutoConfirm_whenCorrect() =
        testScope.runTest {
            // TODO(b/332768183) remove this after the bug if fixed.
            // Collect the flow so that it is hot, in the real application this is done by using a
            // refreshingFlow that relies on the UI to make this flow hot.
            val autoConfirmEnabled by
                collectLastValue(authenticationInteractor.isAutoConfirmEnabled)
            kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true)

            assertThat(autoConfirmEnabled).isTrue()
            val authResult by collectLastValue(authenticationInteractor.onAuthenticationResult)
            lockDeviceAndOpenPinBouncer()

@@ -264,9 +271,17 @@ class PinBouncerViewModelTest : SysuiTestCase() {
    @Test
    fun onAutoConfirm_whenWrong() =
        testScope.runTest {
            // TODO(b/332768183) remove this after the bug if fixed.
            // Collect the flow so that it is hot, in the real application this is done by using a
            // refreshingFlow that relies on the UI to make this flow hot.
            val autoConfirmEnabled by
                collectLastValue(authenticationInteractor.isAutoConfirmEnabled)

            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val pin by collectLastValue(underTest.pinInput.map { it.getPin() })
            kosmos.fakeAuthenticationRepository.setAutoConfirmFeatureEnabled(true)

            assertThat(autoConfirmEnabled).isTrue()
            lockDeviceAndOpenPinBouncer()

            FakeAuthenticationRepository.DEFAULT_PIN.dropLast(1).forEach { digit ->
+0 −6
Original line number Diff line number Diff line
@@ -243,12 +243,6 @@ constructor(
        }

        // Authentication failed.

        if (tryAutoConfirm) {
            // Auto-confirm is active, the failed attempt should have no side-effects.
            return AuthenticationResult.FAILED
        }

        repository.reportAuthenticationAttempt(isSuccessful = false)

        if (authenticationResult.lockoutDurationMs > 0) {
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ class PinBouncerViewModel(
            .map { if (it) ActionButtonAppearance.Hidden else ActionButtonAppearance.Shown }
            .stateIn(
                scope = viewModelScope,
                started = SharingStarted.Eagerly,
                started = SharingStarted.WhileSubscribed(),
                initialValue = ActionButtonAppearance.Hidden,
            )