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

Commit fa0bf38a authored by Andreas Miko's avatar Andreas Miko Committed by Android (Google) Code Review
Browse files

Merge changes from topic "fix-kti" into main

* changes:
  [Scene container] Fix StatusBarKeyguardViewManagerInteractor
  Refactor internal functions to InternalKeyguardTransitionInteractor
  Fix KeyguardTransitionInteractorTest
  Consolidate isInTransitionWhere()
parents ef2629a5 27a87000
Loading
Loading
Loading
Loading
+49 −129
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.keyguard.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectValues
import com.android.systemui.flags.DisableSceneContainer
@@ -42,19 +41,15 @@ import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.Idle
import com.android.systemui.scene.data.repository.Transition
import com.android.systemui.scene.data.repository.sceneContainerRepository
import com.android.systemui.scene.data.repository.setSceneTransition
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@@ -67,36 +62,6 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
    val repository = kosmos.fakeKeyguardTransitionRepository
    val testScope = kosmos.testScope

    private val sceneTransitions =
        MutableStateFlow<ObservableTransitionState>(
            ObservableTransitionState.Idle(Scenes.Lockscreen)
        )

    private val lsToGone =
        ObservableTransitionState.Transition(
            Scenes.Lockscreen,
            Scenes.Gone,
            flowOf(Scenes.Lockscreen),
            flowOf(0f),
            false,
            flowOf(false)
        )

    private val goneToLs =
        ObservableTransitionState.Transition(
            Scenes.Gone,
            Scenes.Lockscreen,
            flowOf(Scenes.Lockscreen),
            flowOf(0f),
            false,
            flowOf(false)
        )

    @Before
    fun setUp() {
        kosmos.sceneContainerRepository.setTransitionState(sceneTransitions)
    }

    @Test
    fun transitionCollectorsReceivesOnlyAppropriateEvents() =
        testScope.runTest {
@@ -318,7 +283,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
    @Test
    fun isInTransitionToAnyState() =
        testScope.runTest {
            val inTransition by collectValues(underTest.isInTransitionToAnyState)
            val inTransition by collectValues(underTest.isInTransition)

            assertEquals(
                listOf(
@@ -373,10 +338,51 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            )
        }

    @Test
    @EnableSceneContainer
    fun isInTransition_withScene() =
        testScope.runTest {
            val inTransition by collectValues(underTest.isInTransition)

            assertEquals(
                listOf(
                    false,
                    true, // The repo is seeded with a transition from OFF to LOCKSCREEN.
                    false,
                ),
                inTransition
            )

            kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Bouncer))

            assertEquals(
                listOf(
                    false,
                    true,
                    false,
                    true,
                ),
                inTransition
            )

            kosmos.setSceneTransition(Idle(Scenes.Bouncer))

            assertEquals(
                listOf(
                    false,
                    true,
                    false,
                    true,
                    false,
                ),
                inTransition
            )
        }

    @Test
    fun isInTransitionToAnyState_finishedStateIsStartedStateAfterCancels() =
        testScope.runTest {
            val inTransition by collectValues(underTest.isInTransitionToAnyState)
            val inTransition by collectValues(underTest.isInTransition)

            assertEquals(
                listOf(
@@ -730,92 +736,6 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
                )
        }

    @Test
    fun isInTransitionFromStateWhere() =
        testScope.runTest {
            val results by collectValues(underTest.isInTransitionFromStateWhere { it == DOZING })

            sendSteps(
                TransitionStep(AOD, DOZING, 0f, STARTED),
                TransitionStep(AOD, DOZING, 0.5f, RUNNING),
                TransitionStep(AOD, DOZING, 1f, FINISHED),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                    )
                )

            sendSteps(
                TransitionStep(DOZING, GONE, 0f, STARTED),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                    )
                )

            sendSteps(
                TransitionStep(DOZING, GONE, 0f, RUNNING),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                    )
                )

            sendSteps(
                TransitionStep(DOZING, GONE, 0f, FINISHED),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                        false,
                    )
                )

            sendSteps(
                TransitionStep(GONE, DOZING, 0f, STARTED),
                TransitionStep(GONE, DOZING, 0f, RUNNING),
                TransitionStep(GONE, DOZING, 1f, FINISHED),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                        false,
                    )
                )

            sendSteps(
                TransitionStep(DOZING, GONE, 0f, STARTED),
                TransitionStep(DOZING, GONE, 0f, RUNNING),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                        false,
                        true,
                    )
                )
        }

    @Test
    fun isInTransitionWhere() =
        testScope.runTest {
@@ -1599,7 +1519,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            val currentStatesConverted by
                collectValues(underTest.transition(Edge.create(LOCKSCREEN, UNDEFINED)))

            sceneTransitions.value = lsToGone
            kosmos.setSceneTransition(Transition(Scenes.Lockscreen, Scenes.Gone))
            val sendStep1 = TransitionStep(LOCKSCREEN, UNDEFINED, 0f, STARTED)
            val sendStep2 = TransitionStep(LOCKSCREEN, UNDEFINED, 1f, FINISHED)
            val sendStep3 = TransitionStep(LOCKSCREEN, AOD, 0f, STARTED)
@@ -1615,7 +1535,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val currentStates by collectValues(underTest.transition(Edge.create(LOCKSCREEN, GONE)))

            sceneTransitions.value = goneToLs
            kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Lockscreen))
            val sendStep1 = TransitionStep(LOCKSCREEN, UNDEFINED, 0f, STARTED)
            val sendStep2 = TransitionStep(LOCKSCREEN, UNDEFINED, 1f, FINISHED)
            val sendStep3 = TransitionStep(LOCKSCREEN, AOD, 0f, STARTED)
