diff options
5 files changed, 48 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt b/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt index d5c7f93e1413..a42c0ae39c88 100644 --- a/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt @@ -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, diff --git a/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt b/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt index 5eefbf5353d3..c2974862bffb 100644 --- a/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt @@ -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() diff --git a/packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt index 7439db29b513..56d3d260d196 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt @@ -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) + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt index 6e2e6377db42..50d2fd22d0fa 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt @@ -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) diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt index c0dbeca423ac..45ded7ffcc8c 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt @@ -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() |