From 446df44b6e0c85e869fe69567952b6a98bf6cb57 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 10 May 2022 06:01:14 +0000 Subject: [PATCH 1/2] Refill all the dispatcher views when updating rotation - Due to a change in ordering, the button dispatcher list is not complete until after inflation and the nav bar controller notifies the view of the current nav mode. When this happens and the rotation button is updated, also update the list of views in the dispatcher list. Bug: 229708157 Test: Enabled 3 button, kill SysUI, rotate and verify button shows Change-Id: I20171f31cc485eb41a0def841e4b89b761bb63f2 --- .../systemui/navigationbar/NavigationBarInflaterView.java | 7 ++++++- .../android/systemui/navigationbar/NavigationBarView.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java index 4d9175b8db686..59bb2278edfea 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java @@ -168,6 +168,7 @@ public class NavigationBarInflaterView extends FrameLayout public void setButtonDispatchers(SparseArray buttonDispatchers) { mButtonDispatchers = buttonDispatchers; + clearDispatcherViews(); for (int i = 0; i < buttonDispatchers.size(); i++) { initiallyFill(buttonDispatchers.valueAt(i)); } @@ -454,12 +455,16 @@ public class NavigationBarInflaterView extends FrameLayout } } - private void clearViews() { + private void clearDispatcherViews() { if (mButtonDispatchers != null) { for (int i = 0; i < mButtonDispatchers.size(); i++) { mButtonDispatchers.valueAt(i).clear(); } } + } + + private void clearViews() { + clearDispatcherViews(); clearAllChildren(mHorizontal.findViewById(R.id.nav_buttons)); clearAllChildren(mVertical.findViewById(R.id.nav_buttons)); } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java index a13c199df41e0..d4539e2976ccf 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java @@ -538,6 +538,7 @@ public class NavigationBarView extends FrameLayout { mRotationButtonController.setRotationButton(mRotationContextButton, mRotationButtonListener); } + mNavigationInflaterView.setButtonDispatchers(mButtonDispatchers); } public KeyButtonDrawable getBackDrawable() { From 12914242774a4ef67f1c4c94e7c71af109578f88 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 10 May 2022 00:06:16 +0000 Subject: [PATCH 2/2] Use configuration for display rotation instead of display - Unlike configuration updates, there are no synchronization guarantees with when a context's display information is updated, so in rare cases where a seamless display rotation happens, the nav bar can be resized and layout can happen before the context's display registers the new rotation, and in such cases we fail to update the button order to keep the button in the same physical position on the device. Bug: 228398192 Test: Open camera in 3 button nav, rotate a bunch of times Change-Id: I2769bc3fb4c069071b6984a0a22dfbe13cf13450 --- .../navigationbar/NavigationBarView.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java index d4539e2976ccf..9cd007ee93120 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java @@ -317,7 +317,7 @@ public class NavigationBarView extends FrameLayout { R.drawable.ic_sysbar_rotate_button_ccw_start_90, R.drawable.ic_sysbar_rotate_button_cw_start_0, R.drawable.ic_sysbar_rotate_button_cw_start_90, - () -> getDisplay().getRotation()); + () -> mCurrentRotation); mConfiguration = new Configuration(); mTmpLastConfiguration = new Configuration(); @@ -979,15 +979,27 @@ public class NavigationBarView extends FrameLayout { return mCurrentRotation != rotation; } + private void updateCurrentRotation() { + final int rotation = mConfiguration.windowConfiguration.getDisplayRotation(); + if (mCurrentRotation == rotation) { + return; + } + mCurrentRotation = rotation; + mNavigationInflaterView.setAlternativeOrder(mCurrentRotation == Surface.ROTATION_90); + mDeadZone.onConfigurationChanged(mCurrentRotation); + if (DEBUG) { + Log.d(TAG, "updateCurrentRotation(): rot=" + mCurrentRotation); + } + } + private void updateCurrentView() { resetViews(); mCurrentView = mIsVertical ? mVertical : mHorizontal; mCurrentView.setVisibility(View.VISIBLE); mNavigationInflaterView.setVertical(mIsVertical); - mCurrentRotation = getContextDisplay().getRotation(); - mNavigationInflaterView.setAlternativeOrder(mCurrentRotation == Surface.ROTATION_90); mNavigationInflaterView.updateButtonDispatchersCurrentView(); updateLayoutTransitionsEnabled(); + updateCurrentRotation(); } private void resetViews() { @@ -1020,17 +1032,11 @@ public class NavigationBarView extends FrameLayout { public void reorient() { updateCurrentView(); - ((NavigationBarFrame) getRootView()).setDeadZone(mDeadZone); - mDeadZone.onConfigurationChanged(mCurrentRotation); // force the low profile & disabled states into compliance mBarTransitions.init(); - if (DEBUG) { - Log.d(TAG, "reorient(): rot=" + mCurrentRotation); - } - // Resolve layout direction if not resolved since components changing layout direction such // as changing languages will recreate this view and the direction will be resolved later if (!isLayoutDirectionResolved()) { @@ -1101,6 +1107,7 @@ public class NavigationBarView extends FrameLayout { boolean uiCarModeChanged = updateCarMode(); updateIcons(mTmpLastConfiguration); updateRecentsIcon(); + updateCurrentRotation(); mEdgeBackGestureHandler.onConfigurationChanged(mConfiguration); if (uiCarModeChanged || mTmpLastConfiguration.densityDpi != mConfiguration.densityDpi || mTmpLastConfiguration.getLayoutDirection() != mConfiguration.getLayoutDirection()) {