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

Commit 244e9600 authored by Tiger's avatar Tiger
Browse files

Introduce the flags of the insets source

This enables us to control the behavior of a specific insets source. The
first flag added in this CL is FLAG_SUPPRESS_SCRIM. If the insets source
owner sets this flag, the system won't draw a semi-transparent scrim at
the insets area.

Fix: 197615177
Test: Open a work-profile app with gesture nav bar. See if there is no
      scrim at the nav bar area.
Change-Id: I32449805f47ba6c44e6eec7b512a6b1a0833371e
parent 36fef761
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -480,9 +480,9 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                    : inset != 0;

            if (outState != null && source != null) {
                outState.getOrCreateSource(source.getId(), source.getType())
                outState.addSource(new InsetsSource(source)
                        .setVisible(visible)
                        .setFrame(mTmpFrame);
                        .setFrame(mTmpFrame));
            }

            // If the system is controlling the insets source, the leash can be null.
+22 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.graphics.Rect;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.InsetsSource.Flags;
import android.view.WindowInsets.Type.InsetsType;

import java.util.Arrays;
@@ -85,6 +86,13 @@ public class InsetsFrameProvider implements Parcelable {
     */
    private Insets mInsetsSize = null;

    /**
     * Various behavioral options/flags. Default is none.
     *
     * @see Flags
     */
    private @Flags int mFlags;

    /**
     * If null, the size set in insetsSize will be applied to all window types. If it contains
     * element of some types, the insets reported to the window with that types will be overridden.
@@ -149,6 +157,15 @@ public class InsetsFrameProvider implements Parcelable {
        return mSource;
    }

    public InsetsFrameProvider setFlags(@Flags int flags, @Flags int mask) {
        mFlags = (mFlags & ~mask) | (flags & mask);
        return this;
    }

    public @Flags int getFlags() {
        return mFlags;
    }

    public InsetsFrameProvider setInsetsSize(Insets insetsSize) {
        mInsetsSize = insetsSize;
        return this;
@@ -198,6 +215,7 @@ public class InsetsFrameProvider implements Parcelable {
        sb.append(", index=").append(mIndex);
        sb.append(", type=").append(WindowInsets.Type.toString(mType));
        sb.append(", source=").append(sourceToString(mSource));
        sb.append(", flags=[").append(InsetsSource.flagsToString(mFlags)).append("]");
        if (mInsetsSize != null) {
            sb.append(", insetsSize=").append(mInsetsSize);
        }
@@ -230,6 +248,7 @@ public class InsetsFrameProvider implements Parcelable {
        mIndex = in.readInt();
        mType = in.readInt();
        mSource = in.readInt();
        mFlags = in.readInt();
        mInsetsSize = in.readTypedObject(Insets.CREATOR);
        mInsetsSizeOverrides = in.createTypedArray(InsetsSizeOverride.CREATOR);
        mArbitraryRectangle = in.readTypedObject(Rect.CREATOR);
@@ -241,6 +260,7 @@ public class InsetsFrameProvider implements Parcelable {
        out.writeInt(mIndex);
        out.writeInt(mType);
        out.writeInt(mSource);
        out.writeInt(mFlags);
        out.writeTypedObject(mInsetsSize, flags);
        out.writeTypedArray(mInsetsSizeOverrides, flags);
        out.writeTypedObject(mArbitraryRectangle, flags);
@@ -260,7 +280,7 @@ public class InsetsFrameProvider implements Parcelable {
        }
        final InsetsFrameProvider other = (InsetsFrameProvider) o;
        return Objects.equals(mOwner, other.mOwner) && mIndex == other.mIndex
                && mType == other.mType && mSource == other.mSource
                && mType == other.mType && mSource == other.mSource && mFlags == other.mFlags
                && Objects.equals(mInsetsSize, other.mInsetsSize)
                && Arrays.equals(mInsetsSizeOverrides, other.mInsetsSizeOverrides)
                && Objects.equals(mArbitraryRectangle, other.mArbitraryRectangle);
@@ -268,7 +288,7 @@ public class InsetsFrameProvider implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mOwner, mIndex, mType, mSource, mInsetsSize,
        return Objects.hash(mOwner, mIndex, mType, mSource, mFlags, mInsetsSize,
                Arrays.hashCode(mInsetsSizeOverrides), mArbitraryRectangle);
    }

+48 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.view.InsetsSourceProto.VISIBLE;
import static android.view.InsetsSourceProto.VISIBLE_FRAME;
import static android.view.WindowInsets.Type.ime;

import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -33,7 +34,10 @@ import android.util.proto.ProtoOutputStream;
import android.view.WindowInsets.Type.InsetsType;

import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * Represents the state of a single entity generating insets for clients.
@@ -44,6 +48,24 @@ public class InsetsSource implements Parcelable {
    /** The insets source ID of IME */
    public static final int ID_IME = createId(null, 0, ime());

    /**
     * Controls whether this source suppresses the scrim. If the scrim is ignored, the system won't
     * draw a semi-transparent scrim behind the system bar area even when the bar contrast is
     * enforced.
     *
     * @see android.R.styleable#Window_enforceStatusBarContrast
     * @see android.R.styleable#Window_enforceNavigationBarContrast
     */
    public static final int FLAG_SUPPRESS_SCRIM = 1;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true, prefix = "FLAG_", value = {
            FLAG_SUPPRESS_SCRIM,
    })
    public @interface Flags {}

    private @Flags int mFlags;

    /**
     * An unique integer to identify this source across processes.
     */
