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

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

Merge "Prevent flicker on PRIMARY_BOUNCER->LOCKSCREEN when dragging" into main

parents 71480392 94c59ea4
Loading
Loading
Loading
Loading
+54 −15
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.keyguardOcclusionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.StatusBarState.KEYGUARD
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat as assertThatRepository
@@ -81,7 +82,7 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {

            assertThat(values)
                .containsExactly(
                    null, // LOCKSCREEN -> AOD does not have any specific surface visibility.
                    null // LOCKSCREEN -> AOD does not have any specific surface visibility.
                )

            transitionRepository.sendTransitionStep(
@@ -117,6 +118,53 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
                .inOrder()
        }

    @Test
    fun draggingToPrimaryBouncerUpdateIsSent() =
        testScope.runTest {
            underTest.start()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.OFF,
                to = KeyguardState.LOCKSCREEN,
                testScope,
            )

            val steps by collectValues(transitionRepository.transitions)

            shadeRepository.setLegacyShadeExpansion(0f)
            shadeRepository.setLegacyShadeTracking(true)
            keyguardRepository.setKeyguardDismissible(false)
            keyguardRepository.setStatusBarState(KEYGUARD)
            runCurrent()

            // User starts dragging up
            shadeRepository.setLegacyShadeExpansion(0.1f)
            runCurrent()

            assertThatRepository(transitionRepository)
                .startedTransition(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.PRIMARY_BOUNCER,
                )

            // FakeKeyguardRepository doesn't send the step, so do that
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    transitionState = TransitionState.STARTED,
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.PRIMARY_BOUNCER,
                    value = 0f,
                )
            )
            runCurrent()

            // Update is sent
            shadeRepository.setLegacyShadeExpansion(0.2f)
            runCurrent()

            assertThatRepository(transitionRepository)
                .updatedTransition(value = 1f, state = TransitionState.RUNNING)
        }

    @Test
    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionsToGone_whenDismissFlingWhileDismissable_flagEnabled() =
@@ -132,10 +180,7 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
            runCurrent()

            assertThatRepository(transitionRepository)
                .startedTransition(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                )
                .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.GONE)
        }

    @Test
@@ -184,15 +229,12 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
                true,
                ActivityManager.RunningTaskInfo().apply {
                    topActivityType = WindowConfiguration.ACTIVITY_TYPE_STANDARD
                }
                },
            )
            runCurrent()

            assertThatRepository(transitionRepository)
                .startedTransition(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.OCCLUDED,
                )
                .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.OCCLUDED)
        }

    @Test
@@ -207,14 +249,11 @@ class FromLockscreenTransitionInteractorTest : SysuiTestCase() {
                true,
                ActivityManager.RunningTaskInfo().apply {
                    topActivityType = WindowConfiguration.ACTIVITY_TYPE_DREAM
                }
                },
            )
            runCurrent()

            assertThatRepository(transitionRepository)
                .startedTransition(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.DREAMING,
                )
                .startedTransition(from = KeyguardState.LOCKSCREEN, to = KeyguardState.DREAMING)
        }
}
+14 −8
Original line number Diff line number Diff line
@@ -210,13 +210,18 @@ constructor(
                                } else {
                                    TransitionState.RUNNING
                                }

                            // startTransition below will issue the CANCELED directly
                            if (nextState != TransitionState.CANCELED) {
                                transitionRepository.updateTransition(
                                    id,
                                    // This maps the shadeExpansion to a much faster curve, to match
                                    // the existing logic
                                1f - MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, shadeExpansion),
                                    1f -
                                        MathUtils.constrainedMap(0f, 1f, 0.95f, 1f, shadeExpansion),
                                    nextState,
                                )
                            }

                            if (
                                nextState == TransitionState.CANCELED ||
@@ -234,11 +239,12 @@ constructor(
                                        ownerName = name,
                                        from = KeyguardState.PRIMARY_BOUNCER,
                                        to = KeyguardState.LOCKSCREEN,
                                        modeOnCanceled = TransitionModeOnCanceled.REVERSE,
                                        animator =
                                            getDefaultAnimatorForTransitionsToState(
                                                    KeyguardState.LOCKSCREEN
                                                )
                                                .apply { duration = 0 },
                                                .apply { duration = 100L },
                                    )
                                )
                            }
+18 −1
Original line number Diff line number Diff line
@@ -21,17 +21,20 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled
import com.android.systemui.util.mockito.any
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.FailureMetadata
import com.google.common.truth.Subject
import com.google.common.truth.Truth
import com.google.common.truth.Truth.assertAbout
import com.google.common.truth.Truth.assertThat
import junit.framework.Assert.assertEquals
import org.junit.Assert.fail
import org.mockito.Mockito
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor

/** [Subject] used to make assertions about a [Mockito.spy] KeyguardTransitionRepository. */
class KeyguardTransitionRepositorySpySubject
@@ -89,6 +92,20 @@ private constructor(
            }
    }

    /**
     * Asserts that we started a transition to the given state, optionally verifying additional
     * params.
     */
    suspend fun updatedTransition(value: Float, state: TransitionState) {
        val valueCaptor = argumentCaptor<Float>()
        val stateCaptor = argumentCaptor<TransitionState>()

        verify(repository).updateTransition(any(), valueCaptor.capture(), stateCaptor.capture())

        assertThat(value).isEqualTo(valueCaptor.firstValue)
        assertThat(state).isEqualTo(stateCaptor.firstValue)
    }

    /** Verifies that [KeyguardTransitionRepository.startTransition] was never called. */
    suspend fun noTransitionsStarted() {
        verify(repository, never()).startTransition(any())