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

Commit 701599f8 authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Fix clock scale changes on the first transition after keyguard root view is attached

Default value of BurnInModel will be emitted when keyguard root view is
attached, and will update until the transition in blueprint is
triggered, which causes the clock scale value change.

Bug: 421050099
Flag: com.android.systemui.shared.clock_reactive_smartspace_layout
Test: manual test transitions after folding/unfolding, e.g. go in and
out of AOD, have enhanced smartspace shown and disappeared

Change-Id: Ibeecc1651c0131d520e9b488ee21a59060e31778
parent 9bc5b6b4
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -64,10 +64,14 @@ class AodBurnInViewModelTest : SysuiTestCase() {
    private val testScope = kosmos.testScope
    private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository
    private val keyguardClockRepository = kosmos.fakeKeyguardClockRepository
    private lateinit var underTest: AodBurnInViewModel
    private val underTest: AodBurnInViewModel by lazy {
        kosmos.aodBurnInViewModel.apply { updateBurnInParams(burnInParameters) }
    }
    // assign a smaller value to minViewY to avoid overflow
    private var burnInParameters = BurnInParameters(minViewY = Int.MAX_VALUE / 2)
    private val burnInFlow = MutableStateFlow(BurnInModel())
    private val burnInFlow: MutableStateFlow<BurnInModel> by lazy {
        MutableStateFlow(BurnInModel())
    }

    @Before
    @DisableSceneContainer
@@ -84,12 +88,10 @@ class AodBurnInViewModelTest : SysuiTestCase() {
        kosmos.goneToAodTransitionViewModel = goneToAodTransitionViewModel
        kosmos.lockscreenToAodTransitionViewModel = lockscreenToAodTransitionViewModel
        kosmos.fakeKeyguardClockRepository.setCurrentClock(clockController)

        underTest = kosmos.aodBurnInViewModel
        underTest.updateBurnInParams(burnInParameters)
    }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun movement_initializedToDefaultValues() =
        testScope.runTest {
            val movement by collectLastValue(underTest.movement)
@@ -98,6 +100,16 @@ class AodBurnInViewModelTest : SysuiTestCase() {
            assertThat(movement?.scale).isEqualTo(1f)
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun movement_initializedToDefaultValues_reactiveSmartspace() =
        testScope.runTest {
            val movement by collectLastValue(underTest.movement)
            assertThat(movement?.translationY).isEqualTo(0)
            assertThat(movement?.translationX).isEqualTo(0)
            assertThat(movement?.scale).isEqualTo(0.9f)
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun translationAndScale_whenNotDozing_reactiveSmartspace() =
+9 −0
Original line number Diff line number Diff line
@@ -139,12 +139,21 @@ class KeyguardRootViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
    }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun defaultBurnInScaleEqualsOne() =
        testScope.runTest {
            val burnInScale by collectLastValue(underTest.scale)
            assertThat(burnInScale!!.scale).isEqualTo(1f)
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun defaultBurnInScaleEqualsMaxLargeClockScale() =
        testScope.runTest {
            val burnInScale by collectLastValue(underTest.scale)
            assertThat(burnInScale!!.scale).isEqualTo(0.9f)
        }

    @Test
    fun burnInLayerVisibility() =
        testScope.runTest {
+19 −2
Original line number Diff line number Diff line
@@ -16,10 +16,27 @@

package com.android.systemui.keyguard.shared.model

import com.android.systemui.shared.Flags

/** Clock burn-in translation/scaling data */
data class BurnInModel(
    val translationX: Int = 0,
    val translationY: Int = 0,
    val scale: Float = 1f,
    val scale: Float = MAX_LARGE_CLOCK_SCALE,
    val scaleClockOnly: Boolean = false,
)
) {
    companion object {
        /**
         * The maximum scale for the large clock.
         *
         * We use a custom getter here instead of static initialization to support test
         * environments. This ensures the value of the flag is read dynamically during each test
         * run, after test rules have had a chance to set the flag's state, preventing a
         * FlagSetException.
         */
        val MAX_LARGE_CLOCK_SCALE: Float
            get() {
                return if (Flags.clockReactiveSmartspaceLayout()) 0.9f else 1f
            }
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -26,12 +26,12 @@ import com.android.systemui.keyguard.domain.interactor.BurnInInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.BurnInModel
import com.android.systemui.keyguard.shared.model.BurnInModel.Companion.MAX_LARGE_CLOCK_SCALE
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.ui.StateToValue
import com.android.systemui.res.R
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.shared.Flags
import javax.inject.Inject
import kotlin.math.max
import kotlinx.coroutines.CoroutineScope
@@ -70,7 +70,6 @@ constructor(
) {
    private val TAG = "AodBurnInViewModel"
    private val burnInParams = MutableStateFlow(BurnInParameters())
    private val maxLargeClockScale = if (Flags.clockReactiveSmartspaceLayout()) 0.9f else 1f

    fun updateBurnInParams(params: BurnInParameters) {
        burnInParams.value =
@@ -196,7 +195,7 @@ constructor(
            BurnInModel(
                translationX = MathUtils.lerp(0, burnIn.translationX, interpolated).toInt(),
                translationY = translationY,
                scale = MathUtils.lerp(burnIn.scale, maxLargeClockScale, 1f - interpolated),
                scale = MathUtils.lerp(burnIn.scale, MAX_LARGE_CLOCK_SCALE, 1f - interpolated),
                scaleClockOnly = useScaleOnly,
            )
        }