From 5616af887ec7a4b00086710e20db312ab9db0d12 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 1 Jun 2021 22:24:12 -0700 Subject: [PATCH] Fix issue with system gesture areas being too large - Currently, SystemGesturesPointerEventListener config change is only called when initializing and if the overlays change, which causes the swipe threshold to be adjusted for the display cutout touchable region in the other orientations as well. In addition, the context used to pull the status bar height is not updated on config changes which results the portrait status bar height to be used for landscape gesture recognition as well (the same height is used for both status and nav bar thresholds). Together, these two issues make the swipe area almost 3x larger, which conflicts with immersive games. Instead, we should load the right status bar height based on the current orientation, and also update the thresholds when the display info changes. Bug: 189220056 Test: Enable a display cutout on the device, open a game and try to swipe up near the edge Change-Id: Ic573da624756768f8b7b600831eb0b7964720760 --- .../com/android/server/wm/DisplayPolicy.java | 3 +-- .../wm/SystemGesturesPointerEventListener.java | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 70f2d64e89aa4..977df93412f88 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -1453,8 +1453,7 @@ public class DisplayPolicy { } void onDisplayInfoChanged(DisplayInfo info) { - mSystemGestures.screenWidth = info.logicalWidth; - mSystemGestures.screenHeight = info.logicalHeight; + mSystemGestures.onDisplayInfoChanged(info); } private void layoutStatusBar(DisplayFrames displayFrames, Rect contentFrame) { diff --git a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java index f3859b41b6fd3..513b1b715a27d 100644 --- a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java +++ b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java @@ -17,6 +17,7 @@ package com.android.server.wm; import android.content.Context; +import android.content.res.Resources; import android.graphics.Rect; import android.graphics.Region; import android.hardware.display.DisplayManagerGlobal; @@ -65,6 +66,7 @@ class SystemGesturesPointerEventListener implements PointerEventListener { int screenHeight; int screenWidth; + private DisplayInfo mTmpDisplayInfo = new DisplayInfo(); private int mDownPointers; private boolean mSwipeFireable; private boolean mDebugFireable; @@ -75,23 +77,31 @@ class SystemGesturesPointerEventListener implements PointerEventListener { mContext = checkNull("context", context); mHandler = handler; mCallbacks = checkNull("callbacks", callbacks); + onConfigurationChanged(); + } + void onDisplayInfoChanged(DisplayInfo info) { + screenWidth = info.logicalWidth; + screenHeight = info.logicalHeight; onConfigurationChanged(); } void onConfigurationChanged() { - mSwipeStartThreshold = mContext.getResources() - .getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); - + final Resources r = mContext.getResources(); final Display display = DisplayManagerGlobal.getInstance() .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(); if (displayCutout != null) { final Rect bounds = displayCutout.getBoundingRectTop(); if (!bounds.isEmpty()) { // Expand swipe start threshold such that we can catch touches that just start below // the notch area - mDisplayCutoutTouchableRegionSize = mContext.getResources().getDimensionPixelSize( + mDisplayCutoutTouchableRegionSize = r.getDimensionPixelSize( com.android.internal.R.dimen.display_cutout_touchable_region_size); mSwipeStartThreshold += mDisplayCutoutTouchableRegionSize; }