Loading packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +5 −0 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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, Loading packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +10 −3 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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() Loading packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +18 −0 Original line number Diff line number Diff line Loading @@ -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) } } packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt +13 −0 Original line number Diff line number Diff line Loading @@ -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) Loading packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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() Loading Loading
packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +5 −0 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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, Loading
packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +10 −3 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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() Loading
packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +18 −0 Original line number Diff line number Diff line Loading @@ -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) } }
packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt +13 −0 Original line number Diff line number Diff line Loading @@ -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) Loading
packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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() Loading