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

Commit d8d93355 authored by Jorge Gil's avatar Jorge Gil
Browse files

Force consume caption bar insets in freeform immersive

Adds top padding to DecorView equal to the caption inset when a freeform
window has FULLSCREEN sysUiVisibility is requested. This is to ensure
that the forced-visible caption doesn't occlude app content when a
freeform app tries to enter immersive mode but remains in freeform.

Bug: 316231589
Test: atest WmTests WMShellUnitTests
Flag: com.android.window.flags.enable_caption_compat_inset_force_consumption

Change-Id: I4a4b20591ef6690dba1eaa16abe5f7310597042b
parent bdecc118
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -162,6 +162,12 @@ public class InsetsFrameProvider implements Parcelable {
        return mSource;
    }

    /** Set the flags of this provider. */
    public InsetsFrameProvider setFlags(@Flags int flags) {
        mFlags = flags;
        return this;
    }

    public InsetsFrameProvider setFlags(@Flags int flags, @Flags int mask) {
        mFlags = (mFlags & ~mask) | (flags & mask);
        return this;
+14 −1
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK
import static com.android.text.flags.Flags.disableHandwritingInitiatorForIme;
import static com.android.window.flags.Flags.activityWindowInfoFlag;
import static com.android.window.flags.Flags.enableBufferTransformHintFromDisplay;
import static com.android.window.flags.Flags.enableCaptionCompatInsetForceConsumption;
import static com.android.window.flags.Flags.insetsControlChangedItem;
import static com.android.window.flags.Flags.insetsControlSeq;
import static com.android.window.flags.Flags.setScPropertiesInClient;
@@ -3187,7 +3188,9 @@ public final class ViewRootImpl implements ViewParent,
        inOutParams.privateFlags &= ~PRIVATE_FLAG_FIT_INSETS_CONTROLLED;
    }
    private void controlInsetsForCompatibility(WindowManager.LayoutParams params) {
    /** Updates the {@link InsetsType}s to hide or show based on layout params. */
    @VisibleForTesting
    public void controlInsetsForCompatibility(WindowManager.LayoutParams params) {
        final int sysUiVis = params.systemUiVisibility | params.subtreeSystemUiVisibility;
        final int flags = params.flags;
        final boolean matchParent = params.width == MATCH_PARENT && params.height == MATCH_PARENT;
@@ -3198,6 +3201,9 @@ public final class ViewRootImpl implements ViewParent,
                || ((flags & FLAG_FULLSCREEN) != 0 && matchParent && nonAttachedAppWindow);
        final boolean navWasHiddenByFlags = (mTypesHiddenByFlags & Type.navigationBars()) != 0;
        final boolean navIsHiddenByFlags = (sysUiVis & SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
        final boolean captionWasHiddenByFlags = (mTypesHiddenByFlags & Type.captionBar()) != 0;
        final boolean captionIsHiddenByFlags = (sysUiVis & SYSTEM_UI_FLAG_FULLSCREEN) != 0
                || ((flags & FLAG_FULLSCREEN) != 0 && matchParent && nonAttachedAppWindow);
        @InsetsType int typesToHide = 0;
        @InsetsType int typesToShow = 0;
@@ -3211,6 +3217,13 @@ public final class ViewRootImpl implements ViewParent,
        } else if (!navIsHiddenByFlags && navWasHiddenByFlags) {
            typesToShow |= Type.navigationBars();
        }
        if (captionIsHiddenByFlags && !captionWasHiddenByFlags
                && enableCaptionCompatInsetForceConsumption()) {
            typesToHide |= Type.captionBar();
        } else if (!captionIsHiddenByFlags && captionWasHiddenByFlags
                && enableCaptionCompatInsetForceConsumption()) {
            typesToShow |= Type.captionBar();
        }
        if (typesToHide != 0) {
            getInsetsController().hide(typesToHide);
        }
+5 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArrayMap;
import android.view.InsetsFrameProvider;
import android.view.InsetsSource;
import android.view.SurfaceControl;
import android.view.WindowInsets.Type.InsetsType;

@@ -711,14 +712,16 @@ public final class WindowContainerTransaction implements Parcelable {
    @NonNull
    public WindowContainerTransaction addInsetsSource(
            @NonNull WindowContainerToken receiver,
            IBinder owner, int index, @InsetsType int type, Rect frame, Rect[] boundingRects) {
            IBinder owner, int index, @InsetsType int type, Rect frame, Rect[] boundingRects,
            @InsetsSource.Flags int flags) {
        final HierarchyOp hierarchyOp =
                new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER)
                        .setContainer(receiver.asBinder())
                        .setInsetsFrameProvider(new InsetsFrameProvider(owner, index, type)
                                .setSource(InsetsFrameProvider.SOURCE_ARBITRARY_RECTANGLE)
                                .setArbitraryRectangle(frame)
                                .setBoundingRects(boundingRects))
                                .setBoundingRects(boundingRects)
                                .setFlags(flags))
                        .setInsetsFrameOwner(owner)
                        .build();
        mHierarchyOps.add(hierarchyOp);
+16 −3
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ import com.android.internal.view.menu.MenuHelper;
import com.android.internal.widget.ActionBarContextView;
import com.android.internal.widget.BackgroundFallback;
import com.android.internal.widget.floatingtoolbar.FloatingToolbar;
import com.android.window.flags.Flags;

import java.util.List;
import java.util.function.Consumer;
@@ -1193,7 +1194,8 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
        // If we should always consume system bars, only consume that if the app wanted to go to
        // fullscreen, as otherwise we can expect the app to handle it.
        boolean fullscreen = (sysUiVisibility & SYSTEM_UI_FLAG_FULLSCREEN) != 0
                || (attrs.flags & FLAG_FULLSCREEN) != 0
                || (attrs.flags & FLAG_FULLSCREEN) != 0;
        final boolean hideStatusBar = fullscreen
                || (requestedVisibleTypes & WindowInsets.Type.statusBars()) == 0;
        boolean consumingStatusBar =
                ((sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == 0
@@ -1203,9 +1205,20 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
                        && mForceWindowDrawsBarBackgrounds
                        && mLastTopInset != 0)
                || ((mLastForceConsumingTypes & WindowInsets.Type.statusBars()) != 0
                        && fullscreen);
                        && hideStatusBar);

        int consumedTop = consumingStatusBar ? mLastTopInset : 0;
        final boolean hideCaptionBar = fullscreen
                || (requestedVisibleTypes & WindowInsets.Type.captionBar()) == 0;
        final boolean consumingCaptionBar =
                ((mLastForceConsumingTypes & WindowInsets.Type.captionBar()) != 0
                        && hideCaptionBar);

        final int consumedTop;
        if (Flags.enableCaptionCompatInsetForceConsumption()) {
            consumedTop = (consumingStatusBar || consumingCaptionBar) ? mLastTopInset : 0;
        } else {
            consumedTop = consumingStatusBar ? mLastTopInset : 0;
        }
        int consumedRight = consumingNavBar ? mLastRightInset : 0;
        int consumedBottom = consumingNavBar ? mLastBottomInset : 0;
        int consumedLeft = consumingNavBar ? mLastLeftInset : 0;
+2 −1
Original line number Diff line number Diff line
@@ -535,7 +535,8 @@ public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener {
        WindowContainerTransaction wct = new WindowContainerTransaction();
        if (mCaptionInsets != null) {
            wct.addInsetsSource(mTaskToken, mCaptionInsetsOwner, 0,
                    WindowInsets.Type.captionBar(), mCaptionInsets, null /* boundingRects */);
                    WindowInsets.Type.captionBar(), mCaptionInsets, null /* boundingRects */,
                    0 /* flags */);
        } else {
            wct.removeInsetsSource(mTaskToken, mCaptionInsetsOwner, 0,
                    WindowInsets.Type.captionBar());
Loading