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

Commit 6d596d2b authored by Justin Weir's avatar Justin Weir Committed by Android (Google) Code Review
Browse files

Merge "Skip detector enablement if isUserInteracting is true" into main

parents 88e80e27 95865b91
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -37,17 +37,23 @@ constructor(

    @MainThread
    fun enable(onShadeInteraction: Runnable) {
        if (shadeExpansionCollectorJob == null) {
        if (shadeExpansionCollectorJob != null) {
            Log.e(TAG, "Already enabled")
            return
        }
        if (shadeInteractorLazy.get().isUserInteracting.value) {
            Log.e(TAG, "isUserInteracting already true, skipping enable")
            return
        }
        shadeExpansionCollectorJob =
            scope.launch {
                Log.i(TAG, "Enable detector")
                // wait for it to emit true once
                shadeInteractorLazy.get().isUserInteracting.first { it }
                Log.i(TAG, "Detector detected shade interaction")
                onShadeInteraction.run()
            }
        shadeExpansionCollectorJob?.invokeOnCompletion { shadeExpansionCollectorJob = null }
        } else {
            Log.e(TAG, "Already enabled")
        }
    }

    @MainThread
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ interface ShadeInteractor : BaseShadeInteractor {
     * input (i.e. dragging a pointer). This will be true even if the user's input gesture had ended
     * but a transition they initiated is still animating.
     */
    val isUserInteracting: Flow<Boolean>
    val isUserInteracting: StateFlow<Boolean>

    /** Are touches allowed on the notification panel? */
    val isShadeTouchable: Flow<Boolean>
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class ShadeInteractorEmptyImpl @Inject constructor() : ShadeInteractor {
    override val isAnyExpanded: StateFlow<Boolean> = inactiveFlowBoolean
    override val isUserInteractingWithShade: Flow<Boolean> = inactiveFlowBoolean
    override val isUserInteractingWithQs: Flow<Boolean> = inactiveFlowBoolean
    override val isUserInteracting: Flow<Boolean> = inactiveFlowBoolean
    override val isUserInteracting: StateFlow<Boolean> = inactiveFlowBoolean
    override val isShadeTouchable: Flow<Boolean> = inactiveFlowBoolean
    override val isExpandToQsEnabled: Flow<Boolean> = inactiveFlowBoolean
}
+2 −1
Original line number Diff line number Diff line
@@ -65,9 +65,10 @@ constructor(
    override val isShadeFullyExpanded: Flow<Boolean> =
        baseShadeInteractor.shadeExpansion.map { it >= 1f }.distinctUntilChanged()

    override val isUserInteracting: Flow<Boolean> =
    override val isUserInteracting: StateFlow<Boolean> =
        combine(isUserInteractingWithShade, isUserInteractingWithQs) { shade, qs -> shade || qs }
            .distinctUntilChanged()
            .stateIn(scope, SharingStarted.Eagerly, false)

    override val isShadeTouchable: Flow<Boolean> =
        combine(
+12 −0
Original line number Diff line number Diff line
@@ -94,6 +94,18 @@ class AuthDialogPanelInteractionDetectorTest : SysuiTestCase() {
            verify(action).run()
        }

    @Test
    fun enableDetector_isUserInteractingTrue_shouldNotPostRunnable() =
        testComponent.runTest {
            // GIVEN isInteracting starts true
            shadeRepository.setLegacyShadeTracking(true)
            runCurrent()
            detector.enable(action)

            // THEN action was not run
            verifyZeroInteractions(action)
        }

    @Test
    fun enableDetector_shadeExpandImmediate_shouldNotPostRunnable() =
        testComponent.runTest {