From 7859ecee1e498a5df3961329c02b96c5a2c59a37 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Wed, 13 Jul 2022 21:32:36 +0800 Subject: [PATCH] Try to fix stale mDisplaySize WM#getMaximumWindowMetrics#getBounds report max window bounds with the Configuration in Resources. However, EdgeBackGestureHandler#onConfigurationChanged counld not guarantee that WM#getMaximumWindowMetrics is updated because the configuration updates are not on the same Context, and also it Resources#getConfiguration. This CL applies the reported Configuration from #onConfigurationChanged callback to mDisplaySize directly. In this way, mDisplaySize is up-to-date with the latest configuration. Bug: 235711424 Test: manual - rotate the device dozens of times and check if mDisplaySize is updated. Change-Id: Iafeb1c580bb0c7b3680a5c32616754c00666768c --- .../navigationbar/gestural/EdgeBackGestureHandler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java index 3039d9d56c803..c6e5723c970b2 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java @@ -53,7 +53,6 @@ import android.view.MotionEvent; import android.view.Surface; import android.view.ViewConfiguration; import android.view.WindowManager; -import android.view.WindowMetrics; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; import com.android.internal.policy.GestureNavigationSettingsObserver; @@ -183,6 +182,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker private final IWindowManager mWindowManagerService; private final Optional mPipOptional; private final FalsingManager mFalsingManager; + private final Configuration mLastReportedConfig = new Configuration(); // Activities which should not trigger Back gesture. private final List mGestureBlockingActivities = new ArrayList<>(); @@ -334,6 +334,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker mFalsingManager = falsingManager; mLatencyTracker = latencyTracker; mFeatureFlags = featureFlags; + mLastReportedConfig.setTo(mContext.getResources().getConfiguration()); ComponentName recentsComponentName = ComponentName.unflattenFromString( context.getString(com.android.internal.R.string.config_recentsComponentName)); if (recentsComponentName != null) { @@ -885,12 +886,12 @@ public class EdgeBackGestureHandler extends CurrentUserTracker if (DEBUG_MISSING_GESTURE) { Log.d(DEBUG_MISSING_GESTURE_TAG, "Config changed: config=" + newConfig); } + mLastReportedConfig.updateFrom(newConfig); updateDisplaySize(); } private void updateDisplaySize() { - WindowMetrics metrics = mWindowManager.getMaximumWindowMetrics(); - Rect bounds = metrics.getBounds(); + Rect bounds = mLastReportedConfig.windowConfiguration.getMaxBounds(); mDisplaySize.set(bounds.width(), bounds.height()); if (DEBUG_MISSING_GESTURE) { Log.d(DEBUG_MISSING_GESTURE_TAG, "Update display size: mDisplaySize=" + mDisplaySize);