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

Commit d53fe6bc authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/26398347'] into 24Q2-release.

Change-Id: Id3268a6941f2677df67e4da18b1c5c7c8b22dc81
parents 8b43acf5 b50ae207
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.phone
import android.app.StatusBarManager.WINDOW_STATUS_BAR
import android.graphics.Point
import android.util.Log
import android.view.InputDevice
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
@@ -81,7 +82,22 @@ private constructor(
        statusContainer.setOnHoverListener(
            statusOverlayHoverListenerFactory.createDarkAwareListener(statusContainer)
        )
        statusContainer.setOnClickListener { shadeViewController.expand(/* animate= */true) }
        statusContainer.setOnTouchListener(object : View.OnTouchListener {
            override fun onTouch(v: View, event: MotionEvent): Boolean {
                // We want to handle only mouse events here to avoid stealing finger touches from
                // status bar which expands shade when swiped down on. We're using onTouchListener
                // instead of onClickListener as the later will lead to isClickable being set to
                // true and hence ALL touches always being intercepted. See [View.OnTouchEvent]
                if (event.source == InputDevice.SOURCE_MOUSE) {
                    if (event.action == MotionEvent.ACTION_UP) {
                        v.performClick()
                        shadeViewController.expand(/* animate= */ true)
                    }
                    return true
                }
                return false
            }
        })

        progressProvider?.setReadyToHandleTransition(true)
        configurationController.addCallback(configurationListener)
+33 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.StatusBarManager.WINDOW_STATE_HIDDEN
import android.app.StatusBarManager.WINDOW_STATE_HIDING
import android.app.StatusBarManager.WINDOW_STATE_SHOWING
import android.app.StatusBarManager.WINDOW_STATUS_BAR
import android.view.InputDevice
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
@@ -239,10 +240,41 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
            controller = createAndInitController(view)
        }
        val statusContainer = view.requireViewById<View>(R.id.system_icons)
        statusContainer.performClick()
        statusContainer.dispatchTouchEvent(
            getMotionEventFromSource(
                MotionEvent.ACTION_UP,
                0,
                0,
                InputDevice.SOURCE_MOUSE
            )
        )
        verify(shadeViewController).expand(any())
    }

    @Test
    fun statusIconContainerIsNotHandlingTouchScreenTouches() {
        val view = createViewMock()
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            controller = createAndInitController(view)
        }
        val statusContainer = view.requireViewById<View>(R.id.system_icons)
        val handled = statusContainer.dispatchTouchEvent(
            getMotionEventFromSource(
                MotionEvent.ACTION_UP,
                0,
                0,
                InputDevice.SOURCE_TOUCHSCREEN
            )
        )
        assertThat(handled).isFalse()
    }

    private fun getMotionEventFromSource(action: Int, x: Int, y: Int, source: Int): MotionEvent {
        val ev = MotionEvent.obtain(0, 0, action, x.toFloat(), y.toFloat(), 0)
        ev.source = source
        return ev
    }

    @Test
    fun shadeIsNotExpandedOnStatusBarGeneralClick() {
        val view = createViewMock()