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

Commit e96a3cf3 authored by cocod's avatar cocod
Browse files

Fix keyguard elements flash after tapping a widget which requires unlock

Fix keyguard clock flashing, by overriding willRunAnimationOnKeyguard
to false, if the activity is started from the hub. This will correct the
lockscreenAlpha in PrimaryBouncerToGoneTransitionViewModel.

Fix notifications flashing, by checking if communal scene is visible
during the transition from bouncer to gone, and make sure keyguardAlpha
of the notifications remains 0f while changing to Blank Scene.

Bug: b/343695867
Fix: b/343695867
Flag: com.android.systemui.communal_hub
Test: atest SharedNotificationContainerViewModelTest
Test: atest CommunalSceneInteractorTest
Test: tap a widget, unlock and verify no flash
Change-Id: I6288222fe67d0bca1387e0e64ff983c0af417334
parent 26cd5061
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -59,9 +59,11 @@ import com.android.systemui.communal.ui.compose.Dimensions.SlideOffsetY
import com.android.systemui.communal.ui.compose.extensions.allowGestures
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.util.CommunalColors
import com.android.systemui.keyguard.domain.interactor.FromPrimaryBouncerTransitionInteractor.Companion.TO_GONE_DURATION
import com.android.systemui.res.R
import com.android.systemui.scene.shared.model.SceneDataSourceDelegator
import com.android.systemui.scene.ui.composable.SceneTransitionLayoutDataSource
import kotlin.time.DurationUnit

object Communal {
    object Elements {
@@ -91,6 +93,10 @@ val sceneTransitions = transitions {
        spec = tween(durationMillis = 250)
        fade(AllElements)
    }
    to(CommunalScenes.Blank, key = CommunalTransitionKeys.SimpleFade) {
        spec = tween(durationMillis = TO_GONE_DURATION.toInt(DurationUnit.MILLISECONDS))
        fade(AllElements)
    }
    to(CommunalScenes.Communal) {
        spec = tween(durationMillis = 1000)
        translate(Communal.Elements.Grid, Edge.Right)
+11 −8
Original line number Diff line number Diff line
@@ -83,24 +83,27 @@ class CommunalSceneInteractorTest : SysuiTestCase() {
        }

    @Test
    fun snapToSceneForActivity() =
    fun changeSceneForActivityStartOnDismissKeyguard() =
        testScope.runTest {
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)

            underTest.snapToSceneForActivityStart(CommunalScenes.Communal)
            underTest.snapToScene(CommunalScenes.Communal)
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)

            underTest.changeSceneForActivityStartOnDismissKeyguard()
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
        }

    @Test
    fun snapToSceneForActivity_willNotChangeScene_forEditModeActivity() =
    fun changeSceneForActivityStartOnDismissKeyguard_willNotChangeScene_forEditModeActivity() =
        testScope.runTest {
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
            underTest.snapToScene(CommunalScenes.Communal)
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)

            underTest.setEditModeState(EditModeState.STARTING)
            underTest.snapToSceneForActivityStart(CommunalScenes.Communal)
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)

            underTest.changeSceneForActivityStartOnDismissKeyguard()
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
        }

    @Test
+1 −0
Original line number Diff line number Diff line
@@ -778,6 +778,7 @@ class DreamOverlayServiceTest : SysuiTestCase() {
            DREAM_COMPONENT,
            false /*shouldShowComplication*/
        )
        testScope.runCurrent()
        mMainExecutor.runAllReady()
        assertThat(lifecycleRegistry.currentState).isEqualTo(Lifecycle.State.STARTED)
    }
+297 −20
Original line number Diff line number Diff line
@@ -23,11 +23,15 @@ import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.systemui.Flags.FLAG_CENTRALIZED_STATUS_BAR_HEIGHT_FIX
import com.android.systemui.Flags.FLAG_MIGRATE_CLOCKS_TO_BLUEPRINT
import com.android.systemui.SysuiTestCase
import com.android.systemui.bouncer.data.repository.keyguardBouncerRepository
import com.android.systemui.common.shared.model.NotificationContainerBounds
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.communal.data.repository.communalSceneRepository
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.flags.BrokenWithSceneContainer
@@ -134,6 +138,9 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
    val largeScreenHeaderHelper
        get() = kosmos.mockLargeScreenHeaderHelper

    val communalSceneRepository
        get() = kosmos.communalSceneRepository

    lateinit var underTest: SharedNotificationContainerViewModel

    @Before
@@ -861,9 +868,7 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            keyguardRootViewModel.onNotificationContainerBoundsChanged(top, bottom)
            runCurrent()

                assertThat(bounds).isEqualTo(
                        NotificationContainerBounds(top = top, bottom = bottom)
                )
            assertThat(bounds).isEqualTo(NotificationContainerBounds(top = top, bottom = bottom))
        }

    @Test
