Loading packages/SystemUI/multivalentTests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +7 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -202,6 +204,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { ) .isEqualTo(AuthenticationResult.SKIPPED) assertThat(throttling).isNull() assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(0) } @Test Loading Loading @@ -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() Loading @@ -363,6 +367,8 @@ class AuthenticationInteractorTest : SysuiTestCase() { // Auto-confirm is re-enabled. assertThat(isAutoConfirmEnabled).isTrue() assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(1) } @Test Loading @@ -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)) Loading packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +9 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) Loading packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +7 −6 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt +6 −0 Original line number Diff line number Diff line Loading @@ -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 } Loading @@ -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 } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +7 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -202,6 +204,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { ) .isEqualTo(AuthenticationResult.SKIPPED) assertThat(throttling).isNull() assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(0) } @Test Loading Loading @@ -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() Loading @@ -363,6 +367,8 @@ class AuthenticationInteractorTest : SysuiTestCase() { // Auto-confirm is re-enabled. assertThat(isAutoConfirmEnabled).isTrue() assertThat(utils.authenticationRepository.lockoutStartedReportCount).isEqualTo(1) } @Test Loading @@ -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)) Loading
packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +9 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) Loading
packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +7 −6 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/tests/utils/src/com/android/systemui/authentication/data/repository/FakeAuthenticationRepository.kt +6 −0 Original line number Diff line number Diff line Loading @@ -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 } Loading @@ -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 } Loading