Fix screenshot back behavior in 3-button mode
We weren't dismissing when the back button was pressed, because the
screenshot UI loses focus on touch_outside and so we never get the key
press. This change checks if the touch is in the navigation bar system
region, and doesn't reset the focus if so.
Bug: 441745433
Test: manual (using 3-button mode)
Flag: EXEMPT bugfix
Change-Id: I5ca573c43a1004e36632b5d868b57f686d4ab09c
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt
index b347270..5b4eeff 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotShelfViewProxy.kt
@@ -357,7 +357,11 @@
if (
ev is MotionEvent &&
ev.actionMasked == MotionEvent.ACTION_DOWN &&
- !getTouchRegion().contains(ev.rawX.toInt(), ev.rawY.toInt())
+ !view
+ .getObservedRegion(
+ windowManager.currentWindowMetrics.windowInsets
+ )
+ .contains(ev.rawX.toInt(), ev.rawY.toInt())
) {
callbacks?.onTouchOutside()
}
@@ -366,11 +370,7 @@
}
private fun getTouchRegion(): Region {
- return view.getTouchRegion(
- windowManager.currentWindowMetrics.windowInsets.getInsets(
- WindowInsets.Type.systemGestures()
- )
- )
+ return view.getTouchRegion(windowManager.currentWindowMetrics.windowInsets)
}
companion object {
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt
index d4b31b9..e4988cc 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ui/ScreenshotShelfView.kt
@@ -18,7 +18,6 @@
import android.content.Context
import android.content.res.Configuration
-import android.graphics.Insets
import android.graphics.Rect
import android.graphics.Region
import android.util.AttributeSet
@@ -119,7 +118,21 @@
})
}
- fun getTouchRegion(gestureInsets: Insets): Region {
+ fun getObservedRegion(insets: WindowInsets): Region {
+ val region = getTouchRegion(insets)
+ if (
+ resources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode) !=
+ NAV_BAR_MODE_GESTURAL
+ ) {
+ region.op(
+ insets.getBoundingRects(WindowInsets.Type.navigationBars())[0],
+ Region.Op.UNION,
+ )
+ }
+ return region
+ }
+
+ fun getTouchRegion(insets: WindowInsets): Region {
val region = getSwipeRegion()
// only add gesture insets to touch region in gestural mode
@@ -127,6 +140,7 @@
resources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode) ==
NAV_BAR_MODE_GESTURAL
) {
+ val gestureInsets = insets.getInsets(WindowInsets.Type.systemGestures())
// Receive touches in gesture insets so they don't cause TOUCH_OUTSIDE
// left edge gesture region
val insetRect = Rect(0, 0, gestureInsets.left, displayMetrics.heightPixels)