diff options
9 files changed, 117 insertions, 46 deletions
| diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt index a8fe16b12e1b..d86b35d3b95a 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt @@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4  import androidx.test.filters.SmallTest  import com.android.systemui.SysuiTestCase  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.coroutines.collectLastValue  import com.android.systemui.dock.DockManager @@ -33,6 +34,7 @@ import com.android.systemui.kosmos.testScope  import com.android.systemui.testKosmos  import com.google.common.truth.Truth.assertThat  import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.launch  import kotlinx.coroutines.test.TestScope  import kotlinx.coroutines.test.advanceTimeBy  import kotlinx.coroutines.test.runCurrent @@ -50,7 +52,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {      private lateinit var underTest: CommunalSceneStartable      @Before -    fun setUp() = +    fun setUp() {          with(kosmos) {              underTest =                  CommunalSceneStartable( @@ -61,7 +63,15 @@ class CommunalSceneStartableTest : SysuiTestCase() {                          bgScope = applicationCoroutineScope,                      )                      .apply { start() } + +            // Make communal available so that communalInteractor.desiredScene accurately reflects +            // scene changes instead of just returning Blank. +            with(kosmos.testScope) { +                launch { setCommunalAvailable(true) } +                testScheduler.runCurrent() +            }          } +    }      @Test      fun keyguardGoesAway_forceBlankScene() = @@ -249,4 +259,10 @@ class CommunalSceneStartableTest : SysuiTestCase() {              fakeDockManager.setDockEvent(DockManager.STATE_DOCKED)              runCurrent()          } + +    private suspend fun TestScope.enableCommunal() = +        with(kosmos) { +            setCommunalAvailable(true) +            runCurrent() +        }  } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt index 4156d833b0de..e007344e5578 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt @@ -455,6 +455,9 @@ class CommunalInteractorTest : SysuiTestCase() {      @Test      fun listensToSceneChange() =          testScope.runTest { +            kosmos.setCommunalAvailable(true) +            runCurrent() +              var desiredScene = collectLastValue(underTest.desiredScene)              runCurrent()              assertThat(desiredScene()).isEqualTo(CommunalSceneKey.Blank) @@ -479,6 +482,30 @@ class CommunalInteractorTest : SysuiTestCase() {          }      @Test +    fun desiredScene_communalNotAvailable_returnsBlank() = +        testScope.runTest { +            kosmos.setCommunalAvailable(true) +            runCurrent() + +            val desiredScene by collectLastValue(underTest.desiredScene) + +            underTest.onSceneChanged(CommunalSceneKey.Communal) +            assertThat(desiredScene).isEqualTo(CommunalSceneKey.Communal) + +            kosmos.setCommunalAvailable(false) +            runCurrent() + +            // Scene returns blank when communal is not available. +            assertThat(desiredScene).isEqualTo(CommunalSceneKey.Blank) + +            kosmos.setCommunalAvailable(true) +            runCurrent() + +            // After re-enabling, scene goes back to Communal. +            assertThat(desiredScene).isEqualTo(CommunalSceneKey.Communal) +        } + +    @Test      fun transitionProgress_onTargetScene_fullProgress() =          testScope.runTest {              val targetScene = CommunalSceneKey.Blank @@ -604,8 +631,28 @@ class CommunalInteractorTest : SysuiTestCase() {          }      @Test +    fun isCommunalShowing() = +        testScope.runTest { +            kosmos.setCommunalAvailable(true) +            runCurrent() + +            var isCommunalShowing = collectLastValue(underTest.isCommunalShowing) +            runCurrent() +            assertThat(isCommunalShowing()).isEqualTo(false) + +            underTest.onSceneChanged(CommunalSceneKey.Communal) + +            isCommunalShowing = collectLastValue(underTest.isCommunalShowing) +            runCurrent() +            assertThat(isCommunalShowing()).isEqualTo(true) +        } + +    @Test      fun isCommunalShowing_whenSceneContainerDisabled() =          testScope.runTest { +            kosmos.setCommunalAvailable(true) +            runCurrent() +              // Verify default is false              val isCommunalShowing by collectLastValue(underTest.isCommunalShowing)              runCurrent() diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt index 5211c55ac911..8b785927ba5e 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt @@ -16,7 +16,6 @@  package com.android.systemui.communal.domain.interactor -import android.content.pm.UserInfo  import android.provider.Settings.Secure.HUB_MODE_TUTORIAL_COMPLETED  import android.provider.Settings.Secure.HUB_MODE_TUTORIAL_NOT_STARTED  import android.provider.Settings.Secure.HUB_MODE_TUTORIAL_STARTED @@ -61,7 +60,6 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          communalInteractor = kosmos.communalInteractor          userRepository = kosmos.fakeUserRepository -        userRepository.setUserInfos(listOf(MAIN_USER_INFO))          kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true)          mSetFlagsRule.enableFlags(FLAG_COMMUNAL_HUB) @@ -72,7 +70,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {      fun tutorialUnavailable_whenKeyguardNotVisible() =          testScope.runTest {              val isTutorialAvailable by collectLastValue(underTest.isTutorialAvailable) -            setCommunalAvailable(true) +            kosmos.setCommunalAvailable(true)              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)              keyguardRepository.setKeyguardShowing(false)              assertThat(isTutorialAvailable).isFalse() @@ -82,10 +80,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {      fun tutorialUnavailable_whenTutorialIsCompleted() =          testScope.runTest {              val isTutorialAvailable by collectLastValue(underTest.isTutorialAvailable) -            setCommunalAvailable(true) -            keyguardRepository.setKeyguardShowing(true) -            keyguardRepository.setKeyguardOccluded(false) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED)              assertThat(isTutorialAvailable).isFalse()          } @@ -94,7 +89,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {      fun tutorialUnavailable_whenCommunalNotAvailable() =          testScope.runTest {              val isTutorialAvailable by collectLastValue(underTest.isTutorialAvailable) -            setCommunalAvailable(false) +            kosmos.setCommunalAvailable(false)              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)              keyguardRepository.setKeyguardShowing(true)              assertThat(isTutorialAvailable).isFalse() @@ -104,10 +99,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {      fun tutorialAvailable_whenTutorialNotStarted() =          testScope.runTest {              val isTutorialAvailable by collectLastValue(underTest.isTutorialAvailable) -            setCommunalAvailable(true) -            keyguardRepository.setKeyguardShowing(true) -            keyguardRepository.setKeyguardOccluded(false) -            communalInteractor.onSceneChanged(CommunalSceneKey.Blank) +            kosmos.setCommunalAvailable(true)              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)              assertThat(isTutorialAvailable).isTrue()          } @@ -116,10 +108,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {      fun tutorialAvailable_whenTutorialIsStarted() =          testScope.runTest {              val isTutorialAvailable by collectLastValue(underTest.isTutorialAvailable) -            setCommunalAvailable(true) -            keyguardRepository.setKeyguardShowing(true) -            keyguardRepository.setKeyguardOccluded(false) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED)              assertThat(isTutorialAvailable).isTrue()          } @@ -129,10 +118,9 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          testScope.runTest {              val tutorialSettingState by                  collectLastValue(communalTutorialRepository.tutorialSettingState) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO)              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_STARTED)          } @@ -142,10 +130,10 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          testScope.runTest {              val tutorialSettingState by                  collectLastValue(communalTutorialRepository.tutorialSettingState) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO) +              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_STARTED)          } @@ -155,10 +143,9 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          testScope.runTest {              val tutorialSettingState by                  collectLastValue(communalTutorialRepository.tutorialSettingState) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO)              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)          } @@ -168,7 +155,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          testScope.runTest {              val tutorialSettingState by                  collectLastValue(communalTutorialRepository.tutorialSettingState) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO) +            kosmos.setCommunalAvailable(true)              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)              communalInteractor.onSceneChanged(CommunalSceneKey.Blank) @@ -181,8 +168,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          testScope.runTest {              val tutorialSettingState by                  collectLastValue(communalTutorialRepository.tutorialSettingState) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED)              communalInteractor.onSceneChanged(CommunalSceneKey.Blank) @@ -195,8 +181,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {          testScope.runTest {              val tutorialSettingState by                  collectLastValue(communalTutorialRepository.tutorialSettingState) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO) -            communalInteractor.onSceneChanged(CommunalSceneKey.Communal) +            goToCommunal()              communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED)              communalInteractor.onSceneChanged(CommunalSceneKey.Blank) @@ -204,17 +189,8 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {              assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)          } -    private suspend fun setCommunalAvailable(available: Boolean) { -        if (available) { -            keyguardRepository.setIsEncryptedOrLockdown(false) -            userRepository.setSelectedUserInfo(MAIN_USER_INFO) -            keyguardRepository.setKeyguardShowing(true) -        } else { -            keyguardRepository.setIsEncryptedOrLockdown(true) -        } -    } - -    private companion object { -        val MAIN_USER_INFO = UserInfo(0, "primary", UserInfo.FLAG_MAIN) +    private suspend fun goToCommunal() { +        kosmos.setCommunalAvailable(true) +        communalInteractor.onSceneChanged(CommunalSceneKey.Communal)      }  } diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt index d0044a4c029e..e52897c28ac7 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt @@ -125,8 +125,13 @@ constructor(      /**       * Target scene as requested by the underlying [SceneTransitionLayout] or through       * [onSceneChanged]. +     * +     * If [isCommunalAvailable] is false, will return [CommunalSceneKey.Blank]       */ -    val desiredScene: StateFlow<CommunalSceneKey> = communalRepository.desiredScene +    val desiredScene: Flow<CommunalSceneKey> = +        communalRepository.desiredScene.combine(isCommunalAvailable) { scene, available -> +            if (available) scene else CommunalSceneKey.Blank +        }      /** Transition state of the hub mode. */      val transitionState: StateFlow<ObservableCommunalTransitionState> = diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt index 8a7b5ebedb7a..3ec9a268f80c 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt @@ -34,7 +34,7 @@ abstract class BaseCommunalViewModel(      private val communalInteractor: CommunalInteractor,      val mediaHost: MediaHost,  ) { -    val currentScene: StateFlow<CommunalSceneKey> = communalInteractor.desiredScene +    val currentScene: Flow<CommunalSceneKey> = communalInteractor.desiredScene      /** Whether widgets are currently being re-ordered. */      open val reorderingWidgets: StateFlow<Boolean> = MutableStateFlow(false) 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 85291b814b3c..5df73197a17c 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,10 @@ 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.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 @@ -508,6 +510,10 @@ class MediaHierarchyManagerTest : SysuiTestCase() {      @Test      fun testCommunalLocation() =          testScope.runTest { +            mSetFlagsRule.enableFlags(Flags.FLAG_COMMUNAL_HUB) +            kosmos.setCommunalAvailable(true) +            runCurrent() +              communalInteractor.onSceneChanged(CommunalSceneKey.Communal)              runCurrent()              verify(mediaCarouselController) diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt index 1dc5f7dbf6fe..665fc750c742 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/GlanceableHubContainerControllerTest.kt @@ -26,17 +26,20 @@ import android.view.View  import android.view.WindowManager  import android.widget.FrameLayout  import androidx.test.filters.SmallTest +import com.android.systemui.Flags  import com.android.systemui.SysuiTestCase  import com.android.systemui.communal.data.repository.FakeCommunalRepository  import com.android.systemui.communal.data.repository.fakeCommunalRepository  import com.android.systemui.communal.domain.interactor.CommunalInteractor  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.communal.ui.viewmodel.CommunalViewModel  import com.android.systemui.compose.ComposeFacade  import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor  import com.android.systemui.kosmos.Kosmos  import com.android.systemui.kosmos.testDispatcher +import com.android.systemui.kosmos.testScope  import com.android.systemui.res.R  import com.android.systemui.shade.domain.interactor.ShadeInteractor  import com.android.systemui.testKosmos @@ -45,6 +48,7 @@ import com.android.systemui.util.mockito.whenever  import com.google.common.truth.Truth.assertThat  import kotlinx.coroutines.ExperimentalCoroutinesApi  import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.launch  import kotlinx.coroutines.test.UnconfinedTestDispatcher  import org.junit.After  import org.junit.Assert.assertThrows @@ -114,6 +118,14 @@ class GlanceableHubContainerControllerTest : SysuiTestCase() {              BOTTOM_SWIPE_REGION_WIDTH          ) +        // Make communal available so that communalInteractor.desiredScene accurately reflects +        // scene changes instead of just returning Blank. +        mSetFlagsRule.enableFlags(Flags.FLAG_COMMUNAL_HUB) +        with(kosmos.testScope) { +            launch { kosmos.setCommunalAvailable(true) } +            testScheduler.runCurrent() +        } +          initAndAttachContainerView()      } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt index 6af08d3df554..505e2f05e068 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt @@ -60,9 +60,11 @@ suspend fun Kosmos.setCommunalAvailable(available: Boolean) {      fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, available)      if (available) {          fakeUserRepository.asMainUser() -        with(fakeKeyguardRepository) { -            setIsEncryptedOrLockdown(false) -            setKeyguardShowing(true) -        } +    } else { +        fakeUserRepository.asDefaultUser() +    } +    with(fakeKeyguardRepository) { +        setIsEncryptedOrLockdown(!available) +        setKeyguardShowing(available)      }  } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/user/data/repository/FakeUserRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/user/data/repository/FakeUserRepository.kt index 931a59d30d7b..3e9ae4d2e354 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/user/data/repository/FakeUserRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/user/data/repository/FakeUserRepository.kt @@ -119,6 +119,13 @@ class FakeUserRepository @Inject constructor() : UserRepository {          yield()      } +    /** Resets the current user to the default of [DEFAULT_SELECTED_USER_INFO]. */ +    suspend fun asDefaultUser(): UserInfo { +        setUserInfos(listOf(DEFAULT_SELECTED_USER_INFO)) +        setSelectedUserInfo(DEFAULT_SELECTED_USER_INFO) +        return DEFAULT_SELECTED_USER_INFO +    } +      /** Makes the current user [MAIN_USER]. */      suspend fun asMainUser(): UserInfo {          setUserInfos(listOf(MAIN_USER)) |