@@ -75,6 +97,7 @@ public class InsetsSource implements Parcelable {
        mVisibleFrame = other.mVisibleFrame != null
                ? new Rect(other.mVisibleFrame)
                : null;
        mFlags = other.mFlags;
        mInsetsRoundedCornerFrame = other.mInsetsRoundedCornerFrame;
    }

@@ -84,6 +107,7 @@ public class InsetsSource implements Parcelable {
        mVisibleFrame = other.mVisibleFrame != null
                ? new Rect(other.mVisibleFrame)
                : null;
        mFlags = other.mFlags;
        mInsetsRoundedCornerFrame = other.mInsetsRoundedCornerFrame;
    }

@@ -107,6 +131,11 @@ public class InsetsSource implements Parcelable {
        return this;
    }

    public InsetsSource setFlags(@Flags int flags) {
        mFlags = flags;
        return this;
    }

    public int getId() {
        return mId;
    }
@@ -127,6 +156,10 @@ public class InsetsSource implements Parcelable {
        return mVisible;
    }

    public @Flags int getFlags() {
        return mFlags;
    }

    boolean isUserControllable() {
        // If mVisibleFrame is null, it will be the same area as mFrame.
        return mVisibleFrame == null || !mVisibleFrame.isEmpty();
@@ -254,6 +287,14 @@ public class InsetsSource implements Parcelable {
                + WindowInsets.Type.indexOf(type);
    }

    public static String flagsToString(@Flags int flags) {
        final StringJoiner joiner = new StringJoiner(" ");
        if ((flags & FLAG_SUPPRESS_SCRIM) != 0) {
            joiner.add("SUPPRESS_SCRIM");
        }
        return joiner.toString();
    }

    /**
     * Export the state of {@link InsetsSource} into a protocol buffer output stream.
     *
@@ -280,6 +321,7 @@ public class InsetsSource implements Parcelable {
            pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString());
        }
        pw.print(" visible="); pw.print(mVisible);
        pw.print(" flags="); pw.print(flagsToString(mFlags));
        pw.print(" insetsRoundedCornerFrame="); pw.print(mInsetsRoundedCornerFrame);
        pw.println();
    }
@@ -302,6 +344,7 @@ public class InsetsSource implements Parcelable {
        if (mId != that.mId) return false;
        if (mType != that.mType) return false;
        if (mVisible != that.mVisible) return false;
        if (mFlags != that.mFlags) return false;
        if (excludeInvisibleImeFrames && !mVisible && mType == WindowInsets.Type.ime()) return true;
        if (!Objects.equals(mVisibleFrame, that.mVisibleFrame)) return false;
        if (mInsetsRoundedCornerFrame != that.mInsetsRoundedCornerFrame) return false;
@@ -310,7 +353,8 @@ public class InsetsSource implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mId, mType, mFrame, mVisibleFrame, mVisible, mInsetsRoundedCornerFrame);
        return Objects.hash(mId, mType, mFrame, mVisibleFrame, mVisible, mFlags,
                mInsetsRoundedCornerFrame);
    }

    public InsetsSource(Parcel in) {
@@ -323,6 +367,7 @@ public class InsetsSource implements Parcelable {
            mVisibleFrame = null;
        }
        mVisible = in.readBoolean();
        mFlags = in.readInt();
        mInsetsRoundedCornerFrame = in.readBoolean();
    }

@@ -343,6 +388,7 @@ public class InsetsSource implements Parcelable {
            dest.writeInt(0);
        }
        dest.writeBoolean(mVisible);
        dest.writeInt(mFlags);
        dest.writeBoolean(mInsetsRoundedCornerFrame);
    }

@@ -352,6 +398,7 @@ public class InsetsSource implements Parcelable {
                + " mType=" + WindowInsets.Type.toString(mType)
                + " mFrame=" + mFrame.toShortString()
                + " mVisible=" + mVisible
                + " mFlags=[" + flagsToString(mFlags) + "]"
                + (mInsetsRoundedCornerFrame ? " insetsRoundedCornerFrame" : "")
                + "}";
    }
+6 −1
Original line number Diff line number Diff line
@@ -143,9 +143,14 @@ public class InsetsState implements Parcelable {
        boolean[] typeVisibilityMap = new boolean[Type.SIZE];
        final Rect relativeFrame = new Rect(frame);
        final Rect relativeFrameMax = new Rect(frame);
        @InsetsType int suppressScrimTypes = 0;
        for (int i = mSources.size() - 1; i >= 0; i--) {
            final InsetsSource source = mSources.valueAt(i);

            if ((source.getFlags() & InsetsSource.FLAG_SUPPRESS_SCRIM) != 0) {
                suppressScrimTypes |= source.getType();
            }

            processSource(source, relativeFrame, false /* ignoreVisibility */, typeInsetsMap,
                    idSideMap, typeVisibilityMap);

