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

Commit 7a4fbc01 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
Browse files

Merge "Fix UMO missing on glanceable hub" into main

parents 3db63dda 28389e86
Loading
Loading
Loading
Loading
+32 −25
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith


@@ -42,13 +41,11 @@ class CommunalTransitionViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val testScope = kosmos.testScope


    val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository
    private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository
    private val communalSceneRepository = kosmos.fakeCommunalSceneRepository


    private lateinit var underTest: CommunalTransitionViewModel
    private val underTest: CommunalTransitionViewModel by lazy {

        kosmos.communalTransitionViewModel
    @Before
    fun setup() {
        underTest = kosmos.communalTransitionViewModel
    }
    }


    @Test
    @Test
@@ -60,11 +57,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() {
            enterCommunal(from = KeyguardState.LOCKSCREEN)
            enterCommunal(from = KeyguardState.LOCKSCREEN)
            assertThat(isUmoOnCommunal).isTrue()
            assertThat(isUmoOnCommunal).isTrue()


            keyguardTransitionRepository.sendTransitionSteps(
            exitCommunal(to = KeyguardState.LOCKSCREEN)
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.LOCKSCREEN,
                testScope
            )
            assertThat(isUmoOnCommunal).isFalse()
            assertThat(isUmoOnCommunal).isFalse()
        }
        }


@@ -77,11 +70,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() {
            enterCommunal(from = KeyguardState.DREAMING)
            enterCommunal(from = KeyguardState.DREAMING)
            assertThat(isUmoOnCommunal).isTrue()
            assertThat(isUmoOnCommunal).isTrue()


            keyguardTransitionRepository.sendTransitionSteps(
            exitCommunal(to = KeyguardState.DREAMING)
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.DREAMING,
                testScope
            )
            assertThat(isUmoOnCommunal).isFalse()
            assertThat(isUmoOnCommunal).isFalse()
        }
        }


@@ -94,11 +83,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() {
            enterCommunal(from = KeyguardState.OCCLUDED)
            enterCommunal(from = KeyguardState.OCCLUDED)
            assertThat(isUmoOnCommunal).isTrue()
            assertThat(isUmoOnCommunal).isTrue()


            keyguardTransitionRepository.sendTransitionSteps(
            exitCommunal(to = KeyguardState.OCCLUDED)
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.OCCLUDED,
                testScope
            )
            assertThat(isUmoOnCommunal).isFalse()
            assertThat(isUmoOnCommunal).isFalse()
        }
        }


@@ -112,20 +97,42 @@ class CommunalTransitionViewModelTest : SysuiTestCase() {
            assertThat(isUmoOnCommunal).isTrue()
            assertThat(isUmoOnCommunal).isTrue()


            // Communal is no longer visible.
            // Communal is no longer visible.
            kosmos.fakeCommunalSceneRepository.changeScene(CommunalScenes.Blank)
            communalSceneRepository.changeScene(CommunalScenes.Blank)
            runCurrent()


            // isUmoOnCommunal returns false, even without any keyguard transition.
            // isUmoOnCommunal returns false, even without any keyguard transition.
            assertThat(isUmoOnCommunal).isFalse()
            assertThat(isUmoOnCommunal).isFalse()
        }
        }


    @Test
    fun isUmoOnCommunal_idleOnCommunal_returnsTrue() =
        testScope.runTest {
            val isUmoOnCommunal by collectLastValue(underTest.isUmoOnCommunal)
            assertThat(isUmoOnCommunal).isFalse()

            // Communal is fully visible.
            communalSceneRepository.changeScene(CommunalScenes.Communal)

            // isUmoOnCommunal returns true, even without any keyguard transition.
            assertThat(isUmoOnCommunal).isTrue()
        }

    private suspend fun TestScope.enterCommunal(from: KeyguardState) {
    private suspend fun TestScope.enterCommunal(from: KeyguardState) {
        keyguardTransitionRepository.sendTransitionSteps(
        keyguardTransitionRepository.sendTransitionSteps(
            from = from,
            from = from,
            to = KeyguardState.GLANCEABLE_HUB,
            to = KeyguardState.GLANCEABLE_HUB,
            testScope
            testScope
        )
        )
        kosmos.fakeCommunalSceneRepository.changeScene(CommunalScenes.Communal)
        communalSceneRepository.changeScene(CommunalScenes.Communal)
        runCurrent()
    }

    private suspend fun TestScope.exitCommunal(to: KeyguardState) {
        keyguardTransitionRepository.sendTransitionSteps(
            from = KeyguardState.GLANCEABLE_HUB,
            to = to,
            testScope
        )
        communalSceneRepository.changeScene(CommunalScenes.Blank)
        runCurrent()
        runCurrent()
    }
    }
}
}
+32 −14
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.util.CommunalColors
import com.android.systemui.communal.util.CommunalColors
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState
@@ -31,13 +32,18 @@ import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTrans
import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf
import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf
import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn


/** View model for transitions related to the communal hub. */
/** View model for transitions related to the communal hub. */
@OptIn(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
@@ -45,6 +51,7 @@ import kotlinx.coroutines.flow.merge
class CommunalTransitionViewModel
class CommunalTransitionViewModel
@Inject
@Inject
constructor(
constructor(
    @Application applicationScope: CoroutineScope,
    communalColors: CommunalColors,
    communalColors: CommunalColors,
    glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel,
    glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel,
    lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel,
    lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel,
@@ -85,10 +92,14 @@ constructor(
     * of UMO should be updated.
     * of UMO should be updated.
     */
     */
    val isUmoOnCommunal: Flow<Boolean> =
    val isUmoOnCommunal: Flow<Boolean> =
        anyOf(
                communalSceneInteractor.isIdleOnCommunal,
                allOf(
                allOf(
            // Only show UMO on the hub if the hub is at least partially visible. This prevents
                    // Only show UMO on the hub if the hub is at least partially visible. This
                    // prevents
                    // the UMO from being missing on the lock screen when going from the hub to lock
                    // the UMO from being missing on the lock screen when going from the hub to lock
            // screen in some way other than through a direct transition, such as unlocking from
                    // screen in some way other than through a direct transition, such as unlocking
                    // from
                    // the hub, then pressing power twice to go back to the lock screen.
                    // the hub, then pressing power twice to go back to the lock screen.
                    communalSceneInteractor.isCommunalVisible,
                    communalSceneInteractor.isCommunalVisible,
                    merge(
                    merge(
@@ -99,6 +110,13 @@ constructor(
                            showUmoFromOccludedToGlanceableHub,
                            showUmoFromOccludedToGlanceableHub,
                            showUmoFromGlanceableHubToOccluded,
                            showUmoFromGlanceableHubToOccluded,
                        )
                        )
                        .onStart { emit(false) }
                )
            )
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.WhileSubscribed(),
                initialValue = false
            )
            )


    /** Whether to show communal when exiting the occluded state. */
    /** Whether to show communal when exiting the occluded state. */
+2 −0
Original line number Original line Diff line number Diff line
@@ -25,12 +25,14 @@ import com.android.systemui.keyguard.ui.viewmodel.glanceableHubToDreamingTransit
import com.android.systemui.keyguard.ui.viewmodel.glanceableHubToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.glanceableHubToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.lockscreenToGlanceableHubTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.lockscreenToGlanceableHubTransitionViewModel
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi


@OptIn(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
val Kosmos.communalTransitionViewModel by
val Kosmos.communalTransitionViewModel by
    Kosmos.Fixture {
    Kosmos.Fixture {
        CommunalTransitionViewModel(
        CommunalTransitionViewModel(
            applicationScope = applicationCoroutineScope,
            glanceableHubToLockscreenTransitionViewModel =
            glanceableHubToLockscreenTransitionViewModel =
                glanceableHubToLockscreenTransitionViewModel,
                glanceableHubToLockscreenTransitionViewModel,
            lockscreenToGlanceableHubTransitionViewModel =
            lockscreenToGlanceableHubTransitionViewModel =