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

Commit f9a90d86 authored by Lucas Silva's avatar Lucas Silva
Browse files

Refactor logic to allow touches to use SceneTransitionLayout APIs

MutableSceneTransitionLayoutState already offers a way to pass in a
function which gets called when a gesture is detected, to determine
whether the gesture is allowed to change scenes or not. This change
migrates the existing mechanism which disallows touches to this built-in
API instead.

This has the benefit of not needing to recompose the container when the
shade is expanded/collapsed.

In the future, we can also check falsing signal inside this same
callback.

Bug: 336330508
Test: atest CommunalViewModelTest
Flag: ACONFIG com.android.systemui.communal_hub TEAMFOOD
Change-Id: I558f03b5e26d5d520bfd07f690278a049e56fd2c
parent 9adec260
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -79,10 +79,10 @@ fun CommunalContainer(
) {
    val coroutineScope = rememberCoroutineScope()
    val currentSceneKey: SceneKey by viewModel.currentScene.collectAsState(CommunalScenes.Blank)
    val touchesAllowed by viewModel.touchesAllowed.collectAsState(initial = false)
    val state: MutableSceneTransitionLayoutState = remember {
        MutableSceneTransitionLayoutState(
            initialScene = currentSceneKey,
            canChangeScene = { _ -> viewModel.canChangeScene() },
            transitions = sceneTransitions,
            enableInterruptions = false,
        )
@@ -112,14 +112,9 @@ fun CommunalContainer(
        scene(
            CommunalScenes.Blank,
            userActions =
                if (touchesAllowed) {
                mapOf(
                        Swipe(SwipeDirection.Left, fromSource = Edge.Right) to
                            CommunalScenes.Communal
                    Swipe(SwipeDirection.Left, fromSource = Edge.Right) to CommunalScenes.Communal
                )
                } else {
                    emptyMap()
                }
        ) {
            // This scene shows nothing only allowing for transitions to the communal scene.
            Box(modifier = Modifier.fillMaxSize())
@@ -128,13 +123,7 @@ fun CommunalContainer(
        scene(
            CommunalScenes.Communal,
            userActions =
                if (touchesAllowed) {
                    mapOf(
                        Swipe(SwipeDirection.Right, fromSource = Edge.Left) to CommunalScenes.Blank
                    )
                } else {
                    emptyMap()
                },
                mapOf(Swipe(SwipeDirection.Right, fromSource = Edge.Left) to CommunalScenes.Blank)
        ) {
            CommunalScene(viewModel, colors, dialogFactory, modifier = modifier)
        }
+23 −0
Original line number Diff line number Diff line
@@ -44,11 +44,13 @@ import com.android.systemui.flags.Flags.COMMUNAL_SERVICE_ENABLED
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.keyguard.shared.model.StatusBarState
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager
import com.android.systemui.media.controls.ui.view.MediaHost
import com.android.systemui.settings.fakeUserTracker
import com.android.systemui.shade.data.repository.fakeShadeRepository
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository
import com.android.systemui.smartspace.data.repository.fakeSmartspaceRepository
@@ -59,6 +61,7 @@ import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@@ -266,6 +269,26 @@ class CommunalViewModelTest : SysuiTestCase() {
            assertThat(isPopupOnDismissCtaShowing).isEqualTo(false)
        }

    @Test
    fun canChangeScene_shadeNotExpanded() =
        testScope.runTest {
            // On keyguard without any shade expansion.
            kosmos.fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
            kosmos.fakeShadeRepository.setLockscreenShadeExpansion(0f)
            runCurrent()
            assertThat(underTest.canChangeScene()).isTrue()
        }

    @Test
    fun canChangeScene_shadeExpanded() =
        testScope.runTest {
            // On keyguard with shade fully expanded.
            kosmos.fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
            kosmos.fakeShadeRepository.setLockscreenShadeExpansion(1f)
            runCurrent()
            assertThat(underTest.canChangeScene()).isFalse()
        }

    private suspend fun setIsMainUser(isMainUser: Boolean) {
        whenever(user.isMain).thenReturn(isMainUser)
        userRepository.setUserInfos(listOf(user))
+6 −5
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import com.android.systemui.media.controls.ui.view.MediaHost
import com.android.systemui.media.controls.ui.view.MediaHostState
import com.android.systemui.media.dagger.MediaModule
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
import javax.inject.Inject
import javax.inject.Named
import kotlinx.coroutines.CoroutineScope
@@ -57,7 +56,7 @@ constructor(
    @Application private val scope: CoroutineScope,
    private val communalInteractor: CommunalInteractor,
    tutorialInteractor: CommunalTutorialInteractor,
    shadeInteractor: ShadeInteractor,
    private val shadeInteractor: ShadeInteractor,
    deviceEntryInteractor: DeviceEntryInteractor,
    @Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost,
    @CommunalLog logBuffer: LogBuffer,
@@ -103,9 +102,6 @@ constructor(
    val isEnableWorkProfileDialogShowing: Flow<Boolean> =
        _isEnableWorkProfileDialogShowing.asStateFlow()

    /** Whether touches should be disabled in communal */
    val touchesAllowed: Flow<Boolean> = not(shadeInteractor.isAnyFullyExpanded)

    val deviceUnlocked: Flow<Boolean> = deviceEntryInteractor.isUnlocked

    init {
@@ -192,6 +188,11 @@ constructor(
        delayedHidePopupJob = null
    }

    /** Whether we can transition to a new scene based on a user gesture. */
    fun canChangeScene(): Boolean {
        return !shadeInteractor.isAnyFullyExpanded.value
    }

    companion object {
        const val POPUP_AUTO_HIDE_TIMEOUT_MS = 12000L
    }