Merge "Account for per-edge cutout for system gestures" into sc-qpr1-dev am: 9c7b64968d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15939153

Change-Id: I6a5096a18fb1418e53f442af9f80dba5016189df
This commit is contained in:
Winson Chung
2021-10-01 20:34:00 +00:00
committed by Automerger Merge Worker
4 changed files with 56 additions and 20 deletions

View File

@@ -60,6 +60,9 @@
<!-- How much we expand the touchable region of the status bar below the notch to catch touches <!-- How much we expand the touchable region of the status bar below the notch to catch touches
that just start below the notch. --> that just start below the notch. -->
<dimen name="display_cutout_touchable_region_size">12dp</dimen> <dimen name="display_cutout_touchable_region_size">12dp</dimen>
<!-- The default margin used in immersive mode to capture the start of a swipe gesture from the
edge of the screen to show the system bars. -->
<dimen name="system_gestures_start_threshold">24dp</dimen>
<!-- Height of the bottom navigation bar frame; this is different than navigation_bar_height <!-- Height of the bottom navigation bar frame; this is different than navigation_bar_height
where that is the height reported to all the other windows to resize themselves around the where that is the height reported to all the other windows to resize themselves around the

View File

@@ -1745,6 +1745,7 @@
<java-symbol type="dimen" name="taskbar_frame_height" /> <java-symbol type="dimen" name="taskbar_frame_height" />
<java-symbol type="dimen" name="status_bar_height" /> <java-symbol type="dimen" name="status_bar_height" />
<java-symbol type="dimen" name="display_cutout_touchable_region_size" /> <java-symbol type="dimen" name="display_cutout_touchable_region_size" />
<java-symbol type="dimen" name="system_gestures_start_threshold" />
<java-symbol type="dimen" name="quick_qs_offset_height" /> <java-symbol type="dimen" name="quick_qs_offset_height" />
<java-symbol type="drawable" name="ic_jog_dial_sound_off" /> <java-symbol type="drawable" name="ic_jog_dial_sound_off" />
<java-symbol type="drawable" name="ic_jog_dial_sound_on" /> <java-symbol type="drawable" name="ic_jog_dial_sound_on" />

View File