@@ -1020,6 +1025,230 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            assertThat(fadeIn[0]).isEqualTo(false)
        }

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

            showPrimaryBouncer()
            showCommunalScene()

            // PRIMARY_BOUNCER->GONE transition is started
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.STARTED,
                    value = 0f,
                )
            )
            runCurrent()

            // PRIMARY_BOUNCER->GONE transition running
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.1f,
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.9f,
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)

            hideCommunalScene()
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.FINISHED,
                    value = 1f
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)
        }

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

            showPrimaryBouncer()
            hideCommunalScene()

            // PRIMARY_BOUNCER->GONE transition is started
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.STARTED,
                )
            )
            runCurrent()

            // PRIMARY_BOUNCER->GONE transition running
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.1f,
                )
            )
            runCurrent()
            assertThat(alpha).isIn(Range.closedOpen(0f, 1f))

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.9f,
                )
            )
            runCurrent()
            assertThat(alpha).isIn(Range.closedOpen(0f, 1f))

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.PRIMARY_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.FINISHED,
                    value = 1f
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)
        }

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

            showAlternateBouncer()
            showCommunalScene()

            // ALTERNATE_BOUNCER->GONE transition is started
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.STARTED,
                    value = 0f,
                )
            )
            runCurrent()

            // ALTERNATE_BOUNCER->GONE transition running
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.1f,
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.9f,
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)

            hideCommunalScene()
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.FINISHED,
                    value = 1f
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)
        }

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

            showAlternateBouncer()
            hideCommunalScene()

            // ALTERNATE_BOUNCER->GONE transition is started
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.STARTED,
                )
            )
            runCurrent()

            // ALTERNATE_BOUNCER->GONE transition running
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.1f,
                )
            )
            runCurrent()
            assertThat(alpha).isIn(Range.closedOpen(0f, 1f))

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.RUNNING,
                    value = 0.9f,
                )
            )
            runCurrent()
            assertThat(alpha).isIn(Range.closedOpen(0f, 1f))

            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = GONE,
                    transitionState = TransitionState.FINISHED,
                    value = 1f
                )
            )
            runCurrent()
            assertThat(alpha).isEqualTo(0f)
        }

    private suspend fun TestScope.showLockscreen() {
        shadeTestUtil.setQsExpansion(0f)
        shadeTestUtil.setLockscreenShadeExpansion(0f)
@@ -1071,4 +1300,52 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            testScope,
        )
    }

    private suspend fun TestScope.showPrimaryBouncer() {
        shadeTestUtil.setQsExpansion(0f)
        shadeTestUtil.setLockscreenShadeExpansion(0f)
        runCurrent()
        keyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
        runCurrent()
        kosmos.keyguardBouncerRepository.setPrimaryShow(true)
        runCurrent()
        keyguardTransitionRepository.sendTransitionSteps(
            from = KeyguardState.GLANCEABLE_HUB,
            to = KeyguardState.PRIMARY_BOUNCER,
            testScope,
        )
    }

    private suspend fun TestScope.showAlternateBouncer() {
        shadeTestUtil.setQsExpansion(0f)
        shadeTestUtil.setLockscreenShadeExpansion(0f)
        runCurrent()
        keyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
        runCurrent()
        kosmos.keyguardBouncerRepository.setPrimaryShow(false)
        runCurrent()
        keyguardTransitionRepository.sendTransitionSteps(
            from = KeyguardState.GLANCEABLE_HUB,
            to = KeyguardState.ALTERNATE_BOUNCER,
            testScope,
        )
    }

    private fun TestScope.showCommunalScene() {
        val transitionState =
            MutableStateFlow<ObservableTransitionState>(
                ObservableTransitionState.Idle(CommunalScenes.Communal)
            )
        communalSceneRepository.setTransitionState(transitionState)
        runCurrent()
    }

    private fun TestScope.hideCommunalScene() {
        val transitionState =
            MutableStateFlow<ObservableTransitionState>(
                ObservableTransitionState.Idle(CommunalScenes.Blank)
            )
        communalSceneRepository.setTransitionState(transitionState)
        runCurrent()
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import java.util.Optional
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -132,6 +133,7 @@ class LegacyActivityStarterInternalImplTest : SysuiTestCase() {
                communalSceneInteractor = communalSceneInteractor,
            )
        whenever(userTracker.userHandle).thenReturn(UserHandle.OWNER)
        whenever(communalSceneInteractor.isIdleOnCommunal).thenReturn(MutableStateFlow(false))
    }

    @Test
Loading