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

Commit 21fe7ba0 authored by Coco Duan's avatar Coco Duan Committed by William Xiao
Browse files

Use blur scale to apply depth push on hub transition

This change refactors an ealier motion change ag/34260411.
Instead of handling wallpaper zoom-out separately, we're now integrating
the zoom-out transition animation, directly into the cross-window blur
for hub transitions.
Then the zoom-out flows are wired up to WindowRootView#blurScale, so
that blur radius and scale can be performed together.

Bug: 404535174
Test: atest WindowRootViewModelTest
Flag: com.android.systemui.gesture_between_hub_and_lockscreen_motion
Change-Id: I1b0b8636defcf0d4f3684a12e867367e479f73fb
parent 1f3ac68e
Loading
Loading
Loading
Loading
+0 −71
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import com.android.systemui.keyguard.domain.interactor.pulseExpansionInteractor
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.keyguard.ui.viewmodel.KeyguardRootViewModel.Companion.DEPTH_PUSH_WALLPAPER_FROM_GLANCEABLE_HUB
import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel.Companion.PUSHBACK_SCALE_FOR_LOCKSCREEN
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
@@ -551,76 +550,6 @@ class KeyguardRootViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
            assertThat(alpha).isEqualTo(1.0f)
        }

    @Test
    @EnableFlags(FLAG_GESTURE_BETWEEN_HUB_AND_LOCKSCREEN_MOTION)
    @DisableSceneContainer
    fun wallpaperZoomOut_transitionFromLockscreenToHubAndBack() =
        testScope.runTest {
            val zoomOut by collectLastValue(underTest.wallpaperZoomOut)

            val transitionState: MutableStateFlow<ObservableTransitionState> =
                MutableStateFlow(
                    ObservableTransitionState.Transition(
                        fromScene = CommunalScenes.Blank,
                        toScene = CommunalScenes.Communal,
                        currentScene = flowOf(CommunalScenes.Communal),
                        progress = flowOf(0f),
                        isInitiatedByUserInput = true,
                        isUserInputOngoing = flowOf(false),
                    )
                )

            // Start transition to communal
            communalRepository.setTransitionState(transitionState)

            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GLANCEABLE_HUB,
                testScope,
            )
            // Finish transition to communal
            transitionState.value = ObservableTransitionState.Idle(CommunalScenes.Communal)

            assertThat(zoomOut).isEqualTo(DEPTH_PUSH_WALLPAPER_FROM_GLANCEABLE_HUB)

            // Start transitioning back.
            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.LOCKSCREEN,
                testScope,
            )
            transitionState.value = ObservableTransitionState.Idle(CommunalScenes.Blank)

            assertThat(zoomOut).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    @EnableFlags(FLAG_GESTURE_BETWEEN_HUB_AND_LOCKSCREEN_MOTION)
    fun wallpaperZoomOut_reset_transitionedAwayFromHub() =
        testScope.runTest {
            val zoomOut by collectLastValue(underTest.wallpaperZoomOut)
            val transitionState: MutableStateFlow<ObservableTransitionState> =
                MutableStateFlow(ObservableTransitionState.Idle(CommunalScenes.Blank))

            // Transition to the glanceable hub and then to bouncer.
            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GLANCEABLE_HUB,
                testScope,
            )
            transitionState.value = ObservableTransitionState.Idle(CommunalScenes.Communal)

            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.PRIMARY_BOUNCER,
                testScope,
            )
            transitionState.value = ObservableTransitionState.Idle(CommunalScenes.Blank)

            assertThat(zoomOut).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    @EnableFlags(FLAG_GESTURE_BETWEEN_HUB_AND_LOCKSCREEN_MOTION)
+71 −0
Original line number Diff line number Diff line
@@ -16,17 +16,23 @@

package com.android.systemui.window.ui.viewmodel

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
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.flags.DisableSceneContainer
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.window.data.repository.fakeWindowRootViewBlurRepository
import com.android.systemui.window.data.repository.windowRootViewBlurRepository
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
@@ -38,6 +44,7 @@ import org.junit.runner.RunWith
class WindowRootViewModelTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    private val communalRepository by lazy { kosmos.communalSceneRepository }

    val underTest by lazy { kosmos.windowRootViewModel }

@@ -78,4 +85,68 @@ class WindowRootViewModelTest : SysuiTestCase() {

            assertThat(blurRadius).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    @EnableFlags(Flags.FLAG_GESTURE_BETWEEN_HUB_AND_LOCKSCREEN_MOTION)
    fun blurScale_changes_onZoomOutFromGlanceableHubFlagEnabled() =
        testScope.runTest {
            kosmos.fakeWindowRootViewBlurRepository.isBlurSupported.value = true
            val blurScale by collectLastValue(underTest.blurScale)

            // Communal scene is visible
            val transitionState: MutableStateFlow<ObservableTransitionState> =
                MutableStateFlow(ObservableTransitionState.Idle(CommunalScenes.Communal))
            communalRepository.setTransitionState(transitionState)

            kosmos.fakeGlanceableHubTransitions.first().zoomOut.value = 0.95f
            runCurrent()

            assertThat(blurScale).isEqualTo(0.95f)
        }

    @Test
    @DisableSceneContainer
    @EnableFlags(Flags.FLAG_GESTURE_BETWEEN_HUB_AND_LOCKSCREEN_MOTION)
    fun blurScale_reset_onExitCommunalScene() =
        testScope.runTest {
            kosmos.fakeWindowRootViewBlurRepository.isBlurSupported.value = true
            val blurScale by collectLastValue(underTest.blurScale)

            // Communal scene is visible
            val transitionState: MutableStateFlow<ObservableTransitionState> =
                MutableStateFlow(ObservableTransitionState.Idle(CommunalScenes.Communal))
            communalRepository.setTransitionState(transitionState)

            kosmos.fakeGlanceableHubTransitions.first().zoomOut.value = 0.95f
            runCurrent()

            assertThat(blurScale).isEqualTo(0.95f)

            // Fully exits communal scene
            transitionState.value = ObservableTransitionState.Idle(CommunalScenes.Blank)

            // Scale is reset
            assertThat(blurScale).isEqualTo(1f)
        }

    @Test
    @DisableSceneContainer
    @DisableFlags(Flags.FLAG_GESTURE_BETWEEN_HUB_AND_LOCKSCREEN_MOTION)
    fun blurScale_doesNotChange_onZoomOutFromGlanceableHubFlagDisabled() =
        testScope.runTest {
            kosmos.fakeWindowRootViewBlurRepository.isBlurSupported.value = true
            val blurScale by collectLastValue(underTest.blurScale)

            // Communal scene is visible
            val transitionState: MutableStateFlow<ObservableTransitionState> =
                MutableStateFlow(ObservableTransitionState.Idle(CommunalScenes.Communal))
            communalRepository.setTransitionState(transitionState)

            kosmos.fakeGlanceableHubTransitions.first().zoomOut.value = 0.95f
            runCurrent()

            // Scale is not changed
            assertThat(blurScale).isEqualTo(1f)
        }
}
+0 −3
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.phone.ScreenOffAnimationController
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator
import com.android.systemui.util.WallpaperController
import com.android.systemui.wallpapers.ui.viewmodel.WallpaperViewModel
import com.google.android.msdl.domain.MSDLPlayer
import java.util.Optional
@@ -92,7 +91,6 @@ constructor(
    @Main private val mainDispatcher: CoroutineDispatcher,
    private val msdlPlayer: MSDLPlayer,
    @KeyguardBlueprintLog private val blueprintLog: LogBuffer,
    private val wallpaperController: WallpaperController,
) : CoreStartable {

    private var rootViewHandle: DisposableHandle? = null
@@ -154,7 +152,6 @@ constructor(
                mainDispatcher,
                msdlPlayer,
                blueprintLog,
                wallpaperController,
            )
    }

+0 −10
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import com.android.systemui.temporarydisplay.ViewPriority
import com.android.systemui.temporarydisplay.chipbar.ChipbarCoordinator
import com.android.systemui.temporarydisplay.chipbar.ChipbarInfo
import com.android.systemui.util.WallpaperController
import com.android.systemui.util.kotlin.DisposableHandles
import com.android.systemui.util.ui.AnimatedValue
import com.android.systemui.util.ui.isAnimating
@@ -108,7 +107,6 @@ object KeyguardRootViewBinder {
        mainImmediateDispatcher: CoroutineDispatcher,
        msdlPlayer: MSDLPlayer?,
        @KeyguardBlueprintLog blueprintLog: LogBuffer,
        wallpaperController: WallpaperController,
    ): DisposableHandle {
        val disposables = DisposableHandles()
        val childViews = mutableMapOf<Int, View>()
@@ -363,14 +361,6 @@ object KeyguardRootViewBinder {
                    }

                    launch { burnInParams.collect { viewModel.updateBurnInParams(it) } }

                    if (Flags.gestureBetweenHubAndLockscreenMotion()) {
                        launch {
                            viewModel.wallpaperZoomOut.collect { zoomOutToApply ->
                                wallpaperController.setWallpaperZoom(zoomOutToApply)
                            }
                        }
                    }
                }
            }

+5 −0
Original line number Diff line number Diff line
@@ -17,8 +17,13 @@
package com.android.systemui.keyguard.ui.transitions

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow

interface GlanceableHubTransition {
    /** Radius of blur applied to the window's root view. */
    val windowBlurRadius: Flow<Float>

    /** Zoom out applied to the window's or keyguard's root view. */
    val zoomOut: Flow<Float>
        get() = emptyFlow()
}
Loading