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

Commit 8ac17daf authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Automerger Merge Worker
Browse files

Merge "[flexiglass] Addresses comments from ag/23884810" into udc-qpr-dev am:...

Merge "[flexiglass] Addresses comments from ag/23884810" into udc-qpr-dev am: 84c721e5 am: bf08232e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24030505



Change-Id: I6a0c4d4d5b15c1fd1efaa9b8eff922b16c7e773e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 79fc8cd3 bf08232e
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -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. */
@@ -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
+5 −5
Original line number Diff line number Diff line
@@ -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
@@ -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,
+1 −1
Original line number Diff line number Diff line
@@ -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. */
+94 −10
Original line number Diff line number Diff line
@@ -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()
        }

@@ -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)
@@ -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()
        }

@@ -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()
        }

@@ -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()
        }
@@ -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()
        }

@@ -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()
        }

@@ -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())
@@ -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)
@@ -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()
        }
}
+20 −7
Original line number Diff line number Diff line
@@ -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))
        }

@@ -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))
        }

@@ -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))
        }
@@ -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,
@@ -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