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

Commit cc58713d authored by Matt Pietal's avatar Matt Pietal
Browse files

Remove pointless `sample` calls when StateFlow exists

`sample` launches coroutines to collect the value from a flow as it
updates. This is not needed for StateFlows, when the value can be
queried as needed.

This should reduce continuations.

Also, change how StatusBarStateControllerImpl collects shade expansion.
isAnyExpanded uses legacy behavior that updates on bouncer expansion.

Bug: 405159039
Test: perfetto analysis
Flag: EXEMPT performance fix
Change-Id: Iba5df3db2907df2f130ac9fe2b437d4dc284a345
parent 928b7963
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ constructor(
    @Application scope: CoroutineScope,
) {
    var receivedDownTouch = false
    val isVisible: Flow<Boolean> = bouncerRepository.alternateBouncerVisible
    val isVisible: StateFlow<Boolean> = bouncerRepository.alternateBouncerVisible
    private val alternateBouncerUiAvailableFromSource: HashSet<String> = HashSet()
    val alternateBouncerSupported: StateFlow<Boolean> =
        fingerprintPropertyRepository.sensorType
+8 −15
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.res.R
import com.android.systemui.util.kotlin.combine
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@@ -128,15 +127,9 @@ constructor(
            scope.launch {
                // On fingerprint success when the screen is on and not dreaming, go to the home
                // screen
                fingerprintUnlockSuccessEvents
                    .sample(
                        combine(
                            powerInteractor.isInteractive,
                            keyguardInteractor.isDreaming,
                            ::Pair,
                        )
                    )
                    .collect { (interactive, dreaming) ->
                fingerprintUnlockSuccessEvents.collect {
                    val interactive = powerInteractor.isInteractive.value
                    val dreaming = keyguardInteractor.isDreaming.value
                    if (interactive && !dreaming) {
                        goToHomeScreen()
                    }
+5 −4
Original line number Diff line number Diff line
@@ -151,8 +151,8 @@ constructor(
        transitionFlows
            .merge()
            .filter { it.transitionState == TransitionState.STARTED }
            .sample(powerInteractor.detailedWakefulness)
            .filter { wakefulnessModel ->
            .filter {
                val wakefulnessModel = powerInteractor.detailedWakefulness.value
                val validWakeupReason =
                    faceWakeUpTriggersConfig.shouldTriggerFaceAuthOnWakeUpFrom(
                        wakefulnessModel.lastWakeReason
@@ -163,9 +163,10 @@ constructor(
                validWakeupReason
            }
            .onEach {
                faceAuthenticationLogger.lockscreenBecameVisible(it)
                val wakefulnessModel = powerInteractor.detailedWakefulness.value
                faceAuthenticationLogger.lockscreenBecameVisible(wakefulnessModel)
                FaceAuthUiEvent.FACE_AUTH_UPDATED_KEYGUARD_VISIBILITY_CHANGED.extraInfo =
                    it.lastWakeReason.powerManagerWakeReason
                    wakefulnessModel.lastWakeReason.powerManagerWakeReason
                runFaceAuth(
                    FaceAuthUiEvent.FACE_AUTH_UPDATED_KEYGUARD_VISIBILITY_CHANGED,
                    fallbackToDetect = true,
+1 −6
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.WakefulnessModel
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineDispatcher
@@ -98,12 +97,8 @@ constructor(
        scope.launch {
            powerInteractor.isAwake
                .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
                .sample(keyguardInteractor.biometricUnlockState, ::Pair)
                .collect {
                    (
                        _,
                        biometricUnlockState,
                    ) ->
                    val biometricUnlockState = keyguardInteractor.biometricUnlockState.value
                    if (isWakeAndUnlock(biometricUnlockState.mode)) {
                        if (SceneContainerFlag.isEnabled) {
                            // TODO(b/360368320): Adapt for scene framework
+11 −13
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import com.android.systemui.power.shared.model.WakeSleepReason.FOLD
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.data.repository.ShadeRepository
import com.android.systemui.util.kotlin.sample
import java.util.UUID
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
@@ -133,12 +132,11 @@ constructor(

        val invalidFromStates = setOf(KeyguardState.AOD, KeyguardState.DOZING)
        scope.launch("$TAG#listenForLockscreenToDreaming") {
            keyguardInteractor.isAbleToDream
                .filterRelevantKeyguardState()
                .sample(transitionInteractor.isFinishedIn(KeyguardState.LOCKSCREEN), ::Pair)
                .collect { (isAbleToDream, isOnLockscreen) ->
                    val transitionInfo =
                        internalTransitionInteractor.currentTransitionInfoInternal()
            keyguardInteractor.isAbleToDream.filterRelevantKeyguardState().collect { isAbleToDream
                ->
                val isOnLockscreen =
                    transitionInteractor.finishedKeyguardState.value == KeyguardState.LOCKSCREEN
                val transitionInfo = internalTransitionInteractor.currentTransitionInfoInternal()
                val isTransitionInterruptible =
                    transitionInfo.to == KeyguardState.LOCKSCREEN &&
                        !invalidFromStates.contains(transitionInfo.from)
Loading