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

Commit f3ff1160 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz
Browse files

[Flexi] Fix swipe from touchable status bar elements not going through to the shade.

Test: Manually ensure gesture behavior is identical over chips compared to the rest of the status bar.
Test: PhoneStatusBarViewControllerTest
Bug: 359192607
Flag: com.android.systemui.scene_container

Change-Id: I3f3020e1c29a329dbfc5cfbc965ecbd20f4e2ff8
parent 9082c0a6
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.view.Display.DEFAULT_DISPLAY
import android.view.InputDevice
import android.view.MotionEvent
import android.view.View
import android.view.ViewConfiguration
import androidx.annotation.VisibleForTesting
import com.android.systemui.Flags
import com.android.systemui.Gefingerpoken
@@ -258,16 +259,39 @@ private constructor(
    }

    inner class PhoneStatusBarViewTouchHandler : Gefingerpoken {
        private val touchSlop = ViewConfiguration.get(mView.context).scaledTouchSlop
        private var initialTouchX = 0f
        private var initialTouchY = 0f

        override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
            if (event.action == MotionEvent.ACTION_DOWN) {
                dispatchEventToShadeDisplayPolicy(event)
            }
            return if (Flags.statusBarSwipeOverChip()) {
                shadeViewController.handleExternalInterceptTouch(event)
            } else {

            if (!Flags.statusBarSwipeOverChip()) {
                onTouch(event)
                false
                return false
            }

            // Let ShadeViewController intercept touch events when flexiglass is disabled.
            if (!SceneContainerFlag.isEnabled) {
                return shadeViewController.handleExternalInterceptTouch(event)
            }

            when (event.action) {
                MotionEvent.ACTION_DOWN -> {
                    initialTouchX = event.x
                    initialTouchY = event.y
                }
                MotionEvent.ACTION_MOVE -> {
                    val dy = event.y - initialTouchY
                    if (dy > touchSlop) {
                        windowRootView.get().dispatchTouchEvent(event)
                        return true
                    }
                }
            }
            return false
        }

        override fun onTouchEvent(event: MotionEvent): Boolean {
+44 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestableContext
import com.android.systemui.battery.BatteryMeterView
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.kosmos.collectLastValue
@@ -385,6 +386,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
    }

    @Test
    @DisableSceneContainer
    @DisableFlags(com.android.systemui.Flags.FLAG_STATUS_BAR_SWIPE_OVER_CHIP)
    fun handleInterceptTouchEventFromStatusBar_shadeReturnsFalse_flagOff_viewReturnsFalse() {
        whenever(shadeViewController.handleExternalInterceptTouch(any())).thenReturn(false)
@@ -396,6 +398,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
    }

    @Test
    @DisableSceneContainer
    @EnableFlags(com.android.systemui.Flags.FLAG_STATUS_BAR_SWIPE_OVER_CHIP)
    fun handleInterceptTouchEventFromStatusBar_shadeReturnsFalse_flagOn_viewReturnsFalse() {
        whenever(shadeViewController.handleExternalInterceptTouch(any())).thenReturn(false)
@@ -407,6 +410,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
    }

    @Test
    @DisableSceneContainer
    @DisableFlags(com.android.systemui.Flags.FLAG_STATUS_BAR_SWIPE_OVER_CHIP)
    fun handleInterceptTouchEventFromStatusBar_shadeReturnsTrue_flagOff_viewReturnsFalse() {
        whenever(shadeViewController.handleExternalInterceptTouch(any())).thenReturn(true)
@@ -418,6 +422,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
    }

    @Test
    @DisableSceneContainer
    @EnableFlags(com.android.systemui.Flags.FLAG_STATUS_BAR_SWIPE_OVER_CHIP)
    fun handleInterceptTouchEventFromStatusBar_shadeReturnsTrue_flagOn_viewReturnsTrue() {
        whenever(shadeViewController.handleExternalInterceptTouch(any())).thenReturn(true)
@@ -428,6 +433,45 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        assertThat(returnVal).isTrue()
    }

    @Test
    @EnableSceneContainer
    fun handleInterceptTouchEventFromStatusBar_swipeDown_intercepts() {
        val downEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 10f, 0)
        view.onInterceptTouchEvent(downEvent)

        val moveEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 0f, 100f, 0)
        val intercepted = view.onInterceptTouchEvent(moveEvent)

        assertThat(intercepted).isTrue()
        verify(windowRootView).dispatchTouchEvent(moveEvent)
    }

    @Test
    @EnableSceneContainer
    fun handleInterceptTouchEventFromStatusBar_smallSwipe_doesNotIntercept() {
        val downEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 10f, 0)
        view.onInterceptTouchEvent(downEvent)

        val moveEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 0f, 11f, 0)
        val intercepted = view.onInterceptTouchEvent(moveEvent)

        assertThat(intercepted).isFalse()
        verify(windowRootView, never()).dispatchTouchEvent(any())
    }

    @Test
    @EnableSceneContainer
    fun handleInterceptTouchEventFromStatusBar_horizontalSwipe_doesNotIntercept() {
        val downEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 10f, 0)
        view.onInterceptTouchEvent(downEvent)

        val moveEvent = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_MOVE, 100f, 11f, 0)
        val intercepted = view.onInterceptTouchEvent(moveEvent)

        assertThat(intercepted).isFalse()
        verify(windowRootView, never()).dispatchTouchEvent(any())
    }

    @Test
    fun onTouch_windowHidden_centralSurfacesNotNotified() {
        val callback = getCommandQueueCallback()