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

Commit a328260d authored by William Xiao's avatar William Xiao Committed by Android (Google) Code Review
Browse files

Merge "Block all touches from reaching the hub when the shade is open" into main

parents 2b9feda3 f352cdb2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.compose.animation.scene.observableTransitionState
import com.android.compose.animation.scene.transitions
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalTransitionKeys
import com.android.systemui.communal.ui.compose.extensions.allowGestures
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.util.CommunalColors
import com.android.systemui.res.R
@@ -79,6 +80,7 @@ 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,
@@ -128,6 +130,10 @@ fun CommunalContainer(
            CommunalScene(viewModel, colors, dialogFactory, modifier = modifier)
        }
    }

    // Touches on the notification shade in blank areas fall through to the glanceable hub. When the
    // shade is showing, we block all touches in order to prevent this unwanted behavior.
    Box(modifier = Modifier.fillMaxSize().allowGestures(touchesAllowed))
}

/** Scene containing the glanceable hub UI. */
+24 −0
Original line number Diff line number Diff line
@@ -342,6 +342,30 @@ class CommunalViewModelTest(flags: FlagsParameterization?) : SysuiTestCase() {
            assertThat(underTest.canChangeScene()).isFalse()
        }

    @Test
    fun touchesAllowed_shadeNotExpanded() =
        testScope.runTest {
            val touchesAllowed by collectLastValue(underTest.touchesAllowed)

            // On keyguard without any shade expansion.
            kosmos.fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
            shadeTestUtil.setLockscreenShadeExpansion(0f)
            runCurrent()
            assertThat(touchesAllowed).isTrue()
        }

    @Test
    fun touchesAllowed_shadeExpanded() =
        testScope.runTest {
            val touchesAllowed by collectLastValue(underTest.touchesAllowed)

            // On keyguard with shade fully expanded.
            kosmos.fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
            shadeTestUtil.setLockscreenShadeExpansion(1f)
            runCurrent()
            assertThat(touchesAllowed).isFalse()
        }

    @Test
    fun isFocusable_isFalse_whenTransitioningAwayFromGlanceableHub() =
        testScope.runTest {
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ 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
@@ -206,6 +207,14 @@ constructor(
        return !shadeInteractor.isAnyFullyExpanded.value
    }

    /**
     * Whether touches should be disabled in communal.
     *
     * This is needed because the notification shade does not block touches in blank areas and these
     * fall through to the glanceable hub, which we don't want.
     */
    val touchesAllowed: Flow<Boolean> = not(shadeInteractor.isAnyFullyExpanded)

    companion object {
        const val POPUP_AUTO_HIDE_TIMEOUT_MS = 12000L
    }