Remove CommunalRepository#isCommunalHubShowing
Use CommunalInteractor#isCommunalShowing instead.
Test: atest CommunalInteractorTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING
Change-Id: Ibc14126e796bfe842ca465d66f81928bc2516cf5
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalRepositoryImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalRepositoryImplTest.kt
index 5b20ae5..06b3806 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalRepositoryImplTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/data/repository/CommunalRepositoryImplTest.kt
@@ -25,7 +25,6 @@
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.data.repository.sceneContainerRepository
import com.android.systemui.scene.shared.flag.fakeSceneContainerFlags
-import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.flowOf
@@ -57,46 +56,6 @@
}
@Test
- fun isCommunalShowing_sceneContainerDisabled_onCommunalScene_true() =
- testScope.runTest {
- underTest.setDesiredScene(CommunalSceneKey.Communal)
-
- val isCommunalHubShowing by collectLastValue(underTest.isCommunalHubShowing)
- assertThat(isCommunalHubShowing).isTrue()
- }
-
- @Test
- fun isCommunalShowing_sceneContainerDisabled_onBlankScene_false() =
- testScope.runTest {
- underTest.setDesiredScene(CommunalSceneKey.Blank)
-
- val isCommunalHubShowing by collectLastValue(underTest.isCommunalHubShowing)
- assertThat(isCommunalHubShowing).isFalse()
- }
-
- @Test
- fun isCommunalShowing_sceneContainerEnabled_onCommunalScene_true() =
- testScope.runTest {
- underTest = createRepositoryImpl(true)
-
- sceneContainerRepository.changeScene(SceneKey.Communal)
-
- val isCommunalHubShowing by collectLastValue(underTest.isCommunalHubShowing)
- assertThat(isCommunalHubShowing).isTrue()
- }
-
- @Test
- fun isCommunalShowing_sceneContainerEnabled_onLockscreenScene_false() =
- testScope.runTest {
- underTest = createRepositoryImpl(true)
-
- sceneContainerRepository.changeScene(SceneKey.Lockscreen)
-
- val isCommunalHubShowing by collectLastValue(underTest.isCommunalHubShowing)
- assertThat(isCommunalHubShowing).isFalse()
- }
-
- @Test
fun transitionState_idleByDefault() =
testScope.runTest {
val transitionState by collectLastValue(underTest.transitionState)
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 3ac19e4..7cc4c31 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
@@ -47,6 +47,10 @@
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.kosmos.testScope
+import com.android.systemui.scene.domain.interactor.SceneInteractor
+import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.scene.shared.flag.fakeSceneContainerFlags
+import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository
import com.android.systemui.smartspace.data.repository.fakeSmartspaceRepository
import com.android.systemui.testKosmos
@@ -91,6 +95,7 @@
private lateinit var keyguardRepository: FakeKeyguardRepository
private lateinit var communalPrefsRepository: FakeCommunalPrefsRepository
private lateinit var editWidgetsActivityStarter: EditWidgetsActivityStarter
+ private lateinit var sceneInteractor: SceneInteractor
private lateinit var underTest: CommunalInteractor
@@ -107,6 +112,7 @@
keyguardRepository = kosmos.fakeKeyguardRepository
editWidgetsActivityStarter = kosmos.editWidgetsActivityStarter
communalPrefsRepository = kosmos.fakeCommunalPrefsRepository
+ sceneInteractor = kosmos.sceneInteractor
whenever(mainUser.isMain).thenReturn(true)
whenever(secondaryUser.isMain).thenReturn(false)
@@ -598,17 +604,53 @@
}
@Test
- fun isCommunalShowing() =
+ fun isCommunalShowing_whenSceneContainerDisabled() =
testScope.runTest {
- var isCommunalShowing = collectLastValue(underTest.isCommunalShowing)
+ // Verify default is false
+ val isCommunalShowing by collectLastValue(underTest.isCommunalShowing)
runCurrent()
- assertThat(isCommunalShowing()).isEqualTo(false)
+ assertThat(isCommunalShowing).isFalse()
+ // Verify scene changes with the flag doesn't have any impact
+ sceneInteractor.changeScene(SceneKey.Communal, loggingReason = "")
+ runCurrent()
+ assertThat(isCommunalShowing).isFalse()
+
+ // Verify scene changes (without the flag) to communal sets the value to true
underTest.onSceneChanged(CommunalSceneKey.Communal)
-
- isCommunalShowing = collectLastValue(underTest.isCommunalShowing)
runCurrent()
- assertThat(isCommunalShowing()).isEqualTo(true)
+ assertThat(isCommunalShowing).isTrue()
+
+ // Verify scene changes (without the flag) to blank sets the value back to false
+ underTest.onSceneChanged(CommunalSceneKey.Blank)
+ runCurrent()
+ assertThat(isCommunalShowing).isFalse()
+ }
+
+ @Test
+ fun isCommunalShowing_whenSceneContainerEnabled() =
+ testScope.runTest {
+ kosmos.fakeSceneContainerFlags.enabled = true
+
+ // Verify default is false
+ val isCommunalShowing by collectLastValue(underTest.isCommunalShowing)
+ runCurrent()
+ assertThat(isCommunalShowing).isFalse()
+
+ // Verify scene changes without the flag doesn't have any impact
+ underTest.onSceneChanged(CommunalSceneKey.Communal)
+ runCurrent()
+ assertThat(isCommunalShowing).isFalse()
+
+ // Verify scene changes (with the flag) to communal sets the value to true
+ sceneInteractor.changeScene(SceneKey.Communal, loggingReason = "")
+ runCurrent()
+ assertThat(isCommunalShowing).isTrue()
+
+ // Verify scene changes (with the flag) to lockscreen sets the value to false
+ sceneInteractor.changeScene(SceneKey.Lockscreen, loggingReason = "")
+ runCurrent()
+ assertThat(isCommunalShowing).isFalse()
}
@Test
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 ceb7fac..5211c55 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
@@ -24,10 +24,9 @@
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
import com.android.systemui.SysuiTestCase
-import com.android.systemui.communal.data.repository.FakeCommunalRepository
import com.android.systemui.communal.data.repository.FakeCommunalTutorialRepository
-import com.android.systemui.communal.data.repository.fakeCommunalRepository
import com.android.systemui.communal.data.repository.fakeCommunalTutorialRepository
+import com.android.systemui.communal.shared.model.CommunalSceneKey
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
@@ -38,13 +37,11 @@
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.data.repository.fakeUserRepository
import com.google.common.truth.Truth.assertThat
-import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
-@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class CommunalTutorialInteractorTest : SysuiTestCase() {
@@ -54,7 +51,6 @@
private lateinit var underTest: CommunalTutorialInteractor
private lateinit var keyguardRepository: FakeKeyguardRepository
private lateinit var communalTutorialRepository: FakeCommunalTutorialRepository
- private lateinit var communalRepository: FakeCommunalRepository
private lateinit var communalInteractor: CommunalInteractor
private lateinit var userRepository: FakeUserRepository
@@ -62,7 +58,6 @@
fun setUp() {
keyguardRepository = kosmos.fakeKeyguardRepository
communalTutorialRepository = kosmos.fakeCommunalTutorialRepository
- communalRepository = kosmos.fakeCommunalRepository
communalInteractor = kosmos.communalInteractor
userRepository = kosmos.fakeUserRepository
@@ -90,7 +85,7 @@
setCommunalAvailable(true)
keyguardRepository.setKeyguardShowing(true)
keyguardRepository.setKeyguardOccluded(false)
- communalRepository.setIsCommunalHubShowing(false)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED)
assertThat(isTutorialAvailable).isFalse()
}
@@ -112,7 +107,7 @@
setCommunalAvailable(true)
keyguardRepository.setKeyguardShowing(true)
keyguardRepository.setKeyguardOccluded(false)
- communalRepository.setIsCommunalHubShowing(false)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Blank)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)
assertThat(isTutorialAvailable).isTrue()
}
@@ -124,7 +119,7 @@
setCommunalAvailable(true)
keyguardRepository.setKeyguardShowing(true)
keyguardRepository.setKeyguardOccluded(false)
- communalRepository.setIsCommunalHubShowing(true)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED)
assertThat(isTutorialAvailable).isTrue()
}
@@ -137,7 +132,7 @@
userRepository.setSelectedUserInfo(MAIN_USER_INFO)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)
- communalRepository.setIsCommunalHubShowing(true)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_STARTED)
}
@@ -150,7 +145,7 @@
userRepository.setSelectedUserInfo(MAIN_USER_INFO)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED)
- communalRepository.setIsCommunalHubShowing(true)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_STARTED)
}
@@ -163,7 +158,7 @@
userRepository.setSelectedUserInfo(MAIN_USER_INFO)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED)
- communalRepository.setIsCommunalHubShowing(true)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)
}
@@ -176,7 +171,7 @@
userRepository.setSelectedUserInfo(MAIN_USER_INFO)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)
- communalRepository.setIsCommunalHubShowing(false)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Blank)
assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_NOT_STARTED)
}
@@ -187,10 +182,10 @@
val tutorialSettingState by
collectLastValue(communalTutorialRepository.tutorialSettingState)
userRepository.setSelectedUserInfo(MAIN_USER_INFO)
- communalRepository.setIsCommunalHubShowing(true)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED)
- communalRepository.setIsCommunalHubShowing(false)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Blank)
assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)
}
@@ -201,10 +196,10 @@
val tutorialSettingState by
collectLastValue(communalTutorialRepository.tutorialSettingState)
userRepository.setSelectedUserInfo(MAIN_USER_INFO)
- communalRepository.setIsCommunalHubShowing(true)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED)
- communalRepository.setIsCommunalHubShowing(false)
+ communalInteractor.onSceneChanged(CommunalSceneKey.Blank)
assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)
}
diff --git a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt
index 9e68ff8..f4a3bcb 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt
@@ -22,7 +22,6 @@
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.scene.data.repository.SceneContainerRepository
import com.android.systemui.scene.shared.flag.SceneContainerFlags
-import com.android.systemui.scene.shared.model.SceneKey
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -33,14 +32,10 @@
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
-import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
/** Encapsulates the state of communal mode. */
interface CommunalRepository {
- /** Whether the communal hub is showing. */
- val isCommunalHubShowing: Flow<Boolean>
-
/**
* Target scene as requested by the underlying [SceneTransitionLayout] or through
* [setDesiredScene].
@@ -99,11 +94,4 @@
override fun setTransitionState(transitionState: Flow<ObservableCommunalTransitionState>?) {
_transitionState.value = transitionState
}
-
- override val isCommunalHubShowing: Flow<Boolean> =
- if (sceneContainerFlags.isEnabled()) {
- sceneContainerRepository.currentScene.map { sceneKey -> sceneKey == SceneKey.Communal }
- } else {
- desiredScene.map { sceneKey -> sceneKey == 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 b4f4099..1aa1fe8 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
@@ -41,6 +41,9 @@
import com.android.systemui.log.dagger.CommunalTableLog
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.logDiffsForTable
+import com.android.systemui.scene.domain.interactor.SceneInteractor
+import com.android.systemui.scene.shared.flag.SceneContainerFlags
+import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.smartspace.data.repository.SmartspaceRepository
import com.android.systemui.util.kotlin.BooleanFlowOperators.and
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
@@ -56,6 +59,7 @@
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
@@ -77,6 +81,8 @@
private val communalSettingsInteractor: CommunalSettingsInteractor,
private val appWidgetHost: CommunalAppWidgetHost,
private val editWidgetsActivityStarter: EditWidgetsActivityStarter,
+ sceneInteractor: SceneInteractor,
+ sceneContainerFlags: SceneContainerFlags,
@CommunalLog logBuffer: LogBuffer,
@CommunalTableLog tableLogBuffer: TableLogBuffer,
) {
@@ -172,8 +178,14 @@
*/
// TODO(b/323215860): rename to something more appropriate after cleaning up usages
val isCommunalShowing: Flow<Boolean> =
- communalRepository.desiredScene
- .map { it == CommunalSceneKey.Communal }
+ flow { emit(sceneContainerFlags.isEnabled()) }
+ .flatMapLatest { sceneContainerEnabled ->
+ if (sceneContainerEnabled) {
+ sceneInteractor.currentScene.map { it == SceneKey.Communal }
+ } else {
+ desiredScene.map { it == CommunalSceneKey.Communal }
+ }
+ }
.distinctUntilChanged()
.onEach { showing ->
logger.i({ "Communal is ${if (bool1) "showing" else "gone"}" }) { bool1 = showing }
diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt
index 25dfc02..2b7db14 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt
@@ -17,7 +17,6 @@
package com.android.systemui.communal.domain.interactor
import android.provider.Settings
-import com.android.systemui.communal.data.repository.CommunalRepository
import com.android.systemui.communal.data.repository.CommunalTutorialRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -51,7 +50,6 @@
@Application private val scope: CoroutineScope,
private val communalTutorialRepository: CommunalTutorialRepository,
keyguardInteractor: KeyguardInteractor,
- private val communalRepository: CommunalRepository,
private val communalSettingsInteractor: CommunalSettingsInteractor,
communalInteractor: CommunalInteractor,
@CommunalTableLog tableLogBuffer: TableLogBuffer,
@@ -92,7 +90,7 @@
if (tutorialSettingState == Settings.Secure.HUB_MODE_TUTORIAL_COMPLETED) {
return@flatMapLatest flowOf(null)
}
- communalRepository.isCommunalHubShowing.map { isCommunalShowing ->
+ communalInteractor.isCommunalShowing.map { isCommunalShowing ->
nextStateAfterTransition(
tutorialSettingState,
isCommunalShowing,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/FakeCommunalRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/FakeCommunalRepository.kt
index ae7d877..9d508d2 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/FakeCommunalRepository.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/data/repository/FakeCommunalRepository.kt
@@ -38,11 +38,4 @@
override fun setTransitionState(transitionState: Flow<ObservableCommunalTransitionState>?) {
_transitionState.value = transitionState
}
-
- private val _isCommunalHubShowing: MutableStateFlow<Boolean> = MutableStateFlow(false)
- override val isCommunalHubShowing: Flow<Boolean> = _isCommunalHubShowing
-
- fun setIsCommunalHubShowing(isCommunalHubShowing: Boolean) {
- _isCommunalHubShowing.value = isCommunalHubShowing
- }
}
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 f7e9a11..19c78d2 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
@@ -26,6 +26,8 @@
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.log.logcatLogBuffer
+import com.android.systemui.scene.domain.interactor.sceneInteractor
+import com.android.systemui.scene.shared.flag.fakeSceneContainerFlags
import com.android.systemui.smartspace.data.repository.smartspaceRepository
import com.android.systemui.util.mockito.mock
@@ -43,6 +45,8 @@
logBuffer = logcatLogBuffer("CommunalInteractor"),
tableLogBuffer = mock(),
communalSettingsInteractor = communalSettingsInteractor,
+ sceneInteractor = sceneInteractor,
+ sceneContainerFlags = fakeSceneContainerFlags,
)
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorKosmos.kt
index 00fdced..23f63e6 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorKosmos.kt
@@ -16,7 +16,6 @@
package com.android.systemui.communal.domain.interactor
-import com.android.systemui.communal.data.repository.communalRepository
import com.android.systemui.communal.data.repository.communalTutorialRepository
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.Kosmos
@@ -29,7 +28,6 @@
scope = applicationCoroutineScope,
communalTutorialRepository = communalTutorialRepository,
keyguardInteractor = keyguardInteractor,
- communalRepository = communalRepository,
communalInteractor = communalInteractor,
communalSettingsInteractor = communalSettingsInteractor,
tableLogBuffer = mock(),