From 6c2921def3c96d2b5d491d7624024c7188481c75 Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Thu, 16 Mar 2023 12:09:57 +0000 Subject: [PATCH] Reland "Use non-cached value when calculation button forced visible state" This reverts commit afe3acbbdec745f24b6ea31161ac4687d25c898d. Previous landed patch caused nav bar added with a null insets frame size, and there's a bug the insets size won't get updated at runtime if it was null when added. Fixed the issue and reland the patch. Necessary modification was made to make sure the givenContentInsets and extended by cutout logic can be applied correctly. Reason for revert: Reland with Fix of the flaky test Test: SeamlessAppRotationTest Test: Check setup wizard as stated in b/268210882 Test: DisplayPolicyTests Test: DisplayPolicyInsetsTests Bug: 268210882 Change-Id: I3511bd87852a696a2ec09fe71d1cde90b84a5b66 --- .../android/view/InsetsFrameProvider.java | 16 ++++++++----- .../systemui/navigationbar/NavigationBar.java | 15 ++++-------- .../gestural/EdgeBackGestureHandler.java | 23 +++++++++++-------- .../com/android/server/wm/DisplayPolicy.java | 14 ++++------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/core/java/android/view/InsetsFrameProvider.java b/core/java/android/view/InsetsFrameProvider.java index 867d2b4625653..a2e0326c84b15 100644 --- a/core/java/android/view/InsetsFrameProvider.java +++ b/core/java/android/view/InsetsFrameProvider.java @@ -293,7 +293,7 @@ public class InsetsFrameProvider implements Parcelable { public static void calculateInsetsFrame(Rect displayFrame, Rect containerBounds, Rect displayCutoutSafe, Rect inOutFrame, int source, Insets insetsSize, @WindowManager.LayoutParams.PrivateFlags int privateFlags, - Insets displayCutoutSafeInsetsSize) { + Insets displayCutoutSafeInsetsSize, Rect givenContentInsets) { boolean extendByCutout = false; if (source == InsetsFrameProvider.SOURCE_DISPLAY) { inOutFrame.set(displayFrame); @@ -301,16 +301,20 @@ public class InsetsFrameProvider implements Parcelable { inOutFrame.set(containerBounds); } else { extendByCutout = (privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0; - } - if (insetsSize == null) { - return; + if (givenContentInsets != null) { + inOutFrame.inset(givenContentInsets); + } } if (displayCutoutSafeInsetsSize != null) { sTmpRect2.set(inOutFrame); } - calculateInsetsFrame(inOutFrame, insetsSize); + if (insetsSize != null) { + calculateInsetsFrame(inOutFrame, insetsSize); + } - if (extendByCutout) { + if (extendByCutout && insetsSize != null) { + // Only extend if the insets size is not null. Otherwise, the frame has already been + // extended by the display cutout during layout process. WindowLayout.extendFrameByCutout(displayCutoutSafe, displayFrame, inOutFrame, sTmpRect); } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java index 8a5bac8858b43..44c718f26a4a6 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java @@ -159,6 +159,8 @@ import com.android.systemui.util.ViewController; import com.android.wm.shell.back.BackAnimation; import com.android.wm.shell.pip.Pip; +import dagger.Lazy; + import java.io.PrintWriter; import java.util.Locale; import java.util.Map; @@ -167,8 +169,6 @@ import java.util.concurrent.Executor; import javax.inject.Inject; -import dagger.Lazy; - /** * Contains logic for a navigation bar view. */ @@ -245,12 +245,6 @@ public class NavigationBar extends ViewController implements private boolean mTransientShown; private boolean mTransientShownFromGestureOnSystemBar; - /** - * This is to indicate whether the navigation bar button is forced visible. This is true - * when the setup wizard is on display. When that happens, the window frame should be provided - * as insets size directly. - */ - private boolean mIsButtonForceVisible; private int mNavBarMode = NAV_BAR_MODE_3BUTTON; private LightBarController mLightBarController; private final LightBarController mMainLightBarController; @@ -679,8 +673,7 @@ public class NavigationBar extends ViewController implements mView.setTouchHandler(mTouchHandler); setNavBarMode(mNavBarMode); mEdgeBackGestureHandler.setStateChangeCallback(mView::updateStates); - mEdgeBackGestureHandler.setButtonForceVisibleChangeCallback((forceVisible) -> { - mIsButtonForceVisible = forceVisible; + mEdgeBackGestureHandler.setButtonForcedVisibleChangeCallback((forceVisible) -> { repositionNavigationBar(mCurrentRotation); }); mNavigationBarTransitions.addListener(this::onBarTransition); @@ -1721,7 +1714,7 @@ public class NavigationBar extends ViewController implements .setInsetsSizeOverrides(new InsetsFrameProvider.InsetsSizeOverride[] { new InsetsFrameProvider.InsetsSizeOverride( TYPE_INPUT_METHOD, null)}); - if (insetsHeight != -1 && !mIsButtonForceVisible) { + if (insetsHeight != -1 && !mEdgeBackGestureHandler.isButtonForcedVisible()) { navBarProvider.setInsetsSize(Insets.of(0, 0, 0, insetsHeight)); } 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 84d23c6a6f4aa..498d5c0dedb40 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java @@ -177,7 +177,7 @@ public class EdgeBackGestureHandler implements PluginListener mButtonForceVisibleCallback; + private Consumer mButtonForcedVisibleCallback; private final PluginManager mPluginManager; private final ProtoTracer mProtoTracer; @@ -245,7 +245,7 @@ public class EdgeBackGestureHandler implements PluginListener callback) { - mButtonForceVisibleCallback = callback; + public void setButtonForcedVisibleChangeCallback(Consumer callback) { + mButtonForcedVisibleCallback = callback; } public int getEdgeWidthLeft() { @@ -428,13 +428,14 @@ public class EdgeBackGestureHandler implements PluginListener frameProvider = - getFrameProvider(win, provider, i); + getFrameProvider(win, i); final InsetsFrameProvider.InsetsSizeOverride[] overrides = provider.getInsetsSizeOverrides(); final SparseArray> @@ -1095,19 +1094,15 @@ public class DisplayPolicy { } } - @Nullable private TriConsumer getFrameProvider(WindowState win, - InsetsFrameProvider provider, int index) { - if (provider.getInsetsSize() == null && provider.getSource() == SOURCE_FRAME) { - return null; - } + int index) { return (displayFrames, windowContainer, inOutFrame) -> { final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation); final InsetsFrameProvider ifp = lp.providedInsets[index]; InsetsFrameProvider.calculateInsetsFrame(displayFrames.mUnrestricted, windowContainer.getBounds(), displayFrames.mDisplayCutoutSafe, inOutFrame, ifp.getSource(), ifp.getInsetsSize(), lp.privateFlags, - ifp.getMinimalInsetsSizeInDisplayCutoutSafe()); + ifp.getMinimalInsetsSizeInDisplayCutoutSafe(), win.mGivenContentInsets); }; } @@ -1120,7 +1115,8 @@ public class DisplayPolicy { InsetsFrameProvider.calculateInsetsFrame(displayFrames.mUnrestricted, windowContainer.getBounds(), displayFrames.mDisplayCutoutSafe, inOutFrame, ifp.getSource(), ifp.getInsetsSizeOverrides()[overrideIndex].getInsetsSize(), - lp.privateFlags, null /* displayCutoutSafeInsetsSize */); + lp.privateFlags, null /* displayCutoutSafeInsetsSize */, + null /* givenContentInsets */); }; }