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

Commit 835653f6 authored by Chandru S's avatar Chandru S
Browse files

Repeated calls to cancel should cancel any previously scheduled cancellation timeout jobs

Fixes: 291161749
Test: atest DeviceEntryFaceAuthRepositoryTest
Change-Id: I128b0cd68b29dfa9428df938f8dd03b336cd9c48
parent 025de17a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -574,6 +574,7 @@ constructor(
        if (authCancellationSignal == null) return

        authCancellationSignal?.cancel()
        cancelNotReceivedHandlerJob?.cancel()
        cancelNotReceivedHandlerJob =
            applicationScope.launch {
                delay(DEFAULT_CANCEL_SIGNAL_TIMEOUT)
@@ -583,6 +584,7 @@ constructor(
                    cancellationInProgress,
                    faceAuthRequestedWhileCancellation
                )
                _authenticationStatus.value = ErrorFaceAuthenticationStatus.cancelNotReceivedError()
                onFaceAuthRequestCompleted()
            }
        cancellationInProgress = true
+8 −0
Original line number Diff line number Diff line
@@ -63,6 +63,14 @@ data class ErrorFaceAuthenticationStatus(
    fun isHardwareError() =
        msgId == FaceManager.FACE_ERROR_HW_UNAVAILABLE ||
            msgId == FaceManager.FACE_ERROR_UNABLE_TO_PROCESS

    companion object {
        /**
         * Error message that is created when cancel confirmation is not received from FaceManager
         * after we request for a cancellation of face auth.
         */
        fun cancelNotReceivedError() = ErrorFaceAuthenticationStatus(-1, "")
    }
}

/** Face detection success message. */
+24 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.systemui.bouncer.data.repository.FakeKeyguardBouncerRepositor
import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor
import com.android.systemui.coroutines.FlowValue
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.dump.DumpManager
import com.android.systemui.dump.logcatLogBuffer
import com.android.systemui.flags.FakeFeatureFlags
@@ -450,6 +451,29 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() {
            faceAuthenticateIsCalled()
        }

    @Test
    fun multipleCancelCallsShouldNotCauseMultipleCancellationStatusBeingEmitted() =
        testScope.runTest {
            initCollectors()
            allPreconditionsToRunFaceAuthAreTrue()
            val emittedValues by collectValues(underTest.authenticationStatus)

            underTest.authenticate(FACE_AUTH_TRIGGERED_SWIPE_UP_ON_BOUNCER)
            underTest.cancel()
            advanceTimeBy(100)
            underTest.cancel()

            advanceTimeBy(DeviceEntryFaceAuthRepositoryImpl.DEFAULT_CANCEL_SIGNAL_TIMEOUT)
            runCurrent()
            advanceTimeBy(DeviceEntryFaceAuthRepositoryImpl.DEFAULT_CANCEL_SIGNAL_TIMEOUT)
            runCurrent()

            assertThat(emittedValues.size).isEqualTo(1)
            assertThat(emittedValues.first())
                .isInstanceOf(ErrorFaceAuthenticationStatus::class.java)
            assertThat((emittedValues.first() as ErrorFaceAuthenticationStatus).msgId).isEqualTo(-1)
        }

    @Test
    fun faceHelpMessagesAreIgnoredBasedOnConfig() =
        testScope.runTest {