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

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

Merge "[flexiglass] Ignore passwords shorter than 4 chars." into main

parents d3504987 57f6fdf2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@ interface AuthenticationRepository {
    /** The minimal length of a pattern. */
    val minPatternLength: Int

    /** The minimal length of a password. */
    val minPasswordLength: Int

    /** Whether the "enhanced PIN privacy" setting is enabled for the current user. */
    val isPinEnhancedPrivacyEnabled: StateFlow<Boolean>

@@ -220,6 +223,8 @@ constructor(

    override val minPatternLength: Int = LockPatternUtils.MIN_LOCK_PATTERN_SIZE

    override val minPasswordLength: Int = LockPatternUtils.MIN_LOCK_PASSWORD_SIZE

    override val isPinEnhancedPrivacyEnabled: StateFlow<Boolean> =
        refreshingFlow(
            initialValue = true,
+10 −3
Original line number Diff line number Diff line
@@ -200,9 +200,8 @@ constructor(
                // We're being throttled, the UI layer should not have called this; skip the
                // attempt.
                isThrottled.value -> true
                // The pattern is too short; skip the attempt.
                authMethod == AuthenticationMethodModel.Pattern &&
                    input.size < repository.minPatternLength -> true
                // The input is too short; skip the attempt.
                input.isTooShort(authMethod) -> true
                // Auto-confirm attempt when the feature is not enabled; skip the attempt.
                tryAutoConfirm && !isAutoConfirmEnabled.value -> true
                // Auto-confirm should skip the attempt if the pin entered is too short.
@@ -247,6 +246,14 @@ constructor(
        }
    }

    private fun List<Any>.isTooShort(authMethod: AuthenticationMethodModel): Boolean {
        return when (authMethod) {
            AuthenticationMethodModel.Pattern -> size < repository.minPatternLength
            AuthenticationMethodModel.Password -> size < repository.minPasswordLength
            else -> false
        }
    }

    /** Starts refreshing the throttling state every second. */
    private suspend fun startThrottlingCountdown() {
        cancelThrottlingCountdown()
+18 −0
Original line number Diff line number Diff line
@@ -455,4 +455,22 @@ class AuthenticationInteractorTest : SysuiTestCase() {

            assertThat(hintedPinLength).isNull()
        }

    @Test
    fun authenticate_withTooShortPassword() =
        testScope.runTest {
            utils.authenticationRepository.setAuthenticationMethod(
                AuthenticationMethodModel.Password
            )
            assertThat(
                    underTest.authenticate(
                        buildList {
                            repeat(utils.authenticationRepository.minPasswordLength - 1) { time ->
                                add("$time")
                            }
                        }
                    )
                )
                .isEqualTo(AuthenticationResult.SKIPPED)
        }
}
+13 −0
Original line number Diff line number Diff line
@@ -172,6 +172,19 @@ class BouncerInteractorTest : SysuiTestCase() {
            underTest.resetMessage()
            assertThat(message).isEqualTo(MESSAGE_ENTER_YOUR_PASSWORD)

            // Too short input.
            assertThat(
                    underTest.authenticate(
                        buildList {
                            repeat(utils.authenticationRepository.minPasswordLength - 1) { time ->
                                add("$time")
                            }
                        }
                    )
                )
                .isEqualTo(AuthenticationResult.SKIPPED)
            assertThat(message).isEqualTo(MESSAGE_WRONG_PASSWORD)

            // Correct input.
            assertThat(underTest.authenticate("password".toList()))
                .isEqualTo(AuthenticationResult.SUCCEEDED)
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ class FakeAuthenticationRepository(

    override val minPatternLength: Int = 4

    override val minPasswordLength: Int = 4

    private val _isPinEnhancedPrivacyEnabled = MutableStateFlow(false)
    override val isPinEnhancedPrivacyEnabled: StateFlow<Boolean> =
        _isPinEnhancedPrivacyEnabled.asStateFlow()