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

Commit a0b6693a authored by Danny Burakov's avatar Danny Burakov Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Report lockout attempts to the trust manager." into main

parents 758ae4be a9caeaed
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ class AuthenticationInteractorTest : SysuiTestCase() {
            assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN))
                .isEqualTo(AuthenticationResult.SUCCEEDED)
            assertThat(throttling).isNull()
            assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(0)
        }

    @Test
@@ -137,6 +138,7 @@ class AuthenticationInteractorTest : SysuiTestCase() {
            assertThat(underTest.authenticate("password".toList()))
                .isEqualTo(AuthenticationResult.SUCCEEDED)
            assertThat(throttling).isNull()
            assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(0)
        }

    @Test
@@ -202,6 +204,7 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                )
                .isEqualTo(AuthenticationResult.SKIPPED)
            assertThat(throttling).isNull()
            assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(0)
        }

    @Test
@@ -345,6 +348,7 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                underTest.authenticate(listOf(5, 6, 7)) // Wrong PIN
            }
            assertThat(throttling).isNotNull()
            assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(1)

            // Throttling disabled auto-confirm.
            assertThat(isAutoConfirmEnabled).isFalse()
@@ -363,6 +367,8 @@ class AuthenticationInteractorTest : SysuiTestCase() {

            // Auto-confirm is re-enabled.
            assertThat(isAutoConfirmEnabled).isTrue()

            assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(1)
        }

    @Test
@@ -389,6 +395,7 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                        remainingSeconds = FakeAuthenticationRepository.THROTTLE_DURATION_SECONDS,
                    )
                )
            assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(1)

            // Correct PIN, but throttled, so doesn't attempt it:
            assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN))
+9 −0
Original line number Diff line number Diff line
@@ -138,6 +138,9 @@ interface AuthenticationRepository {
    /** Reports an authentication attempt. */
    suspend fun reportAuthenticationAttempt(isSuccessful: Boolean)

    /** Reports that the user has entered a temporary device lockout (throttling). */
    suspend fun reportLockoutStarted(durationMs: Int)

    /** Returns the current number of failed authentication attempts. */
    suspend fun getFailedAuthenticationAttemptCount(): Int

@@ -252,6 +255,12 @@ constructor(
        }
    }

    override suspend fun reportLockoutStarted(durationMs: Int) {
        return withContext(backgroundDispatcher) {
            lockPatternUtils.reportPasswordLockout(durationMs, selectedUserId)
        }
    }

    override suspend fun getFailedAuthenticationAttemptCount(): Int {
        return withContext(backgroundDispatcher) {
            lockPatternUtils.getCurrentFailedPasswordAttempts(selectedUserId)
+7 −6
Original line number Diff line number Diff line
@@ -217,16 +217,17 @@ constructor(

        // Check if we need to throttle and, if so, kick off the throttle countdown:
        if (!authenticationResult.isSuccessful && authenticationResult.throttleDurationMs > 0) {
            repository.setThrottleDuration(
                durationMs = authenticationResult.throttleDurationMs,
            )
            repository.hasThrottlingOccurred.value = true
            repository.apply {
                setThrottleDuration(durationMs = authenticationResult.throttleDurationMs)
                reportLockoutStarted(durationMs = authenticationResult.throttleDurationMs)
                hasThrottlingOccurred.value = true
            }
            startThrottlingCountdown()
        }

        if (authenticationResult.isSuccessful) {
            // Since authentication succeeded, we should refresh throttling to make sure that our
            // state is completely reflecting the upstream source of truth.
            // Since authentication succeeded, refresh throttling to make sure the state is
            // completely reflecting the upstream source of truth.
            refreshThrottling()

            repository.hasThrottlingOccurred.value = false
+6 −0
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ class FakeAuthenticationRepository(
    private var credentialOverride: List<Any>? = null
    private var securityMode: SecurityMode = DEFAULT_AUTHENTICATION_METHOD.toSecurityMode()

    var lockoutStartedReportCount = 0

    override suspend fun getAuthenticationMethod(): AuthenticationMethodModel {
        return authenticationMethod.value
    }
@@ -92,6 +94,10 @@ class FakeAuthenticationRepository(
        authenticationChallengeResult.emit(isSuccessful)
    }

    override suspend fun reportLockoutStarted(durationMs: Int) {
        lockoutStartedReportCount++
    }

    override suspend fun getPinLength(): Int {
        return (credentialOverride ?: DEFAULT_PIN).size
    }