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

Commit 3ecb0627 authored by William Xiao's avatar William Xiao
Browse files

Fix swipe to hub sometimes not working

The hub ignores all touches when the shade is open as touches in empty
portions of the shade seem to fall through directly to our view without
going through any of our other touch handling logic. However we were
not using a StateFlow and set the initial value to false, meaning that
if the shade flow didn't update once the hub became available, touches
would be ignored. The flow seems to update most of the time when
locking or entering the dream, but it is not guaranteed.

This changes the flow in our ViewModel to a StateFlow and initializes
the variable in the composable using the StateFlow's value instead of
always false.

Bug: 349200647
Fix: 349200647
Test: manually verified that swiping to open the hub after pressing
      power to start dream works repeatedly, and that touchesAllowed
      has the right value once dreaming starts
Flag: com.android.systemui.communal_hub
Change-Id: Ic5503632db231f2a82a5a4bb24ecdff74d65f198
parent c7c4057c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ fun CommunalContainer(
    val coroutineScope = rememberCoroutineScope()
    val currentSceneKey: SceneKey by
        viewModel.currentScene.collectAsStateWithLifecycle(CommunalScenes.Blank)
    val touchesAllowed by viewModel.touchesAllowed.collectAsStateWithLifecycle(initialValue = false)
    val touchesAllowed by viewModel.touchesAllowed.collectAsStateWithLifecycle()
    val showGestureIndicator by
        viewModel.showGestureIndicator.collectAsStateWithLifecycle(initialValue = false)
    val backgroundType by
+1 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            CommunalViewModel(
                kosmos.testDispatcher,
                testScope,
                kosmos.testScope.backgroundScope,
                context.resources,
                kosmos.keyguardTransitionInteractor,
                kosmos.keyguardInteractor,
+10 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.model.CommunalBackgroundType
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
@@ -55,6 +56,8 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
@@ -64,6 +67,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

/** The default view model used for showing the communal hub. */
@@ -74,6 +78,7 @@ class CommunalViewModel
constructor(
    @Main val mainDispatcher: CoroutineDispatcher,
    @Application private val scope: CoroutineScope,
    @Background private val bgScope: CoroutineScope,
    @Main private val resources: Resources,
    keyguardTransitionInteractor: KeyguardTransitionInteractor,
    keyguardInteractor: KeyguardInteractor,
@@ -303,8 +308,12 @@ constructor(
     *
     * 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.
     *
     * Using a StateFlow as the value does not necessarily change when hub becomes available.
     */
    val touchesAllowed: Flow<Boolean> = not(shadeInteractor.isAnyFullyExpanded)
    val touchesAllowed: StateFlow<Boolean> =
        not(shadeInteractor.isAnyFullyExpanded)
            .stateIn(bgScope, SharingStarted.Eagerly, initialValue = false)

    // TODO(b/339667383): remove this temporary swipe gesture handle
    /**