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

Commit 79387b99 authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

Shortcuts alpha should only react to shadeExpansion when on Lockscreen

Shade expansion was sending a 0f while going from GONE -> AOD

Then during AOD -> LOCKSCREEN, due to the shade expansion value, the
shortcuts were flickering one frame of 1f alpha.

The shortcuts should only be reacting to shade expansion on LOCKSCREEN

Fixes: 325329538
Test: KeyguardQuickAffordancesCombinedViewModelTest.kt
Flag: ACONFIG com.android.systemui.keyguard_bottom_area_refactor TEAMFOOD
Change-Id: I90c218346ff265352de02be955d62cf9a41404ed
parent 36a3df8f
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ package com.android.systemui.keyguard.ui.viewmodel
import androidx.annotation.VisibleForTesting
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.model.KeyguardQuickAffordanceModel
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition
import com.android.systemui.shade.domain.interactor.ShadeInteractor
@@ -57,6 +59,7 @@ constructor(
    lockscreenToGoneTransitionViewModel: LockscreenToGoneTransitionViewModel,
    lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel,
    lockscreenToPrimaryBouncerTransitionViewModel: LockscreenToPrimaryBouncerTransitionViewModel,
    transitionInteractor: KeyguardTransitionInteractor,
) {

    data class PreviewMode(
@@ -71,6 +74,24 @@ constructor(
     */
    private val previewMode = MutableStateFlow(PreviewMode())

    private val showingLockscreen: Flow<Boolean> =
        transitionInteractor.finishedKeyguardState.map { keyguardState ->
            keyguardState == KeyguardState.LOCKSCREEN
        }

    /** The only time the expansion is important is while lockscreen is actively displayed */
    private val shadeExpansionAlpha =
        combine(
            showingLockscreen,
            shadeInteractor.anyExpansion,
        ) { showingLockscreen, expansion ->
            if (showingLockscreen) {
                1 - expansion
            } else {
                0f
            }
        }

    /**
     * ID of the slot that's currently selected in the preview that renders exclusively in the
     * wallpaper picker application. This is ignored for the actual, real lock screen experience.
@@ -101,7 +122,7 @@ constructor(
            lockscreenToGoneTransitionViewModel.shortcutsAlpha,
            lockscreenToOccludedTransitionViewModel.shortcutsAlpha,
            lockscreenToPrimaryBouncerTransitionViewModel.shortcutsAlpha,
            shadeInteractor.qsExpansion.map { 1 - it },
            shadeExpansionAlpha,
        )

    /** The source of truth of alpha for all of the quick affordances on lockscreen */
+37 −2
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import com.android.systemui.keyguard.data.repository.KeyguardQuickAffordanceRepo
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractorFactory
import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.quickaffordance.ActivationState
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancePosition
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLogger
@@ -75,6 +77,7 @@ import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
import kotlin.test.assertEquals

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -130,6 +133,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() {
    @Mock
    private lateinit var lockscreenToPrimaryBouncerTransitionViewModel:
        LockscreenToPrimaryBouncerTransitionViewModel
    @Mock
    private lateinit var transitionInteractor: KeyguardTransitionInteractor

    private lateinit var underTest: KeyguardQuickAffordancesCombinedViewModel

@@ -146,6 +151,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() {
    // the viewModel does a `map { 1 - it }` on this value, which is why it's different
    private val intendedShadeAlphaMutableStateFlow: MutableStateFlow<Float> = MutableStateFlow(0f)

    private val intendedFinishedKeyguardStateFlow = MutableStateFlow(KeyguardState.LOCKSCREEN)

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
@@ -242,6 +249,7 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() {

        intendedAlphaMutableStateFlow.value = 1f
        intendedShadeAlphaMutableStateFlow.value = 0f
        intendedFinishedKeyguardStateFlow.value = KeyguardState.LOCKSCREEN
        whenever(aodToLockscreenTransitionViewModel.shortcutsAlpha)
            .thenReturn(intendedAlphaMutableStateFlow)
        whenever(dozingToLockscreenTransitionViewModel.shortcutsAlpha).thenReturn(emptyFlow())
@@ -263,7 +271,9 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() {
        whenever(lockscreenToOccludedTransitionViewModel.shortcutsAlpha).thenReturn(emptyFlow())
        whenever(lockscreenToPrimaryBouncerTransitionViewModel.shortcutsAlpha)
            .thenReturn(emptyFlow())
        whenever(shadeInteractor.qsExpansion).thenReturn(intendedShadeAlphaMutableStateFlow)
        whenever(shadeInteractor.anyExpansion).thenReturn(intendedShadeAlphaMutableStateFlow)
        whenever(transitionInteractor.finishedKeyguardState)
            .thenReturn(intendedFinishedKeyguardStateFlow)

        underTest =
            KeyguardQuickAffordancesCombinedViewModel(
@@ -304,7 +314,8 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() {
                lockscreenToGoneTransitionViewModel = lockscreenToGoneTransitionViewModel,
                lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel,
                lockscreenToPrimaryBouncerTransitionViewModel =
                    lockscreenToPrimaryBouncerTransitionViewModel
                    lockscreenToPrimaryBouncerTransitionViewModel,
                transitionInteractor = transitionInteractor,
            )
    }

@@ -682,6 +693,30 @@ class KeyguardQuickAffordancesCombinedViewModelTest : SysuiTestCase() {
            )
        }

    @Test
    fun shadeExpansionAlpha_changes_whenOnLockscreen() =
        testScope.runTest {
            intendedFinishedKeyguardStateFlow.value = KeyguardState.LOCKSCREEN
            intendedShadeAlphaMutableStateFlow.value = 0.25f
            val underTest = collectLastValue(underTest.transitionAlpha)
            assertEquals(0.75f, underTest())

            intendedShadeAlphaMutableStateFlow.value = 0.3f
            assertEquals(0.7f, underTest())
        }

    @Test
    fun shadeExpansionAlpha_alwaysZero_whenNotOnLockscreen() =
        testScope.runTest {
            intendedFinishedKeyguardStateFlow.value = KeyguardState.GONE
            intendedShadeAlphaMutableStateFlow.value = 0.5f
            val underTest = collectLastValue(underTest.transitionAlpha)
            assertEquals(0f, underTest())

            intendedShadeAlphaMutableStateFlow.value = 0.25f
            assertEquals(0f, underTest())
        }

    private suspend fun setUpQuickAffordanceModel(
        position: KeyguardQuickAffordancePosition,
        testConfig: TestConfig,