@@ -177,7 +182,7 @@ public class InsetsState implements Parcelable {
        }

        return new WindowInsets(typeInsetsMap, typeMaxInsetsMap, typeVisibilityMap, isScreenRound,
                alwaysConsumeSystemBars, calculateRelativeCutout(frame),
                alwaysConsumeSystemBars, suppressScrimTypes, calculateRelativeCutout(frame),
                calculateRelativeRoundedCorners(frame),
                calculateRelativePrivacyIndicatorBounds(frame),
                calculateRelativeDisplayShape(frame),
+38 −14
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ public final class WindowInsets {
     */
    private final boolean mAlwaysConsumeSystemBars;

    private final @InsetsType int mSuppressScrimTypes;
    private final boolean mSystemWindowInsetsConsumed;
    private final boolean mStableInsetsConsumed;
    private final boolean mDisplayCutoutConsumed;
@@ -116,8 +117,8 @@ public final class WindowInsets {

    static {
        CONSUMED = new WindowInsets(createCompatTypeMap(null), createCompatTypeMap(null),
                createCompatVisibilityMap(createCompatTypeMap(null)), false, false, null, null,
                null, null, systemBars(), false);
                createCompatVisibilityMap(createCompatTypeMap(null)), false, false, 0, null,
                null, null, null, systemBars(), false);
    }

    /**
@@ -136,7 +137,8 @@ public final class WindowInsets {
            @Nullable Insets[] typeMaxInsetsMap,
            boolean[] typeVisibilityMap,
            boolean isRound,
            boolean alwaysConsumeSystemBars, DisplayCutout displayCutout,
            boolean alwaysConsumeSystemBars, @InsetsType int suppressScrimTypes,
            DisplayCutout displayCutout,
            RoundedCorners roundedCorners,
            PrivacyIndicatorBounds privacyIndicatorBounds,
            DisplayShape displayShape,
@@ -154,6 +156,7 @@ public final class WindowInsets {
        mTypeVisibilityMap = typeVisibilityMap;
        mIsRound = isRound;
        mAlwaysConsumeSystemBars = alwaysConsumeSystemBars;
        mSuppressScrimTypes = suppressScrimTypes;
        mCompatInsetsTypes = compatInsetsTypes;
        mCompatIgnoreVisibility = compatIgnoreVisibility;

@@ -175,7 +178,8 @@ public final class WindowInsets {
        this(src.mSystemWindowInsetsConsumed ? null : src.mTypeInsetsMap,
                src.mStableInsetsConsumed ? null : src.mTypeMaxInsetsMap,
                src.mTypeVisibilityMap, src.mIsRound,
                src.mAlwaysConsumeSystemBars, displayCutoutCopyConstructorArgument(src),
                src.mAlwaysConsumeSystemBars, src.mSuppressScrimTypes,
                displayCutoutCopyConstructorArgument(src),
                src.mRoundedCorners,
                src.mPrivacyIndicatorBounds,
                src.mDisplayShape,
@@ -231,8 +235,8 @@ public final class WindowInsets {
    /** @hide */
    @UnsupportedAppUsage
    public WindowInsets(Rect systemWindowInsets) {
        this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, false, null,
                null, null, null, systemBars(), false /* compatIgnoreVisibility */);
        this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, false, 0,
                null, null, null, null, systemBars(), false /* compatIgnoreVisibility */);
    }

    /**
@@ -552,7 +556,7 @@ public final class WindowInsets {
        return new WindowInsets(mSystemWindowInsetsConsumed ? null : mTypeInsetsMap,
                mStableInsetsConsumed ? null : mTypeMaxInsetsMap,
                mTypeVisibilityMap,
                mIsRound, mAlwaysConsumeSystemBars,
                mIsRound, mAlwaysConsumeSystemBars, mSuppressScrimTypes,
                null /* displayCutout */, mRoundedCorners, mPrivacyIndicatorBounds, mDisplayShape,
                mCompatInsetsTypes, mCompatIgnoreVisibility);
    }