@@ -1631,7 +1551,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            val currentStates by
                collectValues(underTest.transition(Edge.create(LOCKSCREEN, DOZING)))

            sceneTransitions.value = goneToLs
            kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Lockscreen))
            val sendStep1 = TransitionStep(LOCKSCREEN, DOZING, 0f, STARTED)
            val sendStep2 = TransitionStep(LOCKSCREEN, DOZING, 1f, FINISHED)
            val sendStep3 = TransitionStep(LOCKSCREEN, AOD, 0f, STARTED)
@@ -1648,7 +1568,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            val currentStatesReversed by
                collectValues(underTest.transition(Edge.create(null, LOCKSCREEN)))

            sceneTransitions.value = goneToLs
            kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Lockscreen))
            val sendStep1 = TransitionStep(LOCKSCREEN, DOZING, 0f, STARTED)
            val sendStep2 = TransitionStep(LOCKSCREEN, DOZING, 1f, FINISHED)
            val sendStep3 = TransitionStep(LOCKSCREEN, AOD, 0f, STARTED)
@@ -1666,7 +1586,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            val currentStates by collectValues(underTest.transition(Edge.create(null, UNDEFINED)))
            val currentStatesMapped by collectValues(underTest.transition(Edge.create(null, GONE)))

            sceneTransitions.value = lsToGone
            kosmos.setSceneTransition(Transition(Scenes.Lockscreen, Scenes.Gone))
            val sendStep1 = TransitionStep(LOCKSCREEN, UNDEFINED, 0f, STARTED)
            val sendStep2 = TransitionStep(LOCKSCREEN, UNDEFINED, 1f, FINISHED)
            val sendStep3 = TransitionStep(UNDEFINED, AOD, 0f, STARTED)
@@ -1683,7 +1603,7 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val currentStatesMapped by collectValues(underTest.transition(Edge.create(null, GONE)))

            sceneTransitions.value = goneToLs
            kosmos.setSceneTransition(Transition(Scenes.Gone, Scenes.Lockscreen))
            val sendStep1 = TransitionStep(LOCKSCREEN, UNDEFINED, 0f, STARTED)
            val sendStep2 = TransitionStep(LOCKSCREEN, UNDEFINED, 1f, FINISHED)
            val sendStep3 = TransitionStep(UNDEFINED, AOD, 0f, STARTED)
+8 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor
@@ -62,6 +63,13 @@ class SceneInteractorTest : SysuiTestCase() {

    private val underTest = kosmos.sceneInteractor

    init {
        // Init lazy Fixtures. Accessing them once makes sure that the singletons are initialized
        // and therefore starts to collect StateFlows eagerly (when there are any).
        kosmos.deviceUnlockedInteractor
        kosmos.keyguardEnabledInteractor
    }

    @Test
    fun allSceneKeys() {
        assertThat(underTest.allSceneKeys()).isEqualTo(kosmos.sceneKeys)
+1 −1
Original line number Diff line number Diff line
@@ -397,7 +397,7 @@ constructor(
            Pair(keyguardRepository.isKeyguardGoingAway.isFalse(), "keyguardNotGoingAway"),
            Pair(
                keyguardTransitionInteractor
                    .isInTransitionToStateWhere(KeyguardState::deviceIsAsleepInState)
                    .isInTransitionWhere(toStatePredicate = KeyguardState::deviceIsAsleepInState)
                    .isFalse(),
                "deviceNotTransitioningToAsleepState"
            ),
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ class FromAlternateBouncerTransitionInteractor
@Inject
constructor(
    override val transitionRepository: KeyguardTransitionRepository,
    override val internalTransitionInteractor: InternalKeyguardTransitionInteractor,
    transitionInteractor: KeyguardTransitionInteractor,
    @Background private val scope: CoroutineScope,
    @Background bgDispatcher: CoroutineDispatcher,
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ class FromAodTransitionInteractor
@Inject
constructor(
    override val transitionRepository: KeyguardTransitionRepository,
    override val internalTransitionInteractor: InternalKeyguardTransitionInteractor,
    transitionInteractor: KeyguardTransitionInteractor,
    @Background private val scope: CoroutineScope,
    @Background bgDispatcher: CoroutineDispatcher,
Loading