Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c2921de authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Reland "Use non-cached value when calculation button forced visible state"

This reverts commit afe3acbb.

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
parent 736bea3f
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -293,7 +293,7 @@ public class InsetsFrameProvider implements Parcelable {
    public static void calculateInsetsFrame(Rect displayFrame, Rect containerBounds,
    public static void calculateInsetsFrame(Rect displayFrame, Rect containerBounds,
            Rect displayCutoutSafe, Rect inOutFrame, int source, Insets insetsSize,
            Rect displayCutoutSafe, Rect inOutFrame, int source, Insets insetsSize,
            @WindowManager.LayoutParams.PrivateFlags int privateFlags,
            @WindowManager.LayoutParams.PrivateFlags int privateFlags,
            Insets displayCutoutSafeInsetsSize) {
            Insets displayCutoutSafeInsetsSize, Rect givenContentInsets) {
        boolean extendByCutout = false;
        boolean extendByCutout = false;
        if (source == InsetsFrameProvider.SOURCE_DISPLAY) {
        if (source == InsetsFrameProvider.SOURCE_DISPLAY) {
            inOutFrame.set(displayFrame);
            inOutFrame.set(displayFrame);
@@ -301,16 +301,20 @@ public class InsetsFrameProvider implements Parcelable {
            inOutFrame.set(containerBounds);
            inOutFrame.set(containerBounds);
        } else {
        } else {
            extendByCutout = (privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0;
            extendByCutout = (privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0;
            if (givenContentInsets != null) {
                inOutFrame.inset(givenContentInsets);
            }
            }
        if (insetsSize == null) {
            return;
        }
        }
        if (displayCutoutSafeInsetsSize != null) {
        if (displayCutoutSafeInsetsSize != null) {
            sTmpRect2.set(inOutFrame);
            sTmpRect2.set(inOutFrame);
        }
        }
        if (insetsSize != null) {
            calculateInsetsFrame(inOutFrame, insetsSize);
            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);
            WindowLayout.extendFrameByCutout(displayCutoutSafe, displayFrame, inOutFrame, sTmpRect);
        }
        }


+4 −11
Original line number Original line Diff line number Diff line
@@ -159,6 +159,8 @@ import com.android.systemui.util.ViewController;
import com.android.wm.shell.back.BackAnimation;
import com.android.wm.shell.back.BackAnimation;
import com.android.wm.shell.pip.Pip;
import com.android.wm.shell.pip.Pip;


import dagger.Lazy;

import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Locale;
import java.util.Map;
import java.util.Map;
@@ -167,8 +169,6 @@ import java.util.concurrent.Executor;


import javax.inject.Inject;
import javax.inject.Inject;


import dagger.Lazy;

/**
/**
 * Contains logic for a navigation bar view.
 * Contains logic for a navigation bar view.
 */
 */
@@ -245,12 +245,6 @@ public class NavigationBar extends ViewController<NavigationBarView> implements


    private boolean mTransientShown;
    private boolean mTransientShown;
    private boolean mTransientShownFromGestureOnSystemBar;
    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 int mNavBarMode = NAV_BAR_MODE_3BUTTON;
    private LightBarController mLightBarController;
    private LightBarController mLightBarController;
    private final LightBarController mMainLightBarController;
    private final LightBarController mMainLightBarController;
@@ -679,8 +673,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        mView.setTouchHandler(mTouchHandler);
        mView.setTouchHandler(mTouchHandler);
        setNavBarMode(mNavBarMode);
        setNavBarMode(mNavBarMode);
        mEdgeBackGestureHandler.setStateChangeCallback(mView::updateStates);
        mEdgeBackGestureHandler.setStateChangeCallback(mView::updateStates);
        mEdgeBackGestureHandler.setButtonForceVisibleChangeCallback((forceVisible) -> {
        mEdgeBackGestureHandler.setButtonForcedVisibleChangeCallback((forceVisible) -> {
            mIsButtonForceVisible = forceVisible;
            repositionNavigationBar(mCurrentRotation);
            repositionNavigationBar(mCurrentRotation);
        });
        });
        mNavigationBarTransitions.addListener(this::onBarTransition);
        mNavigationBarTransitions.addListener(this::onBarTransition);
@@ -1721,7 +1714,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
                        .setInsetsSizeOverrides(new InsetsFrameProvider.InsetsSizeOverride[] {
                        .setInsetsSizeOverrides(new InsetsFrameProvider.InsetsSizeOverride[] {
                                new InsetsFrameProvider.InsetsSizeOverride(
                                new InsetsFrameProvider.InsetsSizeOverride(
                                        TYPE_INPUT_METHOD, null)});
                                        TYPE_INPUT_METHOD, null)});
        if (insetsHeight != -1 && !mIsButtonForceVisible) {
        if (insetsHeight != -1 && !mEdgeBackGestureHandler.isButtonForcedVisible()) {
            navBarProvider.setInsetsSize(Insets.of(0, 0, 0, insetsHeight));
            navBarProvider.setInsetsSize(Insets.of(0, 0, 0, insetsHeight));
        }
        }


+14 −9
Original line number Original line Diff line number Diff line
@@ -177,7 +177,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
    private final OverviewProxyService mOverviewProxyService;
    private final OverviewProxyService mOverviewProxyService;
    private final SysUiState mSysUiState;
    private final SysUiState mSysUiState;
    private Runnable mStateChangeCallback;
    private Runnable mStateChangeCallback;
    private Consumer<Boolean> mButtonForceVisibleCallback;
    private Consumer<Boolean> mButtonForcedVisibleCallback;


    private final PluginManager mPluginManager;
    private final PluginManager mPluginManager;
    private final ProtoTracer mProtoTracer;
    private final ProtoTracer mProtoTracer;
@@ -245,7 +245,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
    private boolean mGestureBlockingActivityRunning;
    private boolean mGestureBlockingActivityRunning;
    private boolean mIsNewBackAffordanceEnabled;
    private boolean mIsNewBackAffordanceEnabled;
    private boolean mIsTrackpadGestureFeaturesEnabled;
    private boolean mIsTrackpadGestureFeaturesEnabled;
    private boolean mIsButtonForceVisible;
    private boolean mIsButtonForcedVisible;


    private InputMonitor mInputMonitor;
    private InputMonitor mInputMonitor;
    private InputChannelCompat.InputEventReceiver mInputEventReceiver;
    private InputChannelCompat.InputEventReceiver mInputEventReceiver;
@@ -412,8 +412,8 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        mStateChangeCallback = callback;
        mStateChangeCallback = callback;
    }
    }


    public void setButtonForceVisibleChangeCallback(Consumer<Boolean> callback) {
    public void setButtonForcedVisibleChangeCallback(Consumer<Boolean> callback) {
        mButtonForceVisibleCallback = callback;
        mButtonForcedVisibleCallback = callback;
    }
    }


    public int getEdgeWidthLeft() {
    public int getEdgeWidthLeft() {
@@ -428,13 +428,14 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        Resources res = mNavigationModeController.getCurrentUserContext().getResources();
        Resources res = mNavigationModeController.getCurrentUserContext().getResources();
        mEdgeWidthLeft = mGestureNavigationSettingsObserver.getLeftSensitivity(res);
        mEdgeWidthLeft = mGestureNavigationSettingsObserver.getLeftSensitivity(res);
        mEdgeWidthRight = mGestureNavigationSettingsObserver.getRightSensitivity(res);
        mEdgeWidthRight = mGestureNavigationSettingsObserver.getRightSensitivity(res);
        final boolean previousForceVisible = mIsButtonForceVisible;
        final boolean previousForcedVisible = mIsButtonForcedVisible;
        mIsButtonForceVisible =
        mIsButtonForcedVisible =
                mGestureNavigationSettingsObserver.areNavigationButtonForcedVisible();
                mGestureNavigationSettingsObserver.areNavigationButtonForcedVisible();
        if (previousForceVisible != mIsButtonForceVisible && mButtonForceVisibleCallback != null) {
        if (previousForcedVisible != mIsButtonForcedVisible
            mButtonForceVisibleCallback.accept(mIsButtonForceVisible);
                && mButtonForcedVisibleCallback != null) {
            mButtonForcedVisibleCallback.accept(mIsButtonForcedVisible);
        }
        }
        mIsBackGestureAllowed = !mIsButtonForceVisible;
        mIsBackGestureAllowed = !mIsButtonForcedVisible;


        final DisplayMetrics dm = res.getDisplayMetrics();
        final DisplayMetrics dm = res.getDisplayMetrics();
        final float defaultGestureHeight = res.getDimension(
        final float defaultGestureHeight = res.getDimension(
@@ -635,6 +636,10 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
        return mIsEnabled && mIsBackGestureAllowed;
        return mIsEnabled && mIsBackGestureAllowed;
    }
    }


    public boolean isButtonForcedVisible() {
        return mIsButtonForcedVisible;
    }

    /**
    /**
     * Update the PiP bounds, used for exclusion calculation.
     * Update the PiP bounds, used for exclusion calculation.
     */
     */
+5 −9
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.view.Display.TYPE_INTERNAL;
import static android.view.Display.TYPE_INTERNAL;
import static android.view.InsetsFrameProvider.SOURCE_FRAME;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
@@ -1069,7 +1068,7 @@ public class DisplayPolicy {
                // runtime as ensured in WMS. Make use of the index in the provider directly
                // runtime as ensured in WMS. Make use of the index in the provider directly
                // to access the latest provided size at runtime.
                // to access the latest provided size at runtime.
                final TriConsumer<DisplayFrames, WindowContainer, Rect> frameProvider =
                final TriConsumer<DisplayFrames, WindowContainer, Rect> frameProvider =
                        getFrameProvider(win, provider, i);
                        getFrameProvider(win, i);
                final InsetsFrameProvider.InsetsSizeOverride[] overrides =
                final InsetsFrameProvider.InsetsSizeOverride[] overrides =
                        provider.getInsetsSizeOverrides();
                        provider.getInsetsSizeOverrides();
                final SparseArray<TriConsumer<DisplayFrames, WindowContainer, Rect>>
                final SparseArray<TriConsumer<DisplayFrames, WindowContainer, Rect>>
@@ -1095,19 +1094,15 @@ public class DisplayPolicy {
        }
        }
    }
    }


    @Nullable
    private TriConsumer<DisplayFrames, WindowContainer, Rect> getFrameProvider(WindowState win,
    private TriConsumer<DisplayFrames, WindowContainer, Rect> getFrameProvider(WindowState win,
            InsetsFrameProvider provider, int index) {
            int index) {
        if (provider.getInsetsSize() == null && provider.getSource() == SOURCE_FRAME) {
            return null;
        }
        return (displayFrames, windowContainer, inOutFrame) -> {
        return (displayFrames, windowContainer, inOutFrame) -> {
            final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation);
            final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation);
            final InsetsFrameProvider ifp = lp.providedInsets[index];
            final InsetsFrameProvider ifp = lp.providedInsets[index];
            InsetsFrameProvider.calculateInsetsFrame(displayFrames.mUnrestricted,
            InsetsFrameProvider.calculateInsetsFrame(displayFrames.mUnrestricted,
                    windowContainer.getBounds(), displayFrames.mDisplayCutoutSafe, inOutFrame,
                    windowContainer.getBounds(), displayFrames.mDisplayCutoutSafe, inOutFrame,
                    ifp.getSource(), ifp.getInsetsSize(), lp.privateFlags,
                    ifp.getSource(), ifp.getInsetsSize(), lp.privateFlags,
                    ifp.getMinimalInsetsSizeInDisplayCutoutSafe());
                    ifp.getMinimalInsetsSizeInDisplayCutoutSafe(), win.mGivenContentInsets);
        };
        };
    }
    }


@@ -1120,7 +1115,8 @@ public class DisplayPolicy {
            InsetsFrameProvider.calculateInsetsFrame(displayFrames.mUnrestricted,
            InsetsFrameProvider.calculateInsetsFrame(displayFrames.mUnrestricted,
                    windowContainer.getBounds(), displayFrames.mDisplayCutoutSafe, inOutFrame,
                    windowContainer.getBounds(), displayFrames.mDisplayCutoutSafe, inOutFrame,
                    ifp.getSource(), ifp.getInsetsSizeOverrides()[overrideIndex].getInsetsSize(),
                    ifp.getSource(), ifp.getInsetsSizeOverrides()[overrideIndex].getInsetsSize(),
                    lp.privateFlags, null /* displayCutoutSafeInsetsSize */);
                    lp.privateFlags, null /* displayCutoutSafeInsetsSize */,
                    null /* givenContentInsets */);
        };
        };
    }
    }