@@ -603,7 +607,7 @@ public final class WindowInsets {
    public WindowInsets consumeSystemWindowInsets() {
        return new WindowInsets(null, null,
                mTypeVisibilityMap,
                mIsRound, mAlwaysConsumeSystemBars,
                mIsRound, mAlwaysConsumeSystemBars, mSuppressScrimTypes,
                // If the system window insets types contain displayCutout, we should also consume
                // it.
                (mCompatInsetsTypes & displayCutout()) != 0
@@ -895,6 +899,13 @@ public final class WindowInsets {
        return mAlwaysConsumeSystemBars;
    }

    /**
     * @hide
     */
    public @InsetsType int getSuppressScrimTypes() {
        return mSuppressScrimTypes;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder("WindowInsets{\n    ");
@@ -919,7 +930,9 @@ public final class WindowInsets {
        result.append("\n    ");
        result.append(mDisplayShape != null ? "displayShape=" + mDisplayShape : "");
        result.append("\n    ");
        result.append("compatInsetsTypes=" + mCompatInsetsTypes);
        result.append("suppressScrimTypes=" + Type.toString(mSuppressScrimTypes));
        result.append("\n    ");
        result.append("compatInsetsTypes=" + Type.toString(mCompatInsetsTypes));
        result.append("\n    ");
        result.append("compatIgnoreVisibility=" + mCompatIgnoreVisibility);
        result.append("\n    ");
@@ -1014,7 +1027,7 @@ public final class WindowInsets {
                        ? null
                        : insetInsets(mTypeMaxInsetsMap, left, top, right, bottom),
                mTypeVisibilityMap,
                mIsRound, mAlwaysConsumeSystemBars,
                mIsRound, mAlwaysConsumeSystemBars, mSuppressScrimTypes,
                mDisplayCutoutConsumed
                        ? null
                        : mDisplayCutout == null
@@ -1038,6 +1051,7 @@ public final class WindowInsets {

        return mIsRound == that.mIsRound
                && mAlwaysConsumeSystemBars == that.mAlwaysConsumeSystemBars
                && mSuppressScrimTypes == that.mSuppressScrimTypes
                && mSystemWindowInsetsConsumed == that.mSystemWindowInsetsConsumed
                && mStableInsetsConsumed == that.mStableInsetsConsumed
                && mDisplayCutoutConsumed == that.mDisplayCutoutConsumed
@@ -1054,8 +1068,9 @@ public final class WindowInsets {
    public int hashCode() {
        return Objects.hash(Arrays.hashCode(mTypeInsetsMap), Arrays.hashCode(mTypeMaxInsetsMap),
                Arrays.hashCode(mTypeVisibilityMap), mIsRound, mDisplayCutout, mRoundedCorners,
                mAlwaysConsumeSystemBars, mSystemWindowInsetsConsumed, mStableInsetsConsumed,
                mDisplayCutoutConsumed, mPrivacyIndicatorBounds, mDisplayShape);
                mAlwaysConsumeSystemBars, mSuppressScrimTypes, mSystemWindowInsetsConsumed,
                mStableInsetsConsumed, mDisplayCutoutConsumed, mPrivacyIndicatorBounds,
                mDisplayShape);
    }


@@ -1120,6 +1135,7 @@ public final class WindowInsets {

        private boolean mIsRound;
        private boolean mAlwaysConsumeSystemBars;
        private @InsetsType int mSuppressScrimTypes;

        private PrivacyIndicatorBounds mPrivacyIndicatorBounds = new PrivacyIndicatorBounds();

@@ -1147,6 +1163,7 @@ public final class WindowInsets {
            mRoundedCorners = insets.mRoundedCorners;
            mIsRound = insets.mIsRound;
            mAlwaysConsumeSystemBars = insets.mAlwaysConsumeSystemBars;
            mSuppressScrimTypes = insets.mSuppressScrimTypes;
            mPrivacyIndicatorBounds = insets.mPrivacyIndicatorBounds;
            mDisplayShape = insets.mDisplayShape;
        }
@@ -1420,6 +1437,13 @@ public final class WindowInsets {
            return this;
        }

        /** @hide */
        @NonNull
        public Builder setSuppressScrimTypes(@InsetsType int suppressScrimTypes) {
            mSuppressScrimTypes = suppressScrimTypes;
            return this;
        }

        /**
         * Builds a {@link WindowInsets} instance.
         *
@@ -1429,8 +1453,8 @@ public final class WindowInsets {
        public WindowInsets build() {
            return new WindowInsets(mSystemInsetsConsumed ? null : mTypeInsetsMap,
                    mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap,
                    mIsRound, mAlwaysConsumeSystemBars, mDisplayCutout, mRoundedCorners,
                    mPrivacyIndicatorBounds, mDisplayShape, systemBars(),
                    mIsRound, mAlwaysConsumeSystemBars, mSuppressScrimTypes, mDisplayCutout,
                    mRoundedCorners, mPrivacyIndicatorBounds, mDisplayShape, systemBars(),
                    false /* compatIgnoreVisibility */);
        }
    }
Loading