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

Commit 90ba0f75 authored by William Xiao's avatar William Xiao
Browse files

Add helper methods to CommunalInteractor

These are helpful for external transitions to depend on in order to
know when the hub is fully showing and not in transition.

Bug: 315205216
Test: atest CommunalInteractorTest
Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Change-Id: I3f746a2c6339c924113ef0f8fbd85adfe0fd5f08
parent 77400256
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -556,6 +556,43 @@ class CommunalInteractorTest : SysuiTestCase() {
            assertThat(isCommunalShowing()).isEqualTo(true)
        }

    @Test
    fun isIdleOnCommunal() =
        testScope.runTest {
            val transitionState =
                MutableStateFlow<ObservableCommunalTransitionState>(
                    ObservableCommunalTransitionState.Idle(CommunalSceneKey.Blank)
                )
            communalRepository.setTransitionState(transitionState)

            // isIdleOnCommunal is false when not on communal.
            val isIdleOnCommunal by collectLastValue(underTest.isIdleOnCommunal)
            runCurrent()
            assertThat(isIdleOnCommunal).isEqualTo(false)

            // Transition to communal.
            transitionState.value =
                ObservableCommunalTransitionState.Idle(CommunalSceneKey.Communal)
            runCurrent()

            // isIdleOnCommunal is now true since we're on communal.
            assertThat(isIdleOnCommunal).isEqualTo(true)

            // Start transition away from communal.
            transitionState.value =
                ObservableCommunalTransitionState.Transition(
                    fromScene = CommunalSceneKey.Communal,
                    toScene = CommunalSceneKey.Blank,
                    progress = flowOf(0f),
                    isInitiatedByUserInput = false,
                    isUserInputOngoing = flowOf(false),
                )
            runCurrent()

            // isIdleOnCommunal turns false as soon as transition away starts.
            assertThat(isIdleOnCommunal).isEqualTo(false)
        }

    @Test
    fun testShowWidgetEditorStartsActivity() =
        testScope.runTest {
+12 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ import kotlinx.coroutines.flow.stateIn
class CommunalInteractor
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Application applicationScope: CoroutineScope,
    private val communalRepository: CommunalRepository,
    private val widgetRepository: CommunalWidgetRepository,
    private val communalPrefsRepository: CommunalPrefsRepository,
@@ -133,6 +133,17 @@ constructor(
    val isCommunalShowing: Flow<Boolean> =
        communalRepository.desiredScene.map { it == CommunalSceneKey.Communal }

    /**
     * Flow that emits a boolean if the communal UI is fully visible and not in transition.
     *
     * This will not be true while transitioning to the hub and will turn false immediately when a
     * swipe to exit the hub starts.
     */
    val isIdleOnCommunal: Flow<Boolean> =
        communalRepository.transitionState.map {
            it is ObservableCommunalTransitionState.Idle && it.scene == CommunalSceneKey.Communal
        }

    val isKeyguardVisible: Flow<Boolean> = keyguardInteractor.isKeyguardVisible

    /** Callback received whenever the [SceneTransitionLayout] finishes a scene transition. */
+2 −2
Original line number Diff line number Diff line
@@ -24,14 +24,14 @@ import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.communal.widgets.CommunalAppWidgetHost
import com.android.systemui.communal.widgets.EditWidgetsActivityStarter
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.smartspace.data.repository.smartspaceRepository
import org.mockito.Mockito.mock

val Kosmos.communalInteractor by
    Kosmos.Fixture {
        CommunalInteractor(
            applicationScope = testScope.backgroundScope,
            applicationScope = applicationCoroutineScope,
            communalRepository = communalRepository,
            widgetRepository = communalWidgetRepository,
            mediaRepository = communalMediaRepository,