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

Commit f96b7617 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Flexiglass] Fade Notifications during Lockscreen -> Dream transitions" into main

parents 687268b5 9e1e91a7
Loading
Loading
Loading
Loading
+39 −13
Original line number Diff line number Diff line
@@ -23,20 +23,26 @@ import com.android.systemui.biometrics.data.repository.FakeFingerprintPropertyRe
import com.android.systemui.biometrics.data.repository.fingerprintPropertyRepository
import com.android.systemui.biometrics.shared.model.FingerprintSensorType
import com.android.systemui.biometrics.shared.model.SensorStrength
import com.android.systemui.coroutines.collectValues
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.KeyguardState.UNDEFINED
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionState.RUNNING
import com.android.systemui.keyguard.shared.model.TransitionState.STARTED
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectValues
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.Transition
import com.android.systemui.scene.data.repository.setSceneTransition
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
import com.google.common.collect.Range
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.flow.flowOf
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -45,7 +51,6 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private lateinit var keyguardTransitionRepository: FakeKeyguardTransitionRepository
    private lateinit var fingerprintPropertyRepository: FakeFingerprintPropertyRepository
    private lateinit var underTest: DreamingToLockscreenTransitionViewModel
@@ -59,9 +64,10 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

    @Test
    fun shortcutsAlpha_bothShortcutsReceiveLastValue() =
        testScope.runTest {
        kosmos.runTest {
            val valuesLeft by collectValues(underTest.shortcutsAlpha)
            val valuesRight by collectValues(underTest.shortcutsAlpha)
            startDreamToLockscreenSceneTransition()

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -81,9 +87,10 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

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

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -104,8 +111,9 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

    @Test
    fun dreamOverlayFadeOut() =
        testScope.runTest {
        kosmos.runTest {
            val values by collectValues(underTest.dreamOverlayAlpha)
            startDreamToLockscreenSceneTransition()

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -126,8 +134,9 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

    @Test
    fun lockscreenFadeIn() =
        testScope.runTest {
        kosmos.runTest {
            val values by collectValues(underTest.lockscreenAlpha)
            startDreamToLockscreenSceneTransition()

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -147,8 +156,9 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

    @Test
    fun deviceEntryParentViewFadeIn() =
        testScope.runTest {
        kosmos.runTest {
            val values by collectValues(underTest.deviceEntryParentViewAlpha)
            startDreamToLockscreenSceneTransition()

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -168,7 +178,7 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

    @Test
    fun deviceEntryBackgroundViewAppear() =
        testScope.runTest {
        kosmos.runTest {
            fingerprintPropertyRepository.setProperties(
                sensorId = 0,
                strength = SensorStrength.STRONG,
@@ -176,6 +186,7 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {
                sensorLocations = emptyMap(),
            )
            val values by collectValues(underTest.deviceEntryBackgroundViewAlpha)
            startDreamToLockscreenSceneTransition()

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -191,11 +202,13 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {

            values.forEach { assertThat(it).isEqualTo(1f) }
        }

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

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
@@ -212,13 +225,26 @@ class DreamingToLockscreenTransitionViewModelTest : SysuiTestCase() {
            values.forEach { assertThat(it).isIn(Range.closed(-100f, 0f)) }
        }

    private fun Kosmos.startDreamToLockscreenSceneTransition() {
        if (SceneContainerFlag.isEnabled) {
            setSceneTransition(
                Transition(from = Scenes.Dream, to = Scenes.Lockscreen, progress = flowOf(0f))
            )
        }
    }

    private fun step(value: Float, state: TransitionState = RUNNING): TransitionStep {
        return TransitionStep(
            from = DREAMING,
            from =
                if (SceneContainerFlag.isEnabled) {
                    UNDEFINED
                } else {
                    DREAMING
                },
            to = LOCKSCREEN,
            value = value,
            transitionState = state,
            ownerName = "DreamingToLockscreenTransitionViewModelTest"
            ownerName = "DreamingToLockscreenTransitionViewModelTest",
        )
    }
}
+38 −1
Original line number Diff line number Diff line
@@ -34,11 +34,16 @@ 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.scene.data.repository.Transition
import com.android.systemui.scene.data.repository.setSceneTransition
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.statusbar.phone.ScrimState
import com.android.systemui.testKosmos
import com.google.common.collect.Range
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.flowOf
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -77,6 +82,8 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
    fun lockscreenFadeOut() =
        kosmos.runTest {
            val values by collectValues(underTest.lockscreenAlpha)

            startLockscreenToDreamSceneTransition()
            fakeKeyguardTransitionRepository.sendTransitionSteps(
                steps =
                    listOf(
@@ -101,6 +108,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
        kosmos.runTest {
            val values by collectValues(underTest.lockscreenAlpha)
            shadeExpanded(true)
            startShadeToDreamSceneTransition()

            fakeKeyguardTransitionRepository.sendTransitionSteps(
                steps =
@@ -123,6 +131,8 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
    fun shortcutsFadeOut() =
        kosmos.runTest {
            val values by collectValues(underTest.shortcutsAlpha)

            startLockscreenToDreamSceneTransition()
            fakeKeyguardTransitionRepository.sendTransitionSteps(
                steps =
                    listOf(
@@ -147,6 +157,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
        kosmos.runTest {
            val values by collectValues(underTest.shortcutsAlpha)
            shadeExpanded(true)
            startShadeToDreamSceneTransition()

            fakeKeyguardTransitionRepository.sendTransitionSteps(
                steps =
@@ -171,6 +182,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
            val pixels = 100
            val values by collectValues(underTest.lockscreenTranslationY(pixels))

            startLockscreenToDreamSceneTransition()
            fakeKeyguardTransitionRepository.sendTransitionSteps(
                steps =
                    listOf(
@@ -195,6 +207,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
        kosmos.runTest {
            val values by collectValues(underTest.deviceEntryParentViewAlpha)
            shadeExpanded(true)
            startShadeToDreamSceneTransition()

            fakeKeyguardTransitionRepository.sendTransitionSteps(
                steps =
@@ -218,6 +231,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
        kosmos.runTest {
            val actual by collectLastValue(underTest.deviceEntryParentViewAlpha)
            shadeExpanded(false)
            startLockscreenToDreamSceneTransition()

            // fade out
            fakeKeyguardTransitionRepository.sendTransitionStep(step(0f, TransitionState.STARTED))
@@ -231,6 +245,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
            assertThat(actual).isEqualTo(0f)

            fakeKeyguardTransitionRepository.sendTransitionStep(step(1f, TransitionState.FINISHED))

            assertThat(actual).isEqualTo(0f)
        }

@@ -239,6 +254,7 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
        kosmos.runTest {
            val value by collectLastValue(underTest.scrimAlpha)

            startLockscreenToDreamSceneTransition()
            for (step in listOf(0f, 0.2f, 0.5f, 0.8f, 1.0f)) {
                fakeKeyguardTransitionRepository.sendTransitionStep(step(step))
                assertThat(value?.behindAlpha)
@@ -246,13 +262,34 @@ class LockscreenToDreamingTransitionViewModelTest(flags: FlagsParameterization)
            }
        }

    private fun Kosmos.startShadeToDreamSceneTransition() {
        if (SceneContainerFlag.isEnabled) {
            setSceneTransition(
                Transition(from = Scenes.Shade, to = Scenes.Dream, progress = flowOf(0f))
            )
        }
    }

    private fun Kosmos.startLockscreenToDreamSceneTransition() {
        if (SceneContainerFlag.isEnabled) {
            setSceneTransition(
                Transition(from = Scenes.Lockscreen, to = Scenes.Dream, progress = flowOf(0f))
            )
        }
    }

    private fun step(
        value: Float,
        state: TransitionState = TransitionState.RUNNING,
    ): TransitionStep {
        return TransitionStep(
            from = KeyguardState.LOCKSCREEN,
            to = KeyguardState.DREAMING,
            to =
                if (SceneContainerFlag.isEnabled) {
                    KeyguardState.UNDEFINED
                } else {
                    KeyguardState.DREAMING
                },
            value = value,
            transitionState = state,
            ownerName = "LockscreenToDreamingTransitionViewModelTest",
+7 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition
import com.android.systemui.scene.shared.model.Scenes
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.flow.Flow
@@ -38,10 +39,12 @@ class DreamingToLockscreenTransitionViewModel
constructor(animationFlow: KeyguardTransitionAnimationFlow) : DeviceEntryIconTransition {

    private val transitionAnimation =
        animationFlow.setup(
        animationFlow
            .setup(
                duration = TO_LOCKSCREEN_DURATION,
            edge = Edge.create(from = DREAMING, to = LOCKSCREEN),
                edge = Edge.create(from = Scenes.Dream, to = LOCKSCREEN),
            )
            .setupWithoutSceneContainer(Edge.create(from = DREAMING, to = LOCKSCREEN))

    /** Dream overlay y-translation on exit */
    fun dreamOverlayTranslationY(translatePx: Int): Flow<Float> {
+7 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.ScrimAlpha
import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransition
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.phone.ScrimState
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
@@ -40,10 +41,12 @@ class LockscreenToDreamingTransitionViewModel
@Inject
constructor(animationFlow: KeyguardTransitionAnimationFlow) : DeviceEntryIconTransition {
    private val transitionAnimation =
        animationFlow.setup(
        animationFlow
            .setup(
                duration = TO_DREAMING_DURATION,
            edge = Edge.create(from = LOCKSCREEN, to = DREAMING),
                edge = Edge.create(from = LOCKSCREEN, to = Scenes.Dream),
            )
            .setupWithoutSceneContainer(Edge.create(from = LOCKSCREEN, to = DREAMING))

    /** Lockscreen views y-translation */
    fun lockscreenTranslationY(translatePx: Int): Flow<Float> {