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

Commit 2f982732 authored by Matt Pietal's avatar Matt Pietal
Browse files

Prevent notif flicker during entirety of swipe to unlock

The current shade relies of status bar state, and so we still
need to check this to confirm that the user has completely
unlocked their device.

Also, remove redundant transition and update shadeExpansion to
be state flow (which matches the rest of the shade flows).

Test: atest SharedNotificationViewModelTest
Fixes: 329236043
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint
TEAMFOOD

Change-Id: I0af12eed5046b9238f66646f9752f48f18aae560
parent 267df17d
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -68,9 +68,7 @@ class LockscreenToGoneTransitionViewModelTest : SysuiTestCase() {
            repository.sendTransitionStep(step(0f))
            assertThat(alpha).isEqualTo(0.5f)

            repository.sendTransitionStep(step(0.25f))
            assertThat(alpha).isEqualTo(0.25f)

            // Before the halfway point, it will have reached zero
            repository.sendTransitionStep(step(.5f))
            assertThat(alpha).isEqualTo(0f)
        }
+53 −0
Original line number Diff line number Diff line
@@ -719,6 +719,59 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() {
            assertThat(alpha).isEqualTo(1f)
        }

    @Test
    fun alphaDoesNotUpdateWhileGoneTransitionIsRunning() =
        testScope.runTest {
            val viewState = ViewStateAccessor()
            val alpha by collectLastValue(underTest.keyguardAlpha(viewState))

            showLockscreen()
            // GONE transition gets to 90% complete
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                    transitionState = TransitionState.STARTED,
                    value = 0f,
                )
            )
            runCurrent()
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.9f,
                )
            )
            runCurrent()

            // At this point, alpha should be zero
            assertThat(alpha).isEqualTo(0f)

            // An attempt to override by the shade should be ignored
            shadeRepository.setQsExpansion(0.5f)
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    fun alphaWhenGoneIsSetToOne() =
        testScope.runTest {
            val viewState = ViewStateAccessor()
            val alpha by collectLastValue(underTest.keyguardAlpha(viewState))

            showLockscreen()

            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GONE,
                testScope
            )
            keyguardRepository.setStatusBarState(StatusBarState.SHADE)

            assertThat(alpha).isEqualTo(1f)
        }

    @Test
    fun shadeCollapseFadeIn() =
        testScope.runTest {
+5 −16
Original line number Diff line number Diff line
@@ -289,7 +289,10 @@ constructor(
                .collect { pair ->
                    val (isKeyguardGoingAway, lastStartedStep) = pair
                    if (isKeyguardGoingAway && lastStartedStep.to == KeyguardState.LOCKSCREEN) {
                        startTransitionTo(KeyguardState.GONE)
                        startTransitionTo(
                            KeyguardState.GONE,
                            modeOnCanceled = TransitionModeOnCanceled.RESET,
                        )
                    }
                }
        }
@@ -303,20 +306,6 @@ constructor(
                    startTransitionTo(KeyguardState.GONE)
                }
            }

            return
        }

        scope.launch {
            keyguardInteractor.isKeyguardGoingAway
                .sample(startedKeyguardTransitionStep, ::Pair)
                .collect { pair ->
                    KeyguardWmStateRefactor.assertInLegacyMode()
                    val (isKeyguardGoingAway, lastStartedStep) = pair
                    if (isKeyguardGoingAway && lastStartedStep.to == KeyguardState.LOCKSCREEN) {
                        startTransitionTo(KeyguardState.GONE)
                    }
                }
        }
    }

@@ -413,7 +402,7 @@ constructor(
        val TO_OCCLUDED_DURATION = 450.milliseconds
        val TO_AOD_DURATION = 500.milliseconds
        val TO_PRIMARY_BOUNCER_DURATION = DEFAULT_DURATION
        val TO_GONE_DURATION = DEFAULT_DURATION
        val TO_GONE_DURATION = 633.milliseconds
        val TO_GLANCEABLE_HUB_DURATION = 1.seconds
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ constructor(
        return transitionValueCache.getOrPut(state) {
            MutableSharedFlow<Float>(
                extraBufferCapacity = 2,
                replay = 1,
                onBufferOverflow = BufferOverflow.DROP_OLDEST
            )
        }
+17 −18
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map

/**
 * Breaks down AOD->LOCKSCREEN transition into discrete steps for corresponding views to consume.
@@ -53,6 +51,8 @@ constructor(
            to = KeyguardState.LOCKSCREEN,
        )

    private var isShadeExpanded = false

    /**
     * Begin the transition from wherever the y-translation value is currently. This helps ensure a
     * smooth transition if a transition in canceled.
@@ -77,22 +77,21 @@ constructor(
    }

    val notificationAlpha: Flow<Float> =
        combine(
            shadeInteractor.shadeExpansion.map { it > 0f },
            shadeInteractor.qsExpansion.map { it > 0f },
        transitionAnimation.sharedFlow(
            duration = 500.milliseconds,
                onStep = { it },
                onCancel = { 1f },
            ),
        ) { isShadeExpanded, isQsExpanded, alpha ->
            if (isShadeExpanded || isQsExpanded) {
                // One example of this happening is dragging a notification while pulsing on AOD
            onStart = {
                isShadeExpanded =
                    shadeInteractor.shadeExpansion.value > 0f ||
                        shadeInteractor.qsExpansion.value > 0f
            },
            onStep = {
                if (isShadeExpanded) {
                    1f
                } else {
                alpha
            }
                    it
                }
            },
        )

    val shortcutsAlpha: Flow<Float> =
        transitionAnimation.sharedFlow(
Loading