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

Commit 74972567 authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Fix flashing when folding to AOD

LightRevealScrimInteractor was launching
scrim animation when folding to AOD
which lasts 500ms. This was causing the content
behind the notifications shade to be sometimes
visible momentarily right after folding.

Updated the logic to immediately set
scrim progress to '0' when folding to AOD.
This allows to update the scrim 500ms earlier,
which reduces the chances to see the content
behind the shade after folding.

Fixes: 357169978
Test: atest LightRevealScrimInteractorTest
Test: fold multiple times manually
Flag: EXEMPT bugfix
Change-Id: I0a95baa245da58f50449ccfa7692e80252548c91
parent aad11054
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -21,16 +21,23 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectValues
import com.android.systemui.keyguard.data.fakeLightRevealScrimRepository
import com.android.systemui.keyguard.data.repository.DEFAULT_REVEAL_DURATION
import com.android.systemui.keyguard.data.repository.DEFAULT_REVEAL_EFFECT
import com.android.systemui.keyguard.data.repository.FakeLightRevealScrimRepository
import com.android.systemui.keyguard.data.repository.FakeLightRevealScrimRepository.RevealAnimatorRequest
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.data.repository.fakePowerRepository
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.statusbar.LightRevealEffect
import com.android.systemui.statusbar.LightRevealScrim
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -52,6 +59,8 @@ class LightRevealScrimInteractorTest : SysuiTestCase() {

    private val fakeKeyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository

    private val fakePowerRepository = kosmos.fakePowerRepository

    private val underTest = kosmos.lightRevealScrimInteractor

    private val reveal1 =
@@ -107,4 +116,50 @@ class LightRevealScrimInteractorTest : SysuiTestCase() {
            runCurrent()
            assertEquals(listOf(DEFAULT_REVEAL_EFFECT, reveal1, reveal2), values)
        }

    @Test
    fun transitionToAod_folding_doesNotAnimateTheScrim() =
        kosmos.testScope.runTest {
            updateWakefulness(goToSleepReason = WakeSleepReason.FOLD)
            runCurrent()

            // Transition to AOD
            fakeKeyguardTransitionRepository.sendTransitionStep(
                TransitionStep(to = KeyguardState.AOD, transitionState = TransitionState.STARTED)
            )
            runCurrent()

            assertThat(fakeLightRevealScrimRepository.revealAnimatorRequests.last())
                .isEqualTo(RevealAnimatorRequest(reveal = false, duration = 0))
        }

    @Test
    fun transitionToAod_powerButton_animatesTheScrim() =
        kosmos.testScope.runTest {
            updateWakefulness(goToSleepReason = WakeSleepReason.POWER_BUTTON)
            runCurrent()

            // Transition to AOD
            fakeKeyguardTransitionRepository.sendTransitionStep(
                TransitionStep(to = KeyguardState.AOD, transitionState = TransitionState.STARTED)
            )
            runCurrent()

            assertThat(fakeLightRevealScrimRepository.revealAnimatorRequests.last())
                .isEqualTo(
                    RevealAnimatorRequest(
                        reveal = false,
                        duration = DEFAULT_REVEAL_DURATION
                    )
                )
        }

    private fun updateWakefulness(goToSleepReason: WakeSleepReason) {
        fakePowerRepository.updateWakefulness(
            rawState = WakefulnessState.STARTING_TO_SLEEP,
            lastWakeReason = WakeSleepReason.POWER_BUTTON,
            lastSleepReason = goToSleepReason,
            powerButtonLaunchGestureTriggered = false
        )
    }
}
+21 −1
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.systemui.keyguard.domain.interactor
import com.android.keyguard.logging.ScrimLogger
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.data.repository.DEFAULT_REVEAL_DURATION
import com.android.systemui.keyguard.data.repository.LightRevealScrimRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.statusbar.LightRevealEffect
import com.android.systemui.util.kotlin.sample
import dagger.Lazy
@@ -50,10 +52,28 @@ constructor(
        scope.launch {
            transitionInteractor.startedKeyguardTransitionStep.collect {
                scrimLogger.d(TAG, "listenForStartedKeyguardTransitionStep", it)
                lightRevealScrimRepository.startRevealAmountAnimator(willBeRevealedInState(it.to))
                val animationDuration =
                    if (it.to == KeyguardState.AOD && isLastSleepDueToFold) {
                        // Do not animate the scrim when folding as we want to cover the screen
                        // with the scrim immediately while displays are switching.
                        // This is needed to play the fold to AOD animation which starts with
                        // fully black screen (see FoldAodAnimationController)
                        0L
                    } else {
                        DEFAULT_REVEAL_DURATION
                    }

                lightRevealScrimRepository.startRevealAmountAnimator(
                    willBeRevealedInState(it.to),
                    duration = animationDuration
                )
            }
        }
    }

    private val isLastSleepDueToFold: Boolean
        get() = powerInteractor.get().detailedWakefulness.value
            .lastSleepReason == WakeSleepReason.FOLD

    /**
     * Whenever a keyguard transition starts, sample the latest reveal effect from the repository
+9 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ class FakeLightRevealScrimRepository : LightRevealScrimRepository {
    private val _revealAmount: MutableStateFlow<Float> = MutableStateFlow(0.0f)
    override val revealAmount: Flow<Float> = _revealAmount

    val revealAnimatorRequests: MutableList<RevealAnimatorRequest> = arrayListOf()

    override val isAnimating: Boolean
        get() = false

@@ -44,5 +46,12 @@ class FakeLightRevealScrimRepository : LightRevealScrimRepository {
        } else {
            _revealAmount.value = 0.0f
        }

        revealAnimatorRequests.add(RevealAnimatorRequest(reveal, duration))
    }

    data class RevealAnimatorRequest(
        val reveal: Boolean,
        val duration: Long
    )
}