diff --git a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt index a02c5ce8bb14af32b16af1bcd3eae3ad357204b8..82d943796e2a8666c51e56b3cb10262a02a0b076 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt @@ -23,8 +23,6 @@ import com.android.systemui.communal.data.repository.CommunalRepositoryModule import com.android.systemui.communal.data.repository.CommunalSettingsRepositoryModule import com.android.systemui.communal.data.repository.CommunalTutorialRepositoryModule import com.android.systemui.communal.data.repository.CommunalWidgetRepositoryModule -import com.android.systemui.communal.ui.viewmodel.CommunalTransitionViewModel -import com.android.systemui.communal.ui.viewmodel.CommunalTransitionViewModelImpl import com.android.systemui.communal.widgets.CommunalWidgetModule import com.android.systemui.communal.widgets.EditWidgetsActivityStarter import com.android.systemui.communal.widgets.EditWidgetsActivityStarterImpl @@ -49,9 +47,4 @@ interface CommunalModule { fun bindEditWidgetsActivityStarter( starter: EditWidgetsActivityStarterImpl ): EditWidgetsActivityStarter - - @Binds - fun bindCommunalTransitionViewModel( - impl: CommunalTransitionViewModelImpl - ): CommunalTransitionViewModel } diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModel.kt deleted file mode 100644 index eed0aa397b65d14c49cdd9c94f857b21e7b05248..0000000000000000000000000000000000000000 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModel.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.communal.ui.viewmodel - -import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.keyguard.ui.viewmodel.DreamingToGlanceableHubTransitionViewModel -import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToDreamingTransitionViewModel -import com.android.systemui.keyguard.ui.viewmodel.GlanceableHubToLockscreenTransitionViewModel -import com.android.systemui.keyguard.ui.viewmodel.LockscreenToGlanceableHubTransitionViewModel -import javax.inject.Inject -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.merge - -/** View model for transitions related to the communal hub. */ -interface CommunalTransitionViewModel { - val isUmoOnCommunal: Flow<Boolean> -} - -@OptIn(ExperimentalCoroutinesApi::class) -@SysUISingleton -class CommunalTransitionViewModelImpl -@Inject -constructor( - glanceableHubToLockscreenTransitionViewModel: GlanceableHubToLockscreenTransitionViewModel, - lockscreenToGlanceableHubTransitionViewModel: LockscreenToGlanceableHubTransitionViewModel, - dreamToGlanceableHubTransitionViewModel: DreamingToGlanceableHubTransitionViewModel, - glanceableHubToDreamTransitionViewModel: GlanceableHubToDreamingTransitionViewModel, -) : CommunalTransitionViewModel { - /** - * Whether UMO location should be on communal. This flow is responsive to transitions so that a - * new value is emitted at the right step of a transition to/from communal hub that the location - * of UMO should be updated. - */ - override val isUmoOnCommunal: Flow<Boolean> = - merge( - lockscreenToGlanceableHubTransitionViewModel.showUmo, - glanceableHubToLockscreenTransitionViewModel.showUmo, - dreamToGlanceableHubTransitionViewModel.showUmo, - glanceableHubToDreamTransitionViewModel.showUmo, - ) - .distinctUntilChanged() -} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DreamingToGlanceableHubTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DreamingToGlanceableHubTransitionViewModel.kt index 5cb2ec9642b9c1c7bfc05ffc3dcc3d2bc8de6908..c64f277b519a4338497feef1ccfdc726ff38b8da 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DreamingToGlanceableHubTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DreamingToGlanceableHubTransitionViewModel.kt @@ -28,7 +28,6 @@ import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.map @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton @@ -66,15 +65,6 @@ constructor( name = "DREAMING->GLANCEABLE_HUB: dreamOverlayAlpha", ) - // Show UMO once the transition starts. - val showUmo: Flow<Boolean> = - transitionAnimation - .sharedFlow( - duration = TO_GLANCEABLE_HUB_DURATION, - onStep = { it }, - ) - .map { step -> step != 0f } - private companion object { val TO_GLANCEABLE_HUB_DURATION = 1.seconds } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToDreamingTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToDreamingTransitionViewModel.kt index 90be4f90410544249636a8a082c4c50e25599907..478c4faa1be303fd7fa1b09a1afc5c5d9cf17e3f 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToDreamingTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToDreamingTransitionViewModel.kt @@ -28,7 +28,6 @@ import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.map @OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton @@ -67,15 +66,6 @@ constructor( ) } - // Show UMO until transition finishes. - val showUmo: Flow<Boolean> = - transitionAnimation - .sharedFlow( - duration = FROM_GLANCEABLE_HUB_DURATION, - onStep = { it }, - ) - .map { step -> step != 1f } - private companion object { val FROM_GLANCEABLE_HUB_DURATION = 1.seconds } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToLockscreenTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToLockscreenTransitionViewModel.kt index f81598f717b07749a9744d8a51d0795096e52f89..e5b596419efe34cce2fb79c6bffff402df88bbc6 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToLockscreenTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/GlanceableHubToLockscreenTransitionViewModel.kt @@ -64,9 +64,6 @@ constructor( ) .onStart { emit(0f) } - // Show UMO as long as keyguard is not visible. - val showUmo: Flow<Boolean> = keyguardAlpha.map { alpha -> alpha == 0f } - val keyguardTranslationX: Flow<StateToValue> = configurationInteractor .dimensionPixelSize(R.dimen.hub_to_lockscreen_transition_lockscreen_translation_x) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToGlanceableHubTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToGlanceableHubTransitionViewModel.kt index 0c33e18d0113afd947c4ab267423f28c63ba35f8..978e71e2a825e759fac1931db2c9426645bae041 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToGlanceableHubTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToGlanceableHubTransitionViewModel.kt @@ -63,9 +63,6 @@ constructor( ) .onStart { emit(1f) } - // Show UMO as long as keyguard is not visible. - val showUmo: Flow<Boolean> = keyguardAlpha.map { alpha -> alpha == 0f } - val keyguardTranslationX: Flow<StateToValue> = configurationInteractor .dimensionPixelSize(R.dimen.lockscreen_to_hub_transition_lockscreen_translation_x) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManager.kt index a4f3e2174791f061096ce208536b6079cb731188..dbd71f3e3a041d4296333a28583558db37bcfa1e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManager.kt @@ -36,7 +36,7 @@ import androidx.annotation.VisibleForTesting import com.android.app.animation.Interpolators import com.android.app.tracing.traceSection import com.android.keyguard.KeyguardViewController -import com.android.systemui.communal.ui.viewmodel.CommunalTransitionViewModel +import com.android.systemui.communal.domain.interactor.CommunalInteractor import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Main @@ -58,6 +58,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.statusbar.policy.SplitShadeStateController import com.android.systemui.util.animation.UniqueObjectHostView +import com.android.systemui.util.kotlin.BooleanFlowOperators.and import com.android.systemui.util.settings.SecureSettings import javax.inject.Inject import kotlinx.coroutines.CoroutineScope @@ -101,7 +102,7 @@ constructor( private val mediaManager: MediaDataManager, private val keyguardViewController: KeyguardViewController, private val dreamOverlayStateController: DreamOverlayStateController, - communalTransitionViewModel: CommunalTransitionViewModel, + private val communalInteractor: CommunalInteractor, configurationController: ConfigurationController, wakefulnessLifecycle: WakefulnessLifecycle, shadeInteractor: ShadeInteractor, @@ -586,10 +587,11 @@ constructor( // Listen to the communal UI state. Make sure that communal UI is showing and hub itself is // available, ie. not disabled and able to be shown. coroutineScope.launch { - communalTransitionViewModel.isUmoOnCommunal.collect { value -> - isCommunalShowing = value - updateDesiredLocation(forceNoAnimation = true) - } + and(communalInteractor.isCommunalShowing, communalInteractor.isCommunalAvailable) + .collect { value -> + isCommunalShowing = value + updateDesiredLocation() + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManagerTest.kt index fa28036f274bdc36bbfb08bc6077c407d35e94ed..45f49f01a43ea8a0af0fd31f09a39a6019d292b1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManagerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/controller/MediaHierarchyManagerTest.kt @@ -24,8 +24,11 @@ import android.view.ViewGroup import android.widget.FrameLayout import androidx.test.filters.SmallTest import com.android.keyguard.KeyguardViewController +import com.android.systemui.Flags import com.android.systemui.SysuiTestCase -import com.android.systemui.communal.ui.viewmodel.fakeCommunalTransitionViewModel +import com.android.systemui.communal.domain.interactor.communalInteractor +import com.android.systemui.communal.domain.interactor.setCommunalAvailable +import com.android.systemui.communal.shared.model.CommunalSceneKey import com.android.systemui.controls.controller.ControlsControllerImplTest.Companion.eq import com.android.systemui.dreams.DreamOverlayStateController import com.android.systemui.keyguard.WakefulnessLifecycle @@ -112,10 +115,10 @@ class MediaHierarchyManagerTest : SysuiTestCase() { private lateinit var isQsBypassingShade: MutableStateFlow<Boolean> private lateinit var mediaFrame: ViewGroup private val configurationController = FakeConfigurationController() + private val communalInteractor = kosmos.communalInteractor private val settings = FakeSettings() private lateinit var testableLooper: TestableLooper private lateinit var fakeHandler: FakeHandler - private var communalTransitionViewModel = kosmos.fakeCommunalTransitionViewModel @Before fun setup() { @@ -139,7 +142,7 @@ class MediaHierarchyManagerTest : SysuiTestCase() { mediaDataManager, keyguardViewController, dreamOverlayStateController, - communalTransitionViewModel, + communalInteractor, configurationController, wakefulnessLifecycle, shadeInteractor, @@ -507,7 +510,11 @@ class MediaHierarchyManagerTest : SysuiTestCase() { @Test fun testCommunalLocation() = testScope.runTest { - communalTransitionViewModel.setIsUmoOnCommunal(true) + mSetFlagsRule.enableFlags(Flags.FLAG_COMMUNAL_HUB) + kosmos.setCommunalAvailable(true) + runCurrent() + + communalInteractor.onSceneChanged(CommunalSceneKey.Communal) runCurrent() verify(mediaCarouselController) .onDesiredLocationChanged( @@ -519,7 +526,7 @@ class MediaHierarchyManagerTest : SysuiTestCase() { ) clearInvocations(mediaCarouselController) - communalTransitionViewModel.setIsUmoOnCommunal(false) + communalInteractor.onSceneChanged(CommunalSceneKey.Blank) runCurrent() verify(mediaCarouselController) .onDesiredLocationChanged( @@ -534,11 +541,15 @@ class MediaHierarchyManagerTest : SysuiTestCase() { @Test fun testCommunalLocation_showsOverLockscreen() = testScope.runTest { + mSetFlagsRule.enableFlags(Flags.FLAG_COMMUNAL_HUB) + kosmos.setCommunalAvailable(true) + runCurrent() + // Device is on lock screen. whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) // UMO goes to communal even over the lock screen. - communalTransitionViewModel.setIsUmoOnCommunal(true) + communalInteractor.onSceneChanged(CommunalSceneKey.Communal) runCurrent() verify(mediaCarouselController) .onDesiredLocationChanged( @@ -553,10 +564,14 @@ class MediaHierarchyManagerTest : SysuiTestCase() { @Test fun testCommunalLocation_showsUntilQsExpands() = testScope.runTest { + mSetFlagsRule.enableFlags(Flags.FLAG_COMMUNAL_HUB) + kosmos.setCommunalAvailable(true) + runCurrent() + // Device is on lock screen. whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) - communalTransitionViewModel.setIsUmoOnCommunal(true) + communalInteractor.onSceneChanged(CommunalSceneKey.Communal) runCurrent() verify(mediaCarouselController) .onDesiredLocationChanged( diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelKosmos.kt deleted file mode 100644 index eaa657b76c3d5fb76c5c6de2082b37fdb4f8e65a..0000000000000000000000000000000000000000 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/CommunalTransitionViewModelKosmos.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.communal.ui.viewmodel - -import com.android.systemui.kosmos.Kosmos - -val Kosmos.communalTransitionViewModel by - Kosmos.Fixture<CommunalTransitionViewModel> { fakeCommunalTransitionViewModel } - -val Kosmos.fakeCommunalTransitionViewModel by Kosmos.Fixture { FakeCommunalTransitionViewModel() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/FakeCommunalTransitionViewModel.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/FakeCommunalTransitionViewModel.kt deleted file mode 100644 index 409cc1d03fda316fa36ffd3e44ba833d427d93aa..0000000000000000000000000000000000000000 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/ui/viewmodel/FakeCommunalTransitionViewModel.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.systemui.communal.ui.viewmodel - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow - -class FakeCommunalTransitionViewModel : CommunalTransitionViewModel { - private val _isUmoOnCommunal = MutableStateFlow(false) - override val isUmoOnCommunal: Flow<Boolean> = _isUmoOnCommunal - - fun setIsUmoOnCommunal(value: Boolean) { - _isUmoOnCommunal.value = value - } -}