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

Commit 5905e8a0 authored by Coco Duan's avatar Coco Duan
Browse files

Fix keyguard clock flicker during Gone->Dream with shade open

In GoneToDreamingTransitionViewModel, the keyguard alpha animates out
(1f to 0f). When shade is open, keyguard clock is revealed and then
animates upwards as shade collapses to launch dream.
Fix is to set alpha to 0 if either shade or QS is expanded with an
amount on transition start.

Fixes: b/381944762
Flag: EXEMPT bugfix
Test: on mobile with shade open; tablet on dock with HUN
Test: atest GoneToDreamingTransitionViewModelTest
Change-Id: Ib587244e87aa4e9c93ce85d864ba11172bbfa633
parent 9c5af322
Loading
Loading
Loading
Loading
+48 −8
Original line number Diff line number Diff line
@@ -19,18 +19,21 @@ package com.android.systemui.keyguard.ui.viewmodel
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectValues
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
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.collectLastValue
import com.android.systemui.kosmos.collectValues
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.testKosmos
import com.google.common.collect.Range
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -39,8 +42,7 @@ import org.junit.runner.RunWith
@DisableSceneContainer
@RunWith(AndroidJUnit4::class)
class GoneToDreamingTransitionViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private lateinit var repository: FakeKeyguardTransitionRepository
    private lateinit var underTest: GoneToDreamingTransitionViewModel

@@ -51,9 +53,11 @@ class GoneToDreamingTransitionViewModelTest : SysuiTestCase() {
    }

    @Test
    fun runTest() =
        testScope.runTest {
            val values by collectValues(underTest.lockscreenAlpha)
    fun lockscreenAlpha_whenShadeAndQsNotExpanded() =
        kosmos.runTest {
            val values by collectValues(underTest.lockscreenAlpha())
            shadeTestUtil.setShadeExpansion(0f)
            shadeTestUtil.setQsExpansion(0f)

            repository.sendTransitionSteps(
                listOf(
@@ -75,9 +79,45 @@ class GoneToDreamingTransitionViewModelTest : SysuiTestCase() {
            values.forEach { assertThat(it).isIn(Range.closed(0f, 1f)) }
        }

    @Test
    fun lockscreenAlpha_isZero_whenShadeExpanded() =
        kosmos.runTest {
            shadeTestUtil.setShadeExpansion(0.9f)
            shadeTestUtil.setLegacyExpandedOrAwaitingInputTransfer(true)

            val alpha by collectLastValue(underTest.lockscreenAlpha())

            repository.sendTransitionStep(step(0f, TransitionState.STARTED))
            assertThat(alpha).isEqualTo(0f)

            repository.sendTransitionStep(step(0.1f, TransitionState.RUNNING))
            assertThat(alpha).isEqualTo(0f)

            repository.sendTransitionStep(step(1f, TransitionState.FINISHED))
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    fun lockscreenAlpha_isZero_whenQsExpanded() =
        kosmos.runTest {
            shadeTestUtil.setQsExpansion(0.9f)
            shadeTestUtil.setLegacyExpandedOrAwaitingInputTransfer(true)

            val alpha by collectLastValue(underTest.lockscreenAlpha())

            repository.sendTransitionStep(step(0f, TransitionState.STARTED))
            assertThat(alpha).isEqualTo(0f)

            repository.sendTransitionStep(step(0.1f, TransitionState.RUNNING))
            assertThat(alpha).isEqualTo(0f)

            repository.sendTransitionStep(step(1f, TransitionState.FINISHED))
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    fun lockscreenTranslationY() =
        testScope.runTest {
        kosmos.runTest {
            val pixels = 100
            val values by collectValues(underTest.lockscreenTranslationY(pixels))

+15 −7
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import dagger.Lazy
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.flow.Flow
@@ -34,6 +36,7 @@ class GoneToDreamingTransitionViewModel
@Inject
constructor(
    animationFlow: KeyguardTransitionAnimationFlow,
    private val shadeInteractor: Lazy<ShadeInteractor>,
) {

    private val transitionAnimation =
@@ -42,9 +45,7 @@ constructor(
                duration = TO_DREAMING_DURATION,
                edge = Edge.create(from = Scenes.Gone, to = DREAMING),
            )
            .setupWithoutSceneContainer(
                edge = Edge.create(from = GONE, to = DREAMING),
            )
            .setupWithoutSceneContainer(edge = Edge.create(from = GONE, to = DREAMING))

    /** Lockscreen views y-translation */
    fun lockscreenTranslationY(translatePx: Int): Flow<Float> {
@@ -58,10 +59,17 @@ constructor(
        )
    }

    /** Lockscreen views alpha */
    val lockscreenAlpha: Flow<Float> =
        transitionAnimation.sharedFlow(
    /**
     * Lockscreen views alpha. If coming from an expanded shade or QS that collapsed to launch
     * dream, then lockscreen views should not be visible.
     */
    fun lockscreenAlpha(): Flow<Float> {
        var isAnyExpanded = false
        return transitionAnimation.sharedFlow(
            duration = 250.milliseconds,
            onStep = { 1f - it },
            onStart = { isAnyExpanded = shadeInteractor.get().isAnyExpanded.value },
            onStep = { step -> if (isAnyExpanded) 0f else 1f - step },
            name = "GONE->DREAMING: lockscreenAlpha",
        )
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ constructor(
                        glanceableHubToAodTransitionViewModel.lockscreenAlpha,
                        goneToAodTransitionViewModel.enterFromTopAnimationAlpha,
                        goneToDozingTransitionViewModel.lockscreenAlpha,
                        goneToDreamingTransitionViewModel.lockscreenAlpha,
                        goneToDreamingTransitionViewModel.lockscreenAlpha(),
                        goneToLockscreenTransitionViewModel.lockscreenAlpha,
                        lockscreenToAodTransitionViewModel.lockscreenAlpha(viewState),
                        lockscreenToAodTransitionViewModel.lockscreenAlphaOnFold,
+1 −1
Original line number Diff line number Diff line
@@ -632,7 +632,7 @@ constructor(
            dozingToPrimaryBouncerTransitionViewModel.notificationAlpha,
            dreamingToLockscreenTransitionViewModel.lockscreenAlpha,
            goneToAodTransitionViewModel.notificationAlpha,
            goneToDreamingTransitionViewModel.lockscreenAlpha,
            goneToDreamingTransitionViewModel.lockscreenAlpha(),
            goneToDozingTransitionViewModel.notificationAlpha,
            goneToLockscreenTransitionViewModel.lockscreenAlpha,
            lockscreenToDreamingTransitionViewModel.lockscreenAlpha,
+2 −0
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.systemui.keyguard.ui.viewmodel
import com.android.systemui.keyguard.ui.keyguardTransitionAnimationFlow
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.shade.domain.interactor.shadeInteractor

val Kosmos.goneToDreamingTransitionViewModel by Fixture {
    GoneToDreamingTransitionViewModel(
        animationFlow = keyguardTransitionAnimationFlow,
        shadeInteractor = { shadeInteractor },
    )
}