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

Commit 24b64e64 authored by Chandru S's avatar Chandru S Committed by Android (Google) Code Review
Browse files

Merge "Move all flows to the background dispatcher" into main

parents 97d3a6b1 3f22a8b9
Loading
Loading
Loading
Loading
+16 −30
Original line number Diff line number Diff line
@@ -187,8 +187,7 @@ constructor(
        faceManager?.sensorPropertiesInternal?.firstOrNull()?.supportsFaceDetection ?: false

    private val _isAuthRunning = MutableStateFlow(false)
    override val isAuthRunning: StateFlow<Boolean>
        get() = _isAuthRunning
    override val isAuthRunning: StateFlow<Boolean> = _isAuthRunning

    private val keyguardSessionId: InstanceId?
        get() = sessionTracker.getSessionId(StatusBarManager.SESSION_KEYGUARD)
@@ -254,6 +253,13 @@ constructor(
                )
                .andAllFlows("canFaceAuthRun", faceAuthLog)
                .flowOn(backgroundDispatcher)
                .onEach {
                    faceAuthLogger.canFaceAuthRunChanged(it)
                    if (!it) {
                        // Cancel currently running auth if any of the gating checks are false.
                        cancel()
                    }
                }
                .stateIn(applicationScope, SharingStarted.Eagerly, false)

        // Face detection can run only when lockscreen bypass is enabled
@@ -281,9 +287,12 @@ constructor(
                )
                .andAllFlows("canFaceDetectRun", faceDetectLog)
                .flowOn(backgroundDispatcher)
                .onEach {
                    if (!it) {
                        cancelDetection()
                    }
                }
                .stateIn(applicationScope, SharingStarted.Eagerly, false)
        observeFaceAuthGatingChecks()
        observeFaceDetectGatingChecks()
        observeFaceAuthResettingConditions()
        listenForSchedulingWatchdog()
        processPendingAuthRequests()
@@ -317,6 +326,7 @@ constructor(
                    it.selectionStatus == SelectionStatus.SELECTION_IN_PROGRESS
                },
            )
            .flowOn(backgroundDispatcher)
            .onEach { anyOfThemIsTrue ->
                if (anyOfThemIsTrue) {
                    clearPendingAuthRequest("Resetting auth status")
@@ -337,17 +347,6 @@ constructor(
        pendingAuthenticateRequest.value = null
    }

    private fun observeFaceDetectGatingChecks() {
        canRunDetection
            .onEach {
                if (!it) {
                    cancelDetection()
                }
            }
            .flowOn(mainDispatcher)
            .launchIn(applicationScope)
    }

    private fun isUdfps() =
        deviceEntryFingerprintAuthRepository.availableFpSensorType.map {
            it == BiometricType.UNDER_DISPLAY_FINGERPRINT
@@ -406,20 +405,6 @@ constructor(
        )
    }

    private fun observeFaceAuthGatingChecks() {
        canRunFaceAuth
            .onEach {
                faceAuthLogger.canFaceAuthRunChanged(it)
                if (!it) {
                    // Cancel currently running auth if any of the gating checks are false.
                    faceAuthLogger.cancellingFaceAuth()
                    cancel()
                }
            }
            .flowOn(mainDispatcher)
            .launchIn(applicationScope)
    }

    private val faceAuthCallback =
        object : FaceManager.AuthenticationCallback() {
            override fun onAuthenticationFailed() {
@@ -554,7 +539,7 @@ constructor(
                    authenticate(it.uiEvent, it.fallbackToDetection)
                }
            }
            .flowOn(mainDispatcher)
            .flowOn(backgroundDispatcher)
            .launchIn(applicationScope)
    }

@@ -650,6 +635,7 @@ constructor(
    override fun cancel() {
        if (authCancellationSignal == null) return

        faceAuthLogger.cancellingFaceAuth()
        authCancellationSignal?.cancel()
        cancelNotReceivedHandlerJob?.cancel()
        cancelNotReceivedHandlerJob =
+7 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor
import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository
import com.android.systemui.keyguard.data.repository.DeviceEntryFaceAuthRepository
@@ -69,6 +70,7 @@ constructor(
    private val context: Context,
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainDispatcher: CoroutineDispatcher,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val repository: DeviceEntryFaceAuthRepository,
    private val primaryBouncerInteractor: Lazy<PrimaryBouncerInteractor>,
    private val alternateBouncerInteractor: AlternateBouncerInteractor,
@@ -104,6 +106,7 @@ constructor(
                    fallbackToDetect = false
                )
            }
            .flowOn(backgroundDispatcher)
            .launchIn(applicationScope)

        alternateBouncerInteractor.isVisible
@@ -115,6 +118,7 @@ constructor(
                    fallbackToDetect = false
                )
            }
            .flowOn(backgroundDispatcher)
            .launchIn(applicationScope)

        merge(
@@ -143,6 +147,7 @@ constructor(
                    fallbackToDetect = true
                )
            }
            .flowOn(backgroundDispatcher)
            .launchIn(applicationScope)

        deviceEntryFingerprintAuthRepository.isLockedOut
@@ -155,6 +160,7 @@ constructor(
                    }
                }
            }
            .flowOn(backgroundDispatcher)
            .launchIn(applicationScope)

        // User switching should stop face auth and then when it is complete we should trigger face
@@ -178,6 +184,7 @@ constructor(
                    )
                }
            }
            .flowOn(backgroundDispatcher)
            .launchIn(applicationScope)
    }

+1 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ class KeyguardFaceAuthInteractorTest : SysuiTestCase() {
                mContext,
                testScope.backgroundScope,
                dispatcher,
                dispatcher,
                faceAuthRepository,
                {
                    PrimaryBouncerInteractor(