Merge "Introduce the flags of the insets source" into udc-dev

This commit is contained in:
Tiger Huang
2023-04-14 10:34:06 +00:00
committed by Android (Google) Code Review
13 changed files with 162 additions and 50 deletions

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -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" : "")
+ "}";
}

View File

@@ -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),

View File

@@ -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 */);
}
}

View File

@@ -233,6 +233,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
private boolean mLastHasLeftStableInset = false;
private int mLastWindowFlags = 0;
private boolean mLastShouldAlwaysConsumeSystemBars = false;
private @InsetsType int mLastSuppressScrimTypes = 0;
private int mRootScrollY = 0;
@@ -1143,6 +1144,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
mLastHasLeftStableInset = hasLeftStableInset;
mLastShouldAlwaysConsumeSystemBars = insets.shouldAlwaysConsumeSystemBars();
mLastSuppressScrimTypes = insets.getSuppressScrimTypes();
}
boolean navBarToRightEdge = isNavBarToRightEdge(mLastBottomInset, mLastRightInset);
@@ -1378,7 +1380,8 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
return calculateBarColor(mWindow.getAttributes().flags, FLAG_TRANSLUCENT_STATUS,
mSemiTransparentBarColor, mWindow.mStatusBarColor,
appearance, APPEARANCE_LIGHT_STATUS_BARS,
mWindow.mEnsureStatusBarContrastWhenTransparent);
mWindow.mEnsureStatusBarContrastWhenTransparent
&& (mLastSuppressScrimTypes & WindowInsets.Type.statusBars()) == 0);
}
private int calculateNavigationBarColor(@Appearance int appearance) {
@@ -1386,7 +1389,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
mSemiTransparentBarColor, mWindow.mNavigationBarColor,
appearance, APPEARANCE_LIGHT_NAVIGATION_BARS,
mWindow.mEnsureNavigationBarContrastWhenTransparent
&& getContext().getResources().getBoolean(R.bool.config_navBarNeedsScrim));
&& (mLastSuppressScrimTypes & WindowInsets.Type.navigationBars()) == 0);
}
public static int calculateBarColor(int flags, int translucentFlag, int semiTransparentBarColor,

View File

@@ -40,14 +40,14 @@ public class WindowInsetsTest {
@Test
public void systemWindowInsets_afterConsuming_isConsumed() {
assertTrue(new WindowInsets(WindowInsets.createCompatTypeMap(new Rect(1, 2, 3, 4)), null,
null, false, false, null, null, null, null,
null, false, false, 0, null, null, null, null,
WindowInsets.Type.systemBars(), false)
.consumeSystemWindowInsets().isConsumed());
}
@Test
public void multiNullConstructor_isConsumed() {
assertTrue(new WindowInsets(null, null, null, false, false, null, null, null, null,
assertTrue(new WindowInsets(null, null, null, false, false, 0, null, null, null, null,
WindowInsets.Type.systemBars(), false).isConsumed());
}
@@ -63,8 +63,8 @@ public class WindowInsetsTest {
boolean[] visible = new boolean[SIZE];
WindowInsets.assignCompatInsets(maxInsets, new Rect(0, 10, 0, 0));
WindowInsets.assignCompatInsets(insets, new Rect(0, 0, 0, 0));
WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, false, null,
null, null, DisplayShape.NONE, systemBars(),
WindowInsets windowInsets = new WindowInsets(insets, maxInsets, visible, false, false,
0, null, null, null, DisplayShape.NONE, systemBars(),
true /* compatIgnoreVisibility */);
assertEquals(Insets.of(0, 10, 0, 0), windowInsets.getSystemWindowInsets());
}

View File

@@ -169,7 +169,7 @@ public class ActionBarOverlayLayoutTest {
private WindowInsets insetsWith(Insets content, DisplayCutout cutout) {
return new WindowInsets(WindowInsets.createCompatTypeMap(content.toRect()), null, null,
false, false, cutout, null, null, null, WindowInsets.Type.systemBars(), false);
false, false, 0, cutout, null, null, null, WindowInsets.Type.systemBars(), false);
}
private ViewGroup createViewGroupWithId(int id) {

View File

@@ -25,6 +25,7 @@ import static android.app.StatusBarManager.WindowType;
import static android.app.StatusBarManager.WindowVisibleState;
import static android.app.StatusBarManager.windowStateToString;
import static android.app.WindowConfiguration.ROTATION_UNDEFINED;
import static android.view.InsetsSource.FLAG_SUPPRESS_SCRIM;
import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
@@ -1717,12 +1718,15 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
if (insetsHeight != -1 && !mEdgeBackGestureHandler.isButtonForcedVisible()) {
navBarProvider.setInsetsSize(Insets.of(0, 0, 0, insetsHeight));
}
final boolean needsScrim = userContext.getResources().getBoolean(
com.android.internal.R.bool.config_navBarNeedsScrim);
navBarProvider.setFlags(needsScrim ? 0 : FLAG_SUPPRESS_SCRIM, FLAG_SUPPRESS_SCRIM);
final InsetsFrameProvider tappableElementProvider = new InsetsFrameProvider(
mInsetsSourceOwner, 0, WindowInsets.Type.tappableElement());
final boolean navBarTapThrough = userContext.getResources().getBoolean(
final boolean tapThrough = userContext.getResources().getBoolean(
com.android.internal.R.bool.config_navBarTapThrough);
if (navBarTapThrough) {
if (tapThrough) {
tappableElementProvider.setInsetsSize(Insets.NONE);
}

View File

@@ -128,7 +128,7 @@ import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.statusbar.LetterboxDetails;
import com.android.internal.util.ScreenshotHelper;
import com.android.internal.util.ScreenshotRequest;
import com.android.internal.util.function.TriConsumer;
import com.android.internal.util.function.TriFunction;
import com.android.internal.view.AppearanceRegion;
import com.android.internal.widget.PointerLocationView;
import com.android.server.LocalServices;
@@ -1081,11 +1081,11 @@ public class DisplayPolicy {
// The index of the provider and corresponding insets types cannot change at
// runtime as ensured in WMS. Make use of the index in the provider directly
// to access the latest provided size at runtime.
final TriConsumer<DisplayFrames, WindowContainer, Rect> frameProvider =
final TriFunction<DisplayFrames, WindowContainer, Rect, Integer> frameProvider =
getFrameProvider(win, i, INSETS_OVERRIDE_INDEX_INVALID);
final InsetsFrameProvider.InsetsSizeOverride[] overrides =
provider.getInsetsSizeOverrides();
final SparseArray<TriConsumer<DisplayFrames, WindowContainer, Rect>>
final SparseArray<TriFunction<DisplayFrames, WindowContainer, Rect, Integer>>
overrideProviders;
if (overrides != null) {
overrideProviders = new SparseArray<>();
@@ -1106,7 +1106,7 @@ public class DisplayPolicy {
}
}
private static TriConsumer<DisplayFrames, WindowContainer, Rect> getFrameProvider(
private static TriFunction<DisplayFrames, WindowContainer, Rect, Integer> getFrameProvider(
WindowState win, int index, int overrideIndex) {
return (displayFrames, windowContainer, inOutFrame) -> {
final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation);
@@ -1152,6 +1152,7 @@ public class DisplayPolicy {
inOutFrame.set(sTmpRect2);
}
}
return ifp.getFlags();
};
}
@@ -1179,7 +1180,7 @@ public class DisplayPolicy {
}
}
TriConsumer<DisplayFrames, WindowContainer, Rect> getImeSourceFrameProvider() {
TriFunction<DisplayFrames, WindowContainer, Rect, Integer> getImeSourceFrameProvider() {
return (displayFrames, windowContainer, inOutFrame) -> {
WindowState windowState = windowContainer.asWindowState();
if (windowState == null) {
@@ -1198,6 +1199,7 @@ public class DisplayPolicy {
} else {
inOutFrame.inset(windowState.mGivenContentInsets);
}
return 0;
};
}

View File

@@ -47,7 +47,7 @@ import android.view.WindowInsets;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.function.TriConsumer;
import com.android.internal.util.function.TriFunction;
import com.android.server.wm.SurfaceAnimator.AnimationType;
import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
@@ -73,8 +73,9 @@ class InsetsSourceProvider {
private @Nullable InsetsControlTarget mFakeControlTarget;
private @Nullable ControlAdapter mAdapter;
private TriConsumer<DisplayFrames, WindowContainer, Rect> mFrameProvider;
private SparseArray<TriConsumer<DisplayFrames, WindowContainer, Rect>> mOverrideFrameProviders;
private TriFunction<DisplayFrames, WindowContainer, Rect, Integer> mFrameProvider;
private SparseArray<TriFunction<DisplayFrames, WindowContainer, Rect, Integer>>
mOverrideFrameProviders;
private final SparseArray<Rect> mOverrideFrames = new SparseArray<Rect>();
private boolean mIsLeashReadyForDispatching;
private final Rect mSourceFrame = new Rect();
@@ -149,8 +150,8 @@ class InsetsSourceProvider {
* resulting frame that should be reported to given window type.
*/
void setWindowContainer(@Nullable WindowContainer windowContainer,
@Nullable TriConsumer<DisplayFrames, WindowContainer, Rect> frameProvider,
@Nullable SparseArray<TriConsumer<DisplayFrames, WindowContainer, Rect>>
@Nullable TriFunction<DisplayFrames, WindowContainer, Rect, Integer> frameProvider,
@Nullable SparseArray<TriFunction<DisplayFrames, WindowContainer, Rect, Integer>>
overrideFrameProviders) {
if (mWindowContainer != null) {
if (mControllable) {
@@ -203,7 +204,7 @@ class InsetsSourceProvider {
if (mServerVisible) {
mTmpRect.set(mWindowContainer.getBounds());
if (mFrameProvider != null) {
mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
mFrameProvider.apply(mWindowContainer.getDisplayContent().mDisplayFrames,
mWindowContainer, mTmpRect);
}
} else {
@@ -216,8 +217,11 @@ class InsetsSourceProvider {
mSourceFrame.set(frame);
if (mFrameProvider != null) {
mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
mWindowContainer, mSourceFrame);
final int flags = mFrameProvider.apply(
mWindowContainer.getDisplayContent().mDisplayFrames,
mWindowContainer,
mSourceFrame);
mSource.setFlags(flags);
}
updateSourceFrameForServerVisibility();
@@ -233,10 +237,10 @@ class InsetsSourceProvider {
} else {
overrideFrame = new Rect(frame);
}
final TriConsumer<DisplayFrames, WindowContainer, Rect> provider =
final TriFunction<DisplayFrames, WindowContainer, Rect, Integer> provider =
mOverrideFrameProviders.get(windowType);
if (provider != null) {
mOverrideFrameProviders.get(windowType).accept(
mOverrideFrameProviders.get(windowType).apply(
mWindowContainer.getDisplayContent().mDisplayFrames, mWindowContainer,
overrideFrame);
}
@@ -274,7 +278,7 @@ class InsetsSourceProvider {
source.setVisible(mSource.isVisible());
mTmpRect.set(frame);
if (mFrameProvider != null) {
mFrameProvider.accept(displayFrames, mWindowContainer, mTmpRect);
mFrameProvider.apply(displayFrames, mWindowContainer, mTmpRect);
}
source.setFrame(mTmpRect);
return source;

View File

@@ -94,6 +94,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
mProvider.setWindowContainer(statusBar,
(displayFrames, windowState, rect) -> {
rect.set(10, 10, 20, 20);
return 0;
}, null);
mProvider.updateSourceFrame(statusBar.getFrame());
mProvider.onPostLayout();

View File

@@ -52,7 +52,7 @@ import android.view.InsetsState;
import androidx.test.filters.SmallTest;
import com.android.internal.util.function.TriConsumer;
import com.android.internal.util.function.TriFunction;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -289,10 +289,12 @@ public class InsetsStateControllerTest extends WindowTestsBase {
InsetsSourceProvider statusBarProvider =
getController().getOrCreateSourceProvider(ID_STATUS_BAR, statusBars());
final SparseArray<TriConsumer<DisplayFrames, WindowContainer, Rect>> imeOverrideProviders =
new SparseArray<>();
imeOverrideProviders.put(TYPE_INPUT_METHOD, ((displayFrames, windowState, rect) ->
rect.set(0, 1, 2, 3)));
final SparseArray<TriFunction<DisplayFrames, WindowContainer, Rect, Integer>>
imeOverrideProviders = new SparseArray<>();
imeOverrideProviders.put(TYPE_INPUT_METHOD, ((displayFrames, windowState, rect) -> {
rect.set(0, 1, 2, 3);
return 0;
}));
statusBarProvider.setWindowContainer(statusBar, null, imeOverrideProviders);
getController().getOrCreateSourceProvider(ID_IME, ime())
.setWindowContainer(ime, null, null);