From e20798f2987ee4f706879ce52451dd884aa2c7ab Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 13 Apr 2021 10:03:49 -0700 Subject: [PATCH] Migrate to using config change to update bounds - There is a race between display manager updates and the display info (from the config) being updated. Bug: 184648245 Test: Rotate and verify the bounds update Test: atest AddConfigWidgetTest Change-Id: I6e2344692b858ba042814ba2a1c0e1f70156bfe5 --- .../systemui/navigationbar/NavigationBar.java | 39 +++++-------------- .../navigationbar/NavigationBarView.java | 1 + .../gestural/EdgeBackGestureHandler.java | 38 +++++++----------- 3 files changed, 25 insertions(+), 53 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java index be9d6bd6edd28..56375adb3d4e3 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java @@ -70,7 +70,6 @@ import android.database.ContentObserver; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.RectF; -import android.hardware.display.DisplayManager; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.Binder; @@ -160,7 +159,7 @@ import dagger.Lazy; */ public class NavigationBar implements View.OnAttachStateChangeListener, Callbacks, NavigationModeController.ModeChangedListener, - AccessibilityButtonModeObserver.ModeChangedListener, DisplayManager.DisplayListener { + AccessibilityButtonModeObserver.ModeChangedListener { public static final String TAG = "NavigationBar"; private static final boolean DEBUG = false; @@ -660,7 +659,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener, mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); if (mOrientationHandle != null) { resetSecondaryHandle(); - mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this); getBarTransitions().removeDarkIntensityListener(mOrientationHandleIntensityListener); mWindowManager.removeView(mOrientationHandle); mOrientationHandle.getViewTreeObserver().removeOnGlobalLayoutListener( @@ -699,7 +697,15 @@ public class NavigationBar implements View.OnAttachStateChangeListener, mLayoutDirection = ld; refreshLayout(ld); } + repositionNavigationBar(); + if (canShowSecondaryHandle()) { + int rotation = newConfig.windowConfiguration.getRotation(); + if (rotation != mCurrentRotation) { + mCurrentRotation = rotation; + orientSecondaryHomeHandle(); + } + } } private void initSecondaryHomeHandleForRotation() { @@ -707,9 +713,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener, return; } - mContext.getSystemService(DisplayManager.class) - .registerDisplayListener(this, new Handler(Looper.getMainLooper())); - mOrientationHandle = new QuickswitchOrientedNavHandle(mContext); mOrientationHandle.setId(R.id.secondary_home_handle); @@ -1604,30 +1607,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener, private final AccessibilityServicesStateChangeListener mAccessibilityListener = this::updateAccessibilityServicesState; - @Override - public void onDisplayAdded(int displayId) { - - } - - @Override - public void onDisplayRemoved(int displayId) { - - } - - @Override - public void onDisplayChanged(int displayId) { - if (!canShowSecondaryHandle()) { - return; - } - - int rotation = mContext.getResources().getConfiguration() - .windowConfiguration.getRotation(); - if (rotation != mCurrentRotation) { - mCurrentRotation = rotation; - orientSecondaryHomeHandle(); - } - } - private boolean canShowSecondaryHandle() { return mNavBarMode == NAV_BAR_MODE_GESTURAL && mOrientationHandle != null; } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java index a8c4d6ef9085d..2ca6a92ecc808 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java @@ -1186,6 +1186,7 @@ public class NavigationBarView extends FrameLayout implements boolean uiCarModeChanged = updateCarMode(); updateIcons(mTmpLastConfiguration); updateRecentsIcon(); + mEdgeBackGestureHandler.onConfigurationChanged(mConfiguration); mRecentsOnboarding.onConfigurationChanged(mConfiguration); if (uiCarModeChanged || mTmpLastConfiguration.densityDpi != mConfiguration.densityDpi || mTmpLastConfiguration.getLayoutDirection() != mConfiguration.getLayoutDirection()) { 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 b6a800f5e3a4e..806ea4fa147d6 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java @@ -20,6 +20,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.PixelFormat; import android.graphics.Point; @@ -50,6 +51,7 @@ import android.view.Surface; import android.view.ViewConfiguration; import android.view.WindowManager; import android.view.WindowManagerGlobal; +import android.view.WindowMetrics; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; import com.android.internal.policy.GestureNavigationSettingsObserver; @@ -86,8 +88,8 @@ import java.util.concurrent.Executor; /** * Utility class to handle edge swipes for back gesture */ -public class EdgeBackGestureHandler extends CurrentUserTracker implements DisplayListener, - PluginListener, ProtoTraceable { +public class EdgeBackGestureHandler extends CurrentUserTracker + implements PluginListener, ProtoTraceable { private static final String TAG = "EdgeBackGestureHandler"; private static final int MAX_LONG_PRESS_TIMEOUT = SystemProperties.getInt( @@ -123,7 +125,7 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa @Override public void onQuickSwitchToNewTask(@Surface.Rotation int rotation) { mStartingQuickstepRotation = rotation; - updateDisabledForQuickstep(); + updateDisabledForQuickstep(mContext.getResources().getConfiguration()); } }; @@ -414,7 +416,6 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa if (!mIsEnabled) { mGestureNavigationSettingsObserver.unregister(); - mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this); if (DEBUG_MISSING_GESTURE) { Log.d(DEBUG_MISSING_GESTURE_TAG, "Unregister display listener"); } @@ -433,8 +434,6 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa } else { mGestureNavigationSettingsObserver.register(); updateDisplaySize(); - mContext.getSystemService(DisplayManager.class).registerDisplayListener(this, - mContext.getMainThreadHandler()); if (DEBUG_MISSING_GESTURE) { Log.d(DEBUG_MISSING_GESTURE_TAG, "Register display listener"); } @@ -805,35 +804,28 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa Dependency.get(ProtoTracer.class).scheduleFrameUpdate(); } - private void updateDisabledForQuickstep() { - int rotation = mContext.getResources().getConfiguration().windowConfiguration.getRotation(); + private void updateDisabledForQuickstep(Configuration newConfig) { + int rotation = newConfig.windowConfiguration.getRotation(); mDisabledForQuickstep = mStartingQuickstepRotation > -1 && mStartingQuickstepRotation != rotation; } - @Override - public void onDisplayAdded(int displayId) { } - - @Override - public void onDisplayRemoved(int displayId) { } - - @Override - public void onDisplayChanged(int displayId) { + public void onConfigurationChanged(Configuration newConfig) { if (mStartingQuickstepRotation > -1) { - updateDisabledForQuickstep(); + updateDisabledForQuickstep(newConfig); } if (DEBUG_MISSING_GESTURE) { - Log.d(DEBUG_MISSING_GESTURE_TAG, "Display changed: mDisplayId=" + mDisplayId - + " displayId=" + displayId); - } - if (displayId == mDisplayId) { - updateDisplaySize(); + Log.d(DEBUG_MISSING_GESTURE_TAG, "Config changed: config=" + newConfig); } + updateDisplaySize(); } private void updateDisplaySize() { - mContext.getDisplay().getRealSize(mDisplaySize); + WindowMetrics metrics = mContext.getSystemService(WindowManager.class) + .getMaximumWindowMetrics(); + Rect bounds = metrics.getBounds(); + mDisplaySize.set(bounds.width(), bounds.height()); if (DEBUG_MISSING_GESTURE) { Log.d(DEBUG_MISSING_GESTURE_TAG, "Update display size: mDisplaySize=" + mDisplaySize); }