@@ -3145,6 +3145,7 @@ public class DisplayPolicy {
pw.print(" mAllowLockscreenWhenOn="); pw.println(mAllowLockscreenWhenOn); pw.print(" mAllowLockscreenWhenOn="); pw.println(mAllowLockscreenWhenOn);
pw.print(prefix); pw.print("mRemoteInsetsControllerControlsSystemBars="); pw.print(prefix); pw.print("mRemoteInsetsControllerControlsSystemBars=");
pw.println(mDisplayContent.getInsetsPolicy().getRemoteInsetsControllerControlsSystemBars()); pw.println(mDisplayContent.getInsetsPolicy().getRemoteInsetsControllerControlsSystemBars());
mSystemGestures.dump(pw, prefix);
pw.print(prefix); pw.println("Looper state:"); pw.print(prefix); pw.println("Looper state:");
mHandler.getLooper().dump(new PrintWriterPrinter(pw), prefix + " "); mHandler.getLooper().dump(new PrintWriterPrinter(pw), prefix + " ");

View File

@@ -16,6 +16,12 @@
package com.android.server.wm; package com.android.server.wm;
import static android.view.DisplayCutout.BOUNDS_POSITION_BOTTOM;
import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT;
import static android.view.DisplayCutout.BOUNDS_POSITION_RIGHT;
import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
import android.annotation.NonNull;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
@@ -33,6 +39,8 @@ import android.view.MotionEvent;
import android.view.WindowManagerPolicyConstants.PointerEventListener; import android.view.WindowManagerPolicyConstants.PointerEventListener;
import android.widget.OverScroller; import android.widget.OverScroller;
import java.io.PrintWriter;
/** /**
* Listens for system-wide input gestures, firing callbacks when detected. * Listens for system-wide input gestures, firing callbacks when detected.
* @hide * @hide
@@ -54,7 +62,8 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
private final Context mContext; private final Context mContext;
private final Handler mHandler; private final Handler mHandler;
private int mDisplayCutoutTouchableRegionSize; private int mDisplayCutoutTouchableRegionSize;
private int mSwipeStartThreshold; // The thresholds for each edge of the display
private final Rect mSwipeStartThreshold = new Rect();
private int mSwipeDistanceThreshold; private int mSwipeDistanceThreshold;
private final Callbacks mCallbacks; private final Callbacks mCallbacks;
private final int[] mDownPointerId = new int[MAX_TRACKED_POINTERS]; private final int[] mDownPointerId = new int[MAX_TRACKED_POINTERS];
@@ -66,7 +75,6 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
int screenHeight; int screenHeight;
int screenWidth; int screenWidth;
private DisplayInfo mTmpDisplayInfo = new DisplayInfo();
private int mDownPointers; private int mDownPointers;
private boolean mSwipeFireable; private boolean mSwipeFireable;
private boolean mDebugFireable; private boolean mDebugFireable;
@@ -88,25 +96,39 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
void onConfigurationChanged() { void onConfigurationChanged() {
final Resources r = mContext.getResources(); final Resources r = mContext.getResources();
final int defaultThreshold = r.getDimensionPixelSize(
com.android.internal.R.dimen.system_gestures_start_threshold);
mSwipeStartThreshold.set(defaultThreshold, defaultThreshold, defaultThreshold,
defaultThreshold);
mSwipeDistanceThreshold = defaultThreshold;
final Display display = DisplayManagerGlobal.getInstance() final Display display = DisplayManagerGlobal.getInstance()
.getRealDisplay(Display.DEFAULT_DISPLAY); .getRealDisplay(Display.DEFAULT_DISPLAY);
display.getDisplayInfo(mTmpDisplayInfo);
mSwipeStartThreshold = mTmpDisplayInfo.logicalWidth > mTmpDisplayInfo.logicalHeight
? r.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height_landscape)
: r.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height_portrait);
final DisplayCutout displayCutout = display.getCutout(); final DisplayCutout displayCutout = display.getCutout();
if (displayCutout != null) { if (displayCutout != null) {
final Rect bounds = displayCutout.getBoundingRectTop(); // Expand swipe start threshold such that we can catch touches that just start beyond
if (!bounds.isEmpty()) {
// Expand swipe start threshold such that we can catch touches that just start below
// the notch area // the notch area
mDisplayCutoutTouchableRegionSize = r.getDimensionPixelSize( mDisplayCutoutTouchableRegionSize = r.getDimensionPixelSize(
com.android.internal.R.dimen.display_cutout_touchable_region_size); com.android.internal.R.dimen.display_cutout_touchable_region_size);
mSwipeStartThreshold += mDisplayCutoutTouchableRegionSize; final Rect[] bounds = displayCutout.getBoundingRectsAll();
if (bounds[BOUNDS_POSITION_LEFT] != null) {
mSwipeStartThreshold.left = Math.max(mSwipeStartThreshold.left,
bounds[BOUNDS_POSITION_LEFT].width() + mDisplayCutoutTouchableRegionSize);
}
if (bounds[BOUNDS_POSITION_TOP] != null) {
mSwipeStartThreshold.top = Math.max(mSwipeStartThreshold.top,
bounds[BOUNDS_POSITION_TOP].height() + mDisplayCutoutTouchableRegionSize);
}
if (bounds[BOUNDS_POSITION_RIGHT] != null) {
mSwipeStartThreshold.right = Math.max(mSwipeStartThreshold.right,
bounds[BOUNDS_POSITION_RIGHT].width() + mDisplayCutoutTouchableRegionSize);
}
if (bounds[BOUNDS_POSITION_BOTTOM] != null) {
mSwipeStartThreshold.bottom = Math.max(mSwipeStartThreshold.bottom,
bounds[BOUNDS_POSITION_BOTTOM].height()
+ mDisplayCutoutTouchableRegionSize);
} }
} }
mSwipeDistanceThreshold = mSwipeStartThreshold;
if (DEBUG) Slog.d(TAG, "mSwipeStartThreshold=" + mSwipeStartThreshold if (DEBUG) Slog.d(TAG, "mSwipeStartThreshold=" + mSwipeStartThreshold
+ " mSwipeDistanceThreshold=" + mSwipeDistanceThreshold); + " mSwipeDistanceThreshold=" + mSwipeDistanceThreshold);
} }
@@ -275,22 +297,22 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
final long elapsed = time - mDownTime[i]; final long elapsed = time - mDownTime[i];
if (DEBUG) Slog.d(TAG, "pointer " + mDownPointerId[i] if (DEBUG) Slog.d(TAG, "pointer " + mDownPointerId[i]
+ " moved (" + fromX + "->" + x + "," + fromY + "->" + y + ") in " + elapsed); + " moved (" + fromX + "->" + x + "," + fromY + "->" + y + ") in " + elapsed);
if (fromY <= mSwipeStartThreshold if (fromY <= mSwipeStartThreshold.top
&& y > fromY + mSwipeDistanceThreshold && y > fromY + mSwipeDistanceThreshold
&& elapsed < SWIPE_TIMEOUT_MS) { && elapsed < SWIPE_TIMEOUT_MS) {
return SWIPE_FROM_TOP; return SWIPE_FROM_TOP;
} }
if (fromY >= screenHeight - mSwipeStartThreshold if (fromY >= screenHeight - mSwipeStartThreshold.bottom
&& y < fromY - mSwipeDistanceThreshold && y < fromY - mSwipeDistanceThreshold
&& elapsed < SWIPE_TIMEOUT_MS) { && elapsed < SWIPE_TIMEOUT_MS) {
return SWIPE_FROM_BOTTOM; return SWIPE_FROM_BOTTOM;
} }
if (fromX >= screenWidth - mSwipeStartThreshold if (fromX >= screenWidth - mSwipeStartThreshold.right
&& x < fromX - mSwipeDistanceThreshold && x < fromX - mSwipeDistanceThreshold
&& elapsed < SWIPE_TIMEOUT_MS) { && elapsed < SWIPE_TIMEOUT_MS) {
return SWIPE_FROM_RIGHT; return SWIPE_FROM_RIGHT;
} }
if (fromX <= mSwipeStartThreshold if (fromX <= mSwipeStartThreshold.left
&& x > fromX + mSwipeDistanceThreshold && x > fromX + mSwipeDistanceThreshold
&& elapsed < SWIPE_TIMEOUT_MS) { && elapsed < SWIPE_TIMEOUT_MS) {
return SWIPE_FROM_LEFT; return SWIPE_FROM_LEFT;
@@ -298,6 +320,15 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
return SWIPE_NONE; return SWIPE_NONE;
} }
public void dump(@NonNull PrintWriter pw, @NonNull String prefix) {
final String inner = prefix + " ";
pw.println(prefix + TAG + ":");
pw.print(inner); pw.print("mDisplayCutoutTouchableRegionSize=");
pw.println(mDisplayCutoutTouchableRegionSize);
pw.print(inner); pw.print("mSwipeStartThreshold="); pw.println(mSwipeStartThreshold);
pw.print(inner); pw.print("mSwipeDistanceThreshold="); pw.println(mSwipeDistanceThreshold);
}
private final class FlingGestureDetector extends GestureDetector.SimpleOnGestureListener { private final class FlingGestureDetector extends GestureDetector.SimpleOnGestureListener {
private OverScroller mOverscroller; private OverScroller mOverscroller;