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

Commit e25c4628 authored by Darrell Shi's avatar Darrell Shi
Browse files

Remove CommunalRepository#isCommunalHubShowing

Use CommunalInteractor#isCommunalShowing instead.

Test: atest CommunalInteractorTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING
Change-Id: Ibc14126e796bfe842ca465d66f81928bc2516cf5
parent fda620ae
Loading
Loading
Loading
Loading
+0 −41
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.coroutines.collectLastValue
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
@@ -56,46 +55,6 @@ class CommunalRepositoryImplTest : SysuiTestCase() {
        )
    }

    @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 {
+47 −5
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ import com.android.systemui.flags.fakeFeatureFlagsClassic
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 @@ class CommunalInteractorTest : SysuiTestCase() {
    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 @@ class CommunalInteractorTest : SysuiTestCase() {
        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 @@ class CommunalInteractorTest : SysuiTestCase() {
        }

    @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)
            runCurrent()
            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()

            isCommunalShowing = collectLastValue(underTest.isCommunalShowing)
            // Verify scene changes (with the flag) to lockscreen sets the value to false
            sceneInteractor.changeScene(SceneKey.Lockscreen, loggingReason = "")
            runCurrent()
            assertThat(isCommunalShowing()).isEqualTo(true)
            assertThat(isCommunalShowing).isFalse()
        }

    @Test
+12 −17
Original line number Diff line number Diff line
@@ -24,10 +24,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
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.testKosmos
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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
    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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
    fun setUp() {
        keyguardRepository = kosmos.fakeKeyguardRepository
        communalTutorialRepository = kosmos.fakeCommunalTutorialRepository
        communalRepository = kosmos.fakeCommunalRepository
        communalInteractor = kosmos.communalInteractor
        userRepository = kosmos.fakeUserRepository

@@ -90,7 +85,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            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)
        }
+0 −12
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import com.android.systemui.dagger.SysUISingleton
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.StateFlow
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 @@ constructor(
    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 }
        }
}
+14 −2
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ import com.android.systemui.log.dagger.CommunalLog
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.asStateFlow
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 @@ constructor(
    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 @@ constructor(
     */
    // 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 }
Loading