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

Commit 0da358b8 authored by Danny Burakov's avatar Danny Burakov Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Always round up the remaining throttle milliseconds." into main

parents f8bfb6da 9e58a42d
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ import com.android.systemui.authentication.shared.model.AuthenticationThrottling
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.scene.SceneTestUtils
import com.google.common.truth.Truth.assertThat
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
@@ -335,7 +333,7 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                    AuthenticationThrottlingModel(
                        failedAttemptCount =
                            FakeAuthenticationRepository.MAX_FAILED_AUTH_TRIES_BEFORE_THROTTLING,
                        remainingMs = FakeAuthenticationRepository.THROTTLE_DURATION_MS,
                        remainingSeconds = FakeAuthenticationRepository.THROTTLE_DURATION_SECONDS,
                    )
                )

@@ -347,15 +345,12 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                    AuthenticationThrottlingModel(
                        failedAttemptCount =
                            FakeAuthenticationRepository.MAX_FAILED_AUTH_TRIES_BEFORE_THROTTLING,
                        remainingMs = FakeAuthenticationRepository.THROTTLE_DURATION_MS,
                        remainingSeconds = FakeAuthenticationRepository.THROTTLE_DURATION_SECONDS,
                    )
                )

            // Move the clock forward to ALMOST skip the throttling, leaving one second to go:
            val throttleTimeoutSec =
                FakeAuthenticationRepository.THROTTLE_DURATION_MS.milliseconds.inWholeSeconds
                    .toInt()
            repeat(throttleTimeoutSec - 1) { time ->
            repeat(FakeAuthenticationRepository.THROTTLE_DURATION_SECONDS - 1) { time ->
                advanceTimeBy(1000)
                assertThat(throttling)
                    .isEqualTo(
@@ -363,9 +358,8 @@ class AuthenticationInteractorTest : SysuiTestCase() {
                            failedAttemptCount =
                                FakeAuthenticationRepository
                                    .MAX_FAILED_AUTH_TRIES_BEFORE_THROTTLING,
                            remainingMs =
                                ((throttleTimeoutSec - (time + 1)).seconds.inWholeMilliseconds)
                                    .toInt(),
                            remainingSeconds =
                                FakeAuthenticationRepository.THROTTLE_DURATION_SECONDS - (time + 1),
                        )
                    )
            }
+2 −4
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardFaceAuthInteracto
import com.android.systemui.res.R
import com.android.systemui.scene.SceneTestUtils
import com.google.common.truth.Truth.assertThat
import kotlin.math.ceil
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceTimeBy
@@ -268,7 +267,7 @@ class BouncerInteractorTest : SysuiTestCase() {
                    AuthenticationThrottlingModel(
                        failedAttemptCount =
                            FakeAuthenticationRepository.MAX_FAILED_AUTH_TRIES_BEFORE_THROTTLING,
                        remainingMs = FakeAuthenticationRepository.THROTTLE_DURATION_MS,
                        remainingSeconds = FakeAuthenticationRepository.THROTTLE_DURATION_SECONDS,
                    )
                )
            assertTryAgainMessage(
@@ -286,8 +285,7 @@ class BouncerInteractorTest : SysuiTestCase() {
                    .toInt()
            )

            throttling?.remainingMs?.let { remainingMs ->
                val seconds = ceil(remainingMs / 1000f).toInt()
            throttling?.remainingSeconds?.let { seconds ->
                repeat(seconds) { time ->
                    advanceTimeBy(1000)
                    val remainingTimeSec = seconds - time - 1
+7 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.flags.Flags
import com.android.systemui.scene.SceneTestUtils
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
@@ -144,7 +145,9 @@ class BouncerViewModelTest : SysuiTestCase() {
            }
            assertThat(message?.isUpdateAnimated).isFalse()

            throttling?.remainingMs?.let { remainingMs -> advanceTimeBy(remainingMs.toLong()) }
            throttling?.remainingSeconds?.let { remainingSeconds ->
                advanceTimeBy(remainingSeconds.seconds.inWholeMilliseconds)
            }
            assertThat(message?.isUpdateAnimated).isTrue()
        }

@@ -167,7 +170,9 @@ class BouncerViewModelTest : SysuiTestCase() {
            }
            assertThat(isInputEnabled).isFalse()

            throttling?.remainingMs?.let { milliseconds -> advanceTimeBy(milliseconds.toLong()) }
            throttling?.remainingSeconds?.let { remainingSeconds ->
                advanceTimeBy(remainingSeconds.seconds.inWholeMilliseconds)
            }
            assertThat(isInputEnabled).isTrue()
        }

+3 −3
Original line number Diff line number Diff line
@@ -335,12 +335,12 @@ class PasswordBouncerViewModelTest : SysuiTestCase() {
            repeat(failedAttemptCount) {
                authenticationRepository.reportAuthenticationAttempt(false)
            }
            val remainingTimeMs = 30_000
            authenticationRepository.setThrottleDuration(remainingTimeMs)
            val remainingTimeSeconds = 30
            authenticationRepository.setThrottleDuration(remainingTimeSeconds * 1000)
            authenticationRepository.throttling.value =
                AuthenticationThrottlingModel(
                    failedAttemptCount = failedAttemptCount,
                    remainingMs = remainingTimeMs,
                    remainingSeconds = remainingTimeSeconds,
                )
        } else {
            authenticationRepository.reportAuthenticationAttempt(true)
+2 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.user.data.repository.UserRepository
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject
import kotlin.math.ceil
import kotlin.math.max
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineDispatcher
@@ -283,7 +284,7 @@ constructor(
                if (remainingMs > 0) {
                    AuthenticationThrottlingModel(
                        failedAttemptCount = failedAttemptCount.await(),
                        remainingMs = remainingMs.toInt(),
                        remainingSeconds = ceil(remainingMs / 1000f).toInt(),
                    )
                } else {
                    null // Throttling ended.
Loading