Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelTest.kt +32 −25 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -42,13 +41,11 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository private val communalSceneRepository = kosmos.fakeCommunalSceneRepository private lateinit var underTest: CommunalTransitionViewModel @Before fun setup() { underTest = kosmos.communalTransitionViewModel private val underTest: CommunalTransitionViewModel by lazy { kosmos.communalTransitionViewModel } @Test Loading @@ -60,11 +57,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { enterCommunal(from = KeyguardState.LOCKSCREEN) assertThat(isUmoOnCommunal).isTrue() keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.GLANCEABLE_HUB, to = KeyguardState.LOCKSCREEN, testScope ) exitCommunal(to = KeyguardState.LOCKSCREEN) assertThat(isUmoOnCommunal).isFalse() } Loading @@ -77,11 +70,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { enterCommunal(from = KeyguardState.DREAMING) assertThat(isUmoOnCommunal).isTrue() keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.GLANCEABLE_HUB, to = KeyguardState.DREAMING, testScope ) exitCommunal(to = KeyguardState.DREAMING) assertThat(isUmoOnCommunal).isFalse() } Loading @@ -94,11 +83,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { enterCommunal(from = KeyguardState.OCCLUDED) assertThat(isUmoOnCommunal).isTrue() keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.GLANCEABLE_HUB, to = KeyguardState.OCCLUDED, testScope ) exitCommunal(to = KeyguardState.OCCLUDED) assertThat(isUmoOnCommunal).isFalse() } Loading @@ -112,20 +97,42 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { assertThat(isUmoOnCommunal).isTrue() // Communal is no longer visible. kosmos.fakeCommunalSceneRepository.changeScene(CommunalScenes.Blank) runCurrent() communalSceneRepository.changeScene(CommunalScenes.Blank) // isUmoOnCommunal returns false, even without any keyguard transition. 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) { keyguardTransitionRepository.sendTransitionSteps( from = from, to = KeyguardState.GLANCEABLE_HUB, 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() } } packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModel.kt +32 −14 Original line number Diff line number Diff line Loading @@ -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.util.CommunalColors 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.shared.model.Edge import com.android.systemui.keyguard.shared.model.KeyguardState Loading @@ -31,13 +32,18 @@ import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTrans import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn /** View model for transitions related to the communal hub. */ @OptIn(ExperimentalCoroutinesApi::class) Loading @@ -45,6 +51,7 @@ import kotlinx.coroutines.flow.merge class CommunalTransitionViewModel @Inject constructor( @Application applicationScope: CoroutineScope, communalColors: CommunalColors, glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel, lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel, Loading Loading @@ -85,10 +92,14 @@ constructor( * of UMO should be updated. */ val isUmoOnCommunal: Flow<Boolean> = anyOf( communalSceneInteractor.isIdleOnCommunal, 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 // 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. communalSceneInteractor.isCommunalVisible, merge( Loading @@ -99,6 +110,13 @@ constructor( showUmoFromOccludedToGlanceableHub, showUmoFromGlanceableHubToOccluded, ) .onStart { emit(false) } ) ) .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = false ) /** Whether to show communal when exiting the occluded state. */ Loading packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelKosmos.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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.lockscreenToGlanceableHubTransitionViewModel import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.applicationCoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi @OptIn(ExperimentalCoroutinesApi::class) val Kosmos.communalTransitionViewModel by Kosmos.Fixture { CommunalTransitionViewModel( applicationScope = applicationCoroutineScope, glanceableHubToLockscreenTransitionViewModel = glanceableHubToLockscreenTransitionViewModel, lockscreenToGlanceableHubTransitionViewModel = Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelTest.kt +32 −25 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -42,13 +41,11 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository private val communalSceneRepository = kosmos.fakeCommunalSceneRepository private lateinit var underTest: CommunalTransitionViewModel @Before fun setup() { underTest = kosmos.communalTransitionViewModel private val underTest: CommunalTransitionViewModel by lazy { kosmos.communalTransitionViewModel } @Test Loading @@ -60,11 +57,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { enterCommunal(from = KeyguardState.LOCKSCREEN) assertThat(isUmoOnCommunal).isTrue() keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.GLANCEABLE_HUB, to = KeyguardState.LOCKSCREEN, testScope ) exitCommunal(to = KeyguardState.LOCKSCREEN) assertThat(isUmoOnCommunal).isFalse() } Loading @@ -77,11 +70,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { enterCommunal(from = KeyguardState.DREAMING) assertThat(isUmoOnCommunal).isTrue() keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.GLANCEABLE_HUB, to = KeyguardState.DREAMING, testScope ) exitCommunal(to = KeyguardState.DREAMING) assertThat(isUmoOnCommunal).isFalse() } Loading @@ -94,11 +83,7 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { enterCommunal(from = KeyguardState.OCCLUDED) assertThat(isUmoOnCommunal).isTrue() keyguardTransitionRepository.sendTransitionSteps( from = KeyguardState.GLANCEABLE_HUB, to = KeyguardState.OCCLUDED, testScope ) exitCommunal(to = KeyguardState.OCCLUDED) assertThat(isUmoOnCommunal).isFalse() } Loading @@ -112,20 +97,42 @@ class CommunalTransitionViewModelTest : SysuiTestCase() { assertThat(isUmoOnCommunal).isTrue() // Communal is no longer visible. kosmos.fakeCommunalSceneRepository.changeScene(CommunalScenes.Blank) runCurrent() communalSceneRepository.changeScene(CommunalScenes.Blank) // isUmoOnCommunal returns false, even without any keyguard transition. 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) { keyguardTransitionRepository.sendTransitionSteps( from = from, to = KeyguardState.GLANCEABLE_HUB, 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() } }
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModel.kt +32 −14 Original line number Diff line number Diff line Loading @@ -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.util.CommunalColors 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.shared.model.Edge import com.android.systemui.keyguard.shared.model.KeyguardState Loading @@ -31,13 +32,18 @@ import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTrans import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn /** View model for transitions related to the communal hub. */ @OptIn(ExperimentalCoroutinesApi::class) Loading @@ -45,6 +51,7 @@ import kotlinx.coroutines.flow.merge class CommunalTransitionViewModel @Inject constructor( @Application applicationScope: CoroutineScope, communalColors: CommunalColors, glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel, lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel, Loading Loading @@ -85,10 +92,14 @@ constructor( * of UMO should be updated. */ val isUmoOnCommunal: Flow<Boolean> = anyOf( communalSceneInteractor.isIdleOnCommunal, 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 // 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. communalSceneInteractor.isCommunalVisible, merge( Loading @@ -99,6 +110,13 @@ constructor( showUmoFromOccludedToGlanceableHub, showUmoFromGlanceableHubToOccluded, ) .onStart { emit(false) } ) ) .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = false ) /** Whether to show communal when exiting the occluded state. */ Loading
packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelKosmos.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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.lockscreenToGlanceableHubTransitionViewModel import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.applicationCoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi @OptIn(ExperimentalCoroutinesApi::class) val Kosmos.communalTransitionViewModel by Kosmos.Fixture { CommunalTransitionViewModel( applicationScope = applicationCoroutineScope, glanceableHubToLockscreenTransitionViewModel = glanceableHubToLockscreenTransitionViewModel, lockscreenToGlanceableHubTransitionViewModel = Loading