Loading packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +17 −4 Original line number Diff line number Diff line Loading @@ -71,10 +71,23 @@ interface AuthenticationRepository { */ val isBypassEnabled: StateFlow<Boolean> /** Whether the auto confirm feature is enabled for the currently-selected user. */ /** * Whether the auto confirm feature is enabled for the currently-selected user. * * Note that the length of the PIN is also important to take into consideration, please see * [hintedPinLength]. */ val isAutoConfirmEnabled: StateFlow<Boolean> /** The length of the PIN for which we should show a hint. */ /** * The exact length a PIN should be for us to enable PIN length hinting. * * A PIN that's shorter or longer than this is not eligible for the UI to render hints showing * how many digits the current PIN is, even if [isAutoConfirmEnabled] is enabled. * * Note that PIN length hinting is only available if the PIN auto confirmation feature is * available. */ val hintedPinLength: Int /** Whether the pattern should be visible for the currently-selected user. */ Loading Loading @@ -166,10 +179,10 @@ constructor( .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = true, initialValue = false, ) override val hintedPinLength: Int = LockPatternUtils.MIN_AUTO_PIN_REQUIREMENT_LENGTH override val hintedPinLength: Int = 6 override val isPatternVisible: StateFlow<Boolean> = userRepository.selectedUserInfo Loading packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +5 −5 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch Loading Loading @@ -103,10 +102,11 @@ constructor( /** The length of the hinted PIN, or `null` if pin length hint should not be shown. */ val hintedPinLength: StateFlow<Int?> = flow { emit(repository.getPinLength()) } .map { currentPinLength -> // Hinting is enabled for 6-digit codes only currentPinLength.takeIf { repository.hintedPinLength == it } repository.isAutoConfirmEnabled .map { isAutoConfirmEnabled -> repository.getPinLength().takeIf { isAutoConfirmEnabled && it == repository.hintedPinLength } } .stateIn( scope = applicationScope, Loading packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ constructor( /** Whether the auto confirm feature is enabled for the currently-selected user. */ val isAutoConfirmEnabled: StateFlow<Boolean> = authenticationInteractor.isAutoConfirmEnabled /** The length of the PIN for which we should show a hint. */ /** The length of the hinted PIN, or `null`, if pin length hint should not be shown. */ val hintedPinLength: StateFlow<Int?> = authenticationInteractor.hintedPinLength /** Whether the pattern should be visible for the currently-selected user. */ Loading packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +94 −10 Original line number Diff line number Diff line Loading @@ -164,7 +164,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { testScope.runTest { val isThrottled by collectLastValue(underTest.isThrottled) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(isThrottled).isFalse() } Loading @@ -172,7 +172,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { fun authenticate_withIncorrectPin_returnsFalse() = testScope.runTest { utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(underTest.authenticate(listOf(9, 8, 7))).isFalse() assertThat(underTest.authenticate(listOf(9, 8, 7, 6, 5, 4))).isFalse() } @Test(expected = IllegalArgumentException::class) Loading Loading @@ -270,7 +270,15 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isThrottled by collectLastValue(underTest.isThrottled) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 3), tryAutoConfirm = true)).isNull() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN.toMutableList().apply { removeLast() }, tryAutoConfirm = true ) ) .isNull() assertThat(isThrottled).isFalse() } Loading @@ -280,7 +288,13 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 4, 4), tryAutoConfirm = true)).isFalse() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN.map { it + 1 }, tryAutoConfirm = true ) ) .isFalse() assertThat(isUnlocked).isFalse() } Loading @@ -290,7 +304,12 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 3, 4, 5), tryAutoConfirm = true)) assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN + listOf(7), tryAutoConfirm = true ) ) .isFalse() assertThat(isUnlocked).isFalse() } Loading @@ -301,7 +320,13 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isTrue() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isTrue() assertThat(isUnlocked).isTrue() } Loading @@ -311,7 +336,13 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(false) assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isNull() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isNull() assertThat(isUnlocked).isFalse() } Loading @@ -334,7 +365,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { val throttling by collectLastValue(underTest.throttling) val isThrottled by collectLastValue(underTest.isThrottled) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) underTest.authenticate(listOf(1, 2, 3, 4)) underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN) assertThat(isUnlocked).isTrue() assertThat(isThrottled).isFalse() assertThat(throttling).isEqualTo(AuthenticationThrottlingModel()) Loading Loading @@ -366,7 +397,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { ) // Correct PIN, but throttled, so doesn't attempt it: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isNull() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isNull() assertThat(isUnlocked).isFalse() assertThat(isThrottled).isTrue() assertThat(throttling) Loading Loading @@ -412,9 +443,62 @@ class AuthenticationInteractorTest : SysuiTestCase() { ) // Correct PIN and no longer throttled so unlocks successfully: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(isUnlocked).isTrue() assertThat(isThrottled).isFalse() assertThat(throttling).isEqualTo(AuthenticationThrottlingModel()) } @Test fun hintedPinLength_withoutAutoConfirm_isNull() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(false) assertThat(hintedPinLength).isNull() } @Test fun hintedPinLength_withAutoConfirmPinTooShort_isNull() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.overrideCredential( buildList { repeat(utils.authenticationRepository.hintedPinLength - 1) { add(it + 1) } } ) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(hintedPinLength).isNull() } @Test fun hintedPinLength_withAutoConfirmPinAtRightLength_isSameLength() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) utils.authenticationRepository.overrideCredential( buildList { repeat(utils.authenticationRepository.hintedPinLength) { add(it + 1) } } ) assertThat(hintedPinLength).isEqualTo(utils.authenticationRepository.hintedPinLength) } @Test fun hintedPinLength_withAutoConfirmPinTooLong_isNull() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.overrideCredential( buildList { repeat(utils.authenticationRepository.hintedPinLength + 1) { add(it + 1) } } ) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(hintedPinLength).isNull() } } packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt +20 −7 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(message).isEqualTo(MESSAGE_ENTER_YOUR_PIN) // Correct input. assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Gone)) } Loading @@ -118,13 +118,20 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(message).isEmpty() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) // Wrong 4-digit pin assertThat(underTest.authenticate(listOf(1, 2, 3, 5), tryAutoConfirm = true)).isFalse() // Wrong 6-digit pin assertThat(underTest.authenticate(listOf(1, 2, 3, 5, 5, 6), tryAutoConfirm = true)) .isFalse() assertThat(message).isEqualTo(MESSAGE_WRONG_PIN) assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) // Correct input. assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isTrue() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isTrue() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Gone)) } Loading @@ -147,7 +154,13 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) // Correct input. assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isNull() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isNull() assertThat(message).isEmpty() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) } Loading Loading @@ -309,7 +322,7 @@ class BouncerInteractorTest : SysuiTestCase() { ) // Correct PIN, but throttled, so doesn't change away from the bouncer scene: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isNull() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isNull() assertThat(currentScene?.key).isEqualTo(SceneKey.Bouncer) assertTryAgainMessage( message, Loading Loading @@ -339,7 +352,7 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(currentScene?.key).isEqualTo(SceneKey.Bouncer) // Correct PIN and no longer throttled so changes to the Gone scene: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(currentScene?.key).isEqualTo(SceneKey.Gone) assertThat(isThrottled).isFalse() assertThat(throttling).isEqualTo(AuthenticationThrottlingModel()) Loading Loading
packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt +17 −4 Original line number Diff line number Diff line Loading @@ -71,10 +71,23 @@ interface AuthenticationRepository { */ val isBypassEnabled: StateFlow<Boolean> /** Whether the auto confirm feature is enabled for the currently-selected user. */ /** * Whether the auto confirm feature is enabled for the currently-selected user. * * Note that the length of the PIN is also important to take into consideration, please see * [hintedPinLength]. */ val isAutoConfirmEnabled: StateFlow<Boolean> /** The length of the PIN for which we should show a hint. */ /** * The exact length a PIN should be for us to enable PIN length hinting. * * A PIN that's shorter or longer than this is not eligible for the UI to render hints showing * how many digits the current PIN is, even if [isAutoConfirmEnabled] is enabled. * * Note that PIN length hinting is only available if the PIN auto confirmation feature is * available. */ val hintedPinLength: Int /** Whether the pattern should be visible for the currently-selected user. */ Loading Loading @@ -166,10 +179,10 @@ constructor( .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = true, initialValue = false, ) override val hintedPinLength: Int = LockPatternUtils.MIN_AUTO_PIN_REQUIREMENT_LENGTH override val hintedPinLength: Int = 6 override val isPatternVisible: StateFlow<Boolean> = userRepository.selectedUserInfo Loading
packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt +5 −5 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch Loading Loading @@ -103,10 +102,11 @@ constructor( /** The length of the hinted PIN, or `null` if pin length hint should not be shown. */ val hintedPinLength: StateFlow<Int?> = flow { emit(repository.getPinLength()) } .map { currentPinLength -> // Hinting is enabled for 6-digit codes only currentPinLength.takeIf { repository.hintedPinLength == it } repository.isAutoConfirmEnabled .map { isAutoConfirmEnabled -> repository.getPinLength().takeIf { isAutoConfirmEnabled && it == repository.hintedPinLength } } .stateIn( scope = applicationScope, Loading
packages/SystemUI/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ constructor( /** Whether the auto confirm feature is enabled for the currently-selected user. */ val isAutoConfirmEnabled: StateFlow<Boolean> = authenticationInteractor.isAutoConfirmEnabled /** The length of the PIN for which we should show a hint. */ /** The length of the hinted PIN, or `null`, if pin length hint should not be shown. */ val hintedPinLength: StateFlow<Int?> = authenticationInteractor.hintedPinLength /** Whether the pattern should be visible for the currently-selected user. */ Loading
packages/SystemUI/tests/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractorTest.kt +94 −10 Original line number Diff line number Diff line Loading @@ -164,7 +164,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { testScope.runTest { val isThrottled by collectLastValue(underTest.isThrottled) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(isThrottled).isFalse() } Loading @@ -172,7 +172,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { fun authenticate_withIncorrectPin_returnsFalse() = testScope.runTest { utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) assertThat(underTest.authenticate(listOf(9, 8, 7))).isFalse() assertThat(underTest.authenticate(listOf(9, 8, 7, 6, 5, 4))).isFalse() } @Test(expected = IllegalArgumentException::class) Loading Loading @@ -270,7 +270,15 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isThrottled by collectLastValue(underTest.isThrottled) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 3), tryAutoConfirm = true)).isNull() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN.toMutableList().apply { removeLast() }, tryAutoConfirm = true ) ) .isNull() assertThat(isThrottled).isFalse() } Loading @@ -280,7 +288,13 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 4, 4), tryAutoConfirm = true)).isFalse() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN.map { it + 1 }, tryAutoConfirm = true ) ) .isFalse() assertThat(isUnlocked).isFalse() } Loading @@ -290,7 +304,12 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 3, 4, 5), tryAutoConfirm = true)) assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN + listOf(7), tryAutoConfirm = true ) ) .isFalse() assertThat(isUnlocked).isFalse() } Loading @@ -301,7 +320,13 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isTrue() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isTrue() assertThat(isUnlocked).isTrue() } Loading @@ -311,7 +336,13 @@ class AuthenticationInteractorTest : SysuiTestCase() { val isUnlocked by collectLastValue(underTest.isUnlocked) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(false) assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isNull() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isNull() assertThat(isUnlocked).isFalse() } Loading @@ -334,7 +365,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { val throttling by collectLastValue(underTest.throttling) val isThrottled by collectLastValue(underTest.isThrottled) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) underTest.authenticate(listOf(1, 2, 3, 4)) underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN) assertThat(isUnlocked).isTrue() assertThat(isThrottled).isFalse() assertThat(throttling).isEqualTo(AuthenticationThrottlingModel()) Loading Loading @@ -366,7 +397,7 @@ class AuthenticationInteractorTest : SysuiTestCase() { ) // Correct PIN, but throttled, so doesn't attempt it: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isNull() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isNull() assertThat(isUnlocked).isFalse() assertThat(isThrottled).isTrue() assertThat(throttling) Loading Loading @@ -412,9 +443,62 @@ class AuthenticationInteractorTest : SysuiTestCase() { ) // Correct PIN and no longer throttled so unlocks successfully: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(isUnlocked).isTrue() assertThat(isThrottled).isFalse() assertThat(throttling).isEqualTo(AuthenticationThrottlingModel()) } @Test fun hintedPinLength_withoutAutoConfirm_isNull() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(false) assertThat(hintedPinLength).isNull() } @Test fun hintedPinLength_withAutoConfirmPinTooShort_isNull() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.overrideCredential( buildList { repeat(utils.authenticationRepository.hintedPinLength - 1) { add(it + 1) } } ) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(hintedPinLength).isNull() } @Test fun hintedPinLength_withAutoConfirmPinAtRightLength_isSameLength() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.setAutoConfirmEnabled(true) utils.authenticationRepository.overrideCredential( buildList { repeat(utils.authenticationRepository.hintedPinLength) { add(it + 1) } } ) assertThat(hintedPinLength).isEqualTo(utils.authenticationRepository.hintedPinLength) } @Test fun hintedPinLength_withAutoConfirmPinTooLong_isNull() = testScope.runTest { val hintedPinLength by collectLastValue(underTest.hintedPinLength) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin) utils.authenticationRepository.overrideCredential( buildList { repeat(utils.authenticationRepository.hintedPinLength + 1) { add(it + 1) } } ) utils.authenticationRepository.setAutoConfirmEnabled(true) assertThat(hintedPinLength).isNull() } }
packages/SystemUI/tests/src/com/android/systemui/bouncer/domain/interactor/BouncerInteractorTest.kt +20 −7 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(message).isEqualTo(MESSAGE_ENTER_YOUR_PIN) // Correct input. assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Gone)) } Loading @@ -118,13 +118,20 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(message).isEmpty() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) // Wrong 4-digit pin assertThat(underTest.authenticate(listOf(1, 2, 3, 5), tryAutoConfirm = true)).isFalse() // Wrong 6-digit pin assertThat(underTest.authenticate(listOf(1, 2, 3, 5, 5, 6), tryAutoConfirm = true)) .isFalse() assertThat(message).isEqualTo(MESSAGE_WRONG_PIN) assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) // Correct input. assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isTrue() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isTrue() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Gone)) } Loading @@ -147,7 +154,13 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) // Correct input. assertThat(underTest.authenticate(listOf(1, 2, 3, 4), tryAutoConfirm = true)).isNull() assertThat( underTest.authenticate( FakeAuthenticationRepository.DEFAULT_PIN, tryAutoConfirm = true ) ) .isNull() assertThat(message).isEmpty() assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer)) } Loading Loading @@ -309,7 +322,7 @@ class BouncerInteractorTest : SysuiTestCase() { ) // Correct PIN, but throttled, so doesn't change away from the bouncer scene: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isNull() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isNull() assertThat(currentScene?.key).isEqualTo(SceneKey.Bouncer) assertTryAgainMessage( message, Loading Loading @@ -339,7 +352,7 @@ class BouncerInteractorTest : SysuiTestCase() { assertThat(currentScene?.key).isEqualTo(SceneKey.Bouncer) // Correct PIN and no longer throttled so changes to the Gone scene: assertThat(underTest.authenticate(listOf(1, 2, 3, 4))).isTrue() assertThat(underTest.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)).isTrue() assertThat(currentScene?.key).isEqualTo(SceneKey.Gone) assertThat(isThrottled).isFalse() assertThat(throttling).isEqualTo(AuthenticationThrottlingModel()) Loading