diff options
36 files changed, 413 insertions, 413 deletions
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 44afb89e1ccc..23513fad2a53 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -1242,7 +1242,7 @@ public abstract class WallpaperService extends Service { null /* ignoringVisibilityState */, config.isScreenRound(), false /* alwaysConsumeSystemBars */, mLayout.softInputMode, mLayout.flags, SYSTEM_UI_FLAG_VISIBLE, mLayout.type, - config.windowConfiguration.getWindowingMode(), null /* typeSideMap */); + config.windowConfiguration.getWindowingMode(), null /* idSideMap */); if (!fixedSize) { final Rect padding = mIWallpaperEngine.mDisplayPadding; diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index d8db99e3f9f6..75f16667f506 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -33,12 +33,12 @@ import static android.view.InsetsController.AnimationType; import static android.view.InsetsController.DEBUG; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN; import static android.view.InsetsController.LayoutInsetsDuringAnimation; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ISIDE_BOTTOM; import static android.view.InsetsState.ISIDE_FLOATING; import static android.view.InsetsState.ISIDE_LEFT; import static android.view.InsetsState.ISIDE_RIGHT; import static android.view.InsetsState.ISIDE_TOP; -import static android.view.InsetsState.ITYPE_IME; import static android.view.WindowInsets.Type.ime; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.inputmethod.ImeTracker.DEBUG_IME_VISIBILITY; @@ -132,19 +132,19 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro mController = controller; mInitialInsetsState = new InsetsState(state, true /* copySources */); if (frame != null) { - final SparseIntArray typeSideMap = new SparseIntArray(); - mCurrentInsets = getInsetsFromState(mInitialInsetsState, frame, null /* typeSideMap */); + final SparseIntArray idSideMap = new SparseIntArray(); + mCurrentInsets = getInsetsFromState(mInitialInsetsState, frame, null /* idSideMap */); mHiddenInsets = calculateInsets(mInitialInsetsState, frame, controls, false /* shown */, - null /* typeSideMap */); + null /* idSideMap */); mShownInsets = calculateInsets(mInitialInsetsState, frame, controls, true /* shown */, - typeSideMap); + idSideMap); mHasZeroInsetsIme = mShownInsets.bottom == 0 && controlsType(WindowInsets.Type.ime()); if (mHasZeroInsetsIme) { // IME has shownInsets of ZERO, and can't map to a side by default. // Map zero insets IME to bottom, making it a special case of bottom insets. - typeSideMap.put(ITYPE_IME, ISIDE_BOTTOM); + idSideMap.put(ID_IME, ISIDE_BOTTOM); } - buildSideControlsMap(typeSideMap, mSideControlsMap, controls); + buildSideControlsMap(idSideMap, mSideControlsMap, controls); } else { // Passing a null frame indicates the caller wants to play the insets animation anyway, // no matter the source provides insets to the frame or not. @@ -399,18 +399,18 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro } private Insets getInsetsFromState(InsetsState state, Rect frame, - @Nullable @InternalInsetsSide SparseIntArray typeSideMap) { + @Nullable @InternalInsetsSide SparseIntArray idSideMap) { return state.calculateInsets(frame, null /* ignoringVisibilityState */, false /* isScreenRound */, false /* alwaysConsumeSystemBars */, LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/, 0 /* legacyWindowFlags */, 0 /* legacySystemUiFlags */, TYPE_APPLICATION, - WINDOWING_MODE_UNDEFINED, typeSideMap).getInsets(mTypes); + WINDOWING_MODE_UNDEFINED, idSideMap).getInsets(mTypes); } /** Computes the insets relative to the given frame. */ private Insets calculateInsets(InsetsState state, Rect frame, SparseArray<InsetsSourceControl> controls, boolean shown, - @Nullable @InternalInsetsSide SparseIntArray typeSideMap) { + @Nullable @InternalInsetsSide SparseIntArray idSideMap) { for (int i = controls.size() - 1; i >= 0; i--) { final InsetsSourceControl control = controls.valueAt(i); if (control == null) { @@ -419,7 +419,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro } state.setSourceVisible(control.getId(), shown); } - return getInsetsFromState(state, frame, typeSideMap); + return getInsetsFromState(state, frame, idSideMap); } /** Computes the insets from the insets hints of controls. */ @@ -521,12 +521,12 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro } } - private static void buildSideControlsMap(SparseIntArray typeSideMap, + private static void buildSideControlsMap(SparseIntArray idSideMap, SparseSetArray<InsetsSourceControl> sideControlsMap, SparseArray<InsetsSourceControl> controls) { - for (int i = typeSideMap.size() - 1; i >= 0; i--) { - final int type = typeSideMap.keyAt(i); - final int side = typeSideMap.valueAt(i); + for (int i = idSideMap.size() - 1; i >= 0; i--) { + final int type = idSideMap.keyAt(i); + final int side = idSideMap.valueAt(i); final InsetsSourceControl control = controls.get(type); if (control == null) { // If the types that we are controlling are less than the types that the system has, diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 5dc3f7232ba3..1c00e5f5229e 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -19,8 +19,7 @@ package android.view; import static android.os.Trace.TRACE_TAG_VIEW; import static android.view.InsetsControllerProto.CONTROL; import static android.view.InsetsControllerProto.STATE; -import static android.view.InsetsState.ITYPE_CAPTION_BAR; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.ViewRootImpl.CAPTION_ON_SHELL; import static android.view.WindowInsets.Type.FIRST; import static android.view.WindowInsets.Type.LAST; @@ -249,6 +248,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation /** The amount IME will move up/down when animating in floating mode. */ private static final int FLOATING_IME_BOTTOM_INSET_DP = -80; + private static final int ID_CAPTION_BAR = + InsetsSource.createId(null /* owner */, 0 /* index */, captionBar()); + static final boolean DEBUG = false; static final boolean WARN = false; @@ -744,7 +746,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation WindowInsets insets = state.calculateInsets(mFrame, mState /* ignoringVisibilityState*/, mLastInsets.isRound(), mLastInsets.shouldAlwaysConsumeSystemBars(), mLastLegacySoftInputMode, mLastLegacyWindowFlags, mLastLegacySystemUiFlags, - mWindowType, mLastWindowingMode, null /* typeSideMap */); + mWindowType, mLastWindowingMode, null /* idSideMap */); mHost.dispatchWindowInsetsAnimationProgress(insets, Collections.unmodifiableList(runningAnimations)); if (DEBUG) { @@ -760,7 +762,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation }; // Make mImeSourceConsumer always non-null. - mImeSourceConsumer = getSourceConsumer(new InsetsSource(ITYPE_IME, ime())); + mImeSourceConsumer = getSourceConsumer(new InsetsSource(ID_IME, ime())); } @VisibleForTesting @@ -882,7 +884,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation if (CAPTION_ON_SHELL) { return false; } - final InsetsSource source = mState.peekSource(ITYPE_CAPTION_BAR); + final InsetsSource source = mState.peekSource(ID_CAPTION_BAR); if (source == null && mCaptionInsetsHeight == 0) { return false; } @@ -908,7 +910,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation mLastLegacySystemUiFlags = legacySystemUiFlags; mLastInsets = mState.calculateInsets(mFrame, null /* ignoringVisibilityState*/, isScreenRound, alwaysConsumeSystemBars, legacySoftInputMode, legacyWindowFlags, - legacySystemUiFlags, windowType, windowingMode, null /* typeSideMap */); + legacySystemUiFlags, windowType, windowingMode, null /* idSideMap */); return mLastInsets; } @@ -1780,10 +1782,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation if (mCaptionInsetsHeight != height) { mCaptionInsetsHeight = height; if (mCaptionInsetsHeight != 0) { - mState.getOrCreateSource(ITYPE_CAPTION_BAR, captionBar()).setFrame( + mState.getOrCreateSource(ID_CAPTION_BAR, captionBar()).setFrame( mFrame.left, mFrame.top, mFrame.right, mFrame.top + mCaptionInsetsHeight); } else { - mState.removeSource(ITYPE_CAPTION_BAR); + mState.removeSource(ID_CAPTION_BAR); } mHost.notifyInsetsChanged(); } diff --git a/core/java/android/view/InsetsSource.java b/core/java/android/view/InsetsSource.java index 582d3dc15b1f..17ab83c0df16 100644 --- a/core/java/android/view/InsetsSource.java +++ b/core/java/android/view/InsetsSource.java @@ -21,7 +21,9 @@ import static android.view.InsetsSourceProto.TYPE; import static android.view.InsetsSourceProto.VISIBLE; import static android.view.InsetsSourceProto.VISIBLE_FRAME; import static android.view.ViewRootImpl.CAPTION_ON_SHELL; +import static android.view.WindowInsets.Type.ime; +import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Insets; @@ -40,6 +42,9 @@ import java.util.Objects; */ public class InsetsSource implements Parcelable { + /** The insets source ID of IME */ + public static final int ID_IME = createId(null, 0, ime()); + /** * An unique integer to identify this source across processes. */ @@ -228,6 +233,29 @@ public class InsetsSource implements Parcelable { } /** + * Creates an identifier of an {@link InsetsSource}. + * + * @param owner An object owned by the owner. Only the owner can modify its own sources. + * @param index An owner may have multiple sources with the same type. For example, the system + * server might have multiple display cutout sources. This is used to identify + * which one is which. The value must be in a range of [0, 2047]. + * @param type The {@link WindowInsets.Type.InsetsType type} of the source. + * @return a unique integer as the identifier. + */ + public static int createId(Object owner, @IntRange(from = 0, to = 2047) int index, + @InsetsType int type) { + if (index < 0 || index >= 2048) { + throw new IllegalArgumentException(); + } + // owner takes top 16 bits; + // index takes 11 bits since the 6th bit; + // type takes bottom 5 bits. + return (((owner != null ? owner.hashCode() : 1) % (1 << 16)) << 16) + + (index << 5) + + WindowInsets.Type.indexOf(type); + } + + /** * Export the state of {@link InsetsSource} into a protocol buffer output stream. * * @param proto Stream to write the state to @@ -246,7 +274,7 @@ public class InsetsSource implements Parcelable { public void dump(String prefix, PrintWriter pw) { pw.print(prefix); - pw.print("InsetsSource id="); pw.print(mId); + pw.print("InsetsSource id="); pw.print(Integer.toHexString(mId)); pw.print(" type="); pw.print(WindowInsets.Type.toString(mType)); pw.print(" frame="); pw.print(mFrame.toShortString()); if (mVisibleFrame != null) { @@ -263,7 +291,7 @@ public class InsetsSource implements Parcelable { } /** - * @param excludeInvisibleImeFrames If {@link InsetsState#ITYPE_IME} frames should be ignored + * @param excludeInvisibleImeFrames If {@link WindowInsets.Type#ime()} frames should be ignored * when IME is not visible. */ public boolean equals(@Nullable Object o, boolean excludeInvisibleImeFrames) { @@ -321,8 +349,7 @@ public class InsetsSource implements Parcelable { @Override public String toString() { - return "InsetsSource: {" - + "mId=" + mId + return "InsetsSource: {" + Integer.toHexString(mId) + " mType=" + WindowInsets.Type.toString(mType) + " mFrame=" + mFrame.toShortString() + " mVisible=" + mVisible diff --git a/core/java/android/view/InsetsSourceControl.java b/core/java/android/view/InsetsSourceControl.java index c849cb5bfe2b..7ea93f5a7542 100644 --- a/core/java/android/view/InsetsSourceControl.java +++ b/core/java/android/view/InsetsSourceControl.java @@ -205,8 +205,7 @@ public class InsetsSourceControl implements Parcelable { @Override public String toString() { - return "InsetsSourceControl: {" - + "mId=" + mId + return "InsetsSourceControl: {" + Integer.toHexString(mId) + " mType=" + WindowInsets.Type.toString(mType) + (mInitiallyVisible ? " initiallyVisible" : "") + " mSurfacePosition=" + mSurfacePosition @@ -217,7 +216,7 @@ public class InsetsSourceControl implements Parcelable { public void dump(String prefix, PrintWriter pw) { pw.print(prefix); - pw.print("InsetsSourceControl mId="); pw.print(mId); + pw.print("InsetsSourceControl mId="); pw.print(Integer.toHexString(mId)); pw.print(" mType="); pw.print(WindowInsets.Type.toString(mType)); pw.print(" mLeash="); pw.print(mLeash); pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible); diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java index acfd94766bdc..70a773994926 100644 --- a/core/java/android/view/InsetsState.java +++ b/core/java/android/view/InsetsState.java @@ -86,11 +86,6 @@ public class InsetsState implements Parcelable { ITYPE_TOP_TAPPABLE_ELEMENT, ITYPE_RIGHT_TAPPABLE_ELEMENT, ITYPE_BOTTOM_TAPPABLE_ELEMENT, - ITYPE_LEFT_DISPLAY_CUTOUT, - ITYPE_TOP_DISPLAY_CUTOUT, - ITYPE_RIGHT_DISPLAY_CUTOUT, - ITYPE_BOTTOM_DISPLAY_CUTOUT, - ITYPE_IME, ITYPE_CLIMATE_BAR, ITYPE_EXTRA_NAVIGATION_BAR, ITYPE_LEFT_GENERIC_OVERLAY, @@ -100,12 +95,6 @@ public class InsetsState implements Parcelable { }) public @interface InternalInsetsType {} - /** - * Special value to be used to by methods returning an {@link InternalInsetsType} to indicate - * that the objects/parameters aren't associated with an {@link InternalInsetsType} - */ - public static final int ITYPE_INVALID = -1; - public static final int ITYPE_STATUS_BAR = 0; public static final int ITYPE_NAVIGATION_BAR = 1; public static final int ITYPE_CAPTION_BAR = 2; @@ -120,19 +109,11 @@ public class InsetsState implements Parcelable { public static final int ITYPE_LEFT_MANDATORY_GESTURES = 9; public static final int ITYPE_RIGHT_MANDATORY_GESTURES = 10; - public static final int ITYPE_LEFT_DISPLAY_CUTOUT = 11; - public static final int ITYPE_TOP_DISPLAY_CUTOUT = 12; - public static final int ITYPE_RIGHT_DISPLAY_CUTOUT = 13; - public static final int ITYPE_BOTTOM_DISPLAY_CUTOUT = 14; - public static final int ITYPE_LEFT_TAPPABLE_ELEMENT = 15; public static final int ITYPE_TOP_TAPPABLE_ELEMENT = 16; public static final int ITYPE_RIGHT_TAPPABLE_ELEMENT = 17; public static final int ITYPE_BOTTOM_TAPPABLE_ELEMENT = 18; - /** Input method window. */ - public static final int ITYPE_IME = 19; - /** Additional system decorations inset type. */ public static final int ITYPE_CLIMATE_BAR = 20; public static final int ITYPE_EXTRA_NAVIGATION_BAR = 21; @@ -144,7 +125,7 @@ public class InsetsState implements Parcelable { public static final int ITYPE_BOTTOM_GENERIC_OVERLAY = 25; @Retention(RetentionPolicy.SOURCE) - @IntDef(prefix = "IINSETS_SIDE", value = { + @IntDef(prefix = "ISIDE", value = { ISIDE_LEFT, ISIDE_TOP, ISIDE_RIGHT, @@ -217,7 +198,7 @@ public class InsetsState implements Parcelable { boolean isScreenRound, boolean alwaysConsumeSystemBars, int legacySoftInputMode, int legacyWindowFlags, int legacySystemUiFlags, int windowType, @WindowConfiguration.WindowingMode int windowingMode, - @Nullable @InternalInsetsSide SparseIntArray typeSideMap) { + @Nullable @InternalInsetsSide SparseIntArray idSideMap) { Insets[] typeInsetsMap = new Insets[Type.SIZE]; Insets[] typeMaxInsetsMap = new Insets[Type.SIZE]; boolean[] typeVisibilityMap = new boolean[Type.SIZE]; @@ -227,7 +208,7 @@ public class InsetsState implements Parcelable { final InsetsSource source = mSources.valueAt(i); processSource(source, relativeFrame, false /* ignoreVisibility */, typeInsetsMap, - typeSideMap, typeVisibilityMap); + idSideMap, typeVisibilityMap); // IME won't be reported in max insets as the size depends on the EditorInfo of the IME // target. @@ -239,7 +220,7 @@ public class InsetsState implements Parcelable { continue; } processSource(ignoringVisibilitySource, relativeFrameMax, - true /* ignoreVisibility */, typeMaxInsetsMap, null /* typeSideMap */, + true /* ignoreVisibility */, typeMaxInsetsMap, null /* idSideMap */, null /* typeVisibilityMap */); } } @@ -410,12 +391,12 @@ public class InsetsState implements Parcelable { } private void processSource(InsetsSource source, Rect relativeFrame, boolean ignoreVisibility, - Insets[] typeInsetsMap, @Nullable @InternalInsetsSide SparseIntArray typeSideMap, + Insets[] typeInsetsMap, @Nullable @InternalInsetsSide SparseIntArray idSideMap, @Nullable boolean[] typeVisibilityMap) { Insets insets = source.calculateInsets(relativeFrame, ignoreVisibility); final int type = source.getType(); - processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap, + processSourceAsPublicType(source, typeInsetsMap, idSideMap, typeVisibilityMap, insets, type); if (type == Type.MANDATORY_SYSTEM_GESTURES) { @@ -424,24 +405,24 @@ public class InsetsState implements Parcelable { // Type.systemGestureInsets() as NORMAL | MANDATORY, but then we lose the // ability to set systemGestureInsets() independently from // mandatorySystemGestureInsets() in the Builder. - processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap, + processSourceAsPublicType(source, typeInsetsMap, idSideMap, typeVisibilityMap, insets, Type.SYSTEM_GESTURES); } if (type == Type.CAPTION_BAR) { // Caption should also be gesture and tappable elements. This should not be needed when // the caption is added from the shell, as the shell can add other types at the same // time. - processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap, + processSourceAsPublicType(source, typeInsetsMap, idSideMap, typeVisibilityMap, insets, Type.SYSTEM_GESTURES); - processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap, + processSourceAsPublicType(source, typeInsetsMap, idSideMap, typeVisibilityMap, insets, Type.MANDATORY_SYSTEM_GESTURES); - processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap, + processSourceAsPublicType(source, typeInsetsMap, idSideMap, typeVisibilityMap, insets, Type.TAPPABLE_ELEMENT); } } private void processSourceAsPublicType(InsetsSource source, Insets[] typeInsetsMap, - @InternalInsetsSide @Nullable SparseIntArray typeSideMap, + @InternalInsetsSide @Nullable SparseIntArray idSideMap, @Nullable boolean[] typeVisibilityMap, Insets insets, int type) { int index = indexOf(type); Insets existing = typeInsetsMap[index]; @@ -455,10 +436,10 @@ public class InsetsState implements Parcelable { typeVisibilityMap[index] = source.isVisible(); } - if (typeSideMap != null) { + if (idSideMap != null) { @InternalInsetsSide int insetSide = getInsetSide(insets); if (insetSide != ISIDE_UNKNOWN) { - typeSideMap.put(source.getId(), insetSide); + idSideMap.put(source.getId(), insetSide); } } } @@ -757,15 +738,6 @@ public class InsetsState implements Parcelable { result.add(ITYPE_RIGHT_MANDATORY_GESTURES); result.add(ITYPE_BOTTOM_MANDATORY_GESTURES); } - if ((types & Type.DISPLAY_CUTOUT) != 0) { - result.add(ITYPE_LEFT_DISPLAY_CUTOUT); - result.add(ITYPE_TOP_DISPLAY_CUTOUT); - result.add(ITYPE_RIGHT_DISPLAY_CUTOUT); - result.add(ITYPE_BOTTOM_DISPLAY_CUTOUT); - } - if ((types & Type.IME) != 0) { - result.add(ITYPE_IME); - } return result; } @@ -789,8 +761,6 @@ public class InsetsState implements Parcelable { return Type.SYSTEM_OVERLAYS; case ITYPE_CAPTION_BAR: return Type.CAPTION_BAR; - case ITYPE_IME: - return Type.IME; case ITYPE_TOP_MANDATORY_GESTURES: case ITYPE_BOTTOM_MANDATORY_GESTURES: case ITYPE_LEFT_MANDATORY_GESTURES: @@ -806,11 +776,6 @@ public class InsetsState implements Parcelable { case ITYPE_RIGHT_TAPPABLE_ELEMENT: case ITYPE_BOTTOM_TAPPABLE_ELEMENT: return Type.TAPPABLE_ELEMENT; - case ITYPE_LEFT_DISPLAY_CUTOUT: - case ITYPE_TOP_DISPLAY_CUTOUT: - case ITYPE_RIGHT_DISPLAY_CUTOUT: - case ITYPE_BOTTOM_DISPLAY_CUTOUT: - return Type.DISPLAY_CUTOUT; default: throw new IllegalArgumentException("Unknown type: " + type); } @@ -845,7 +810,7 @@ public class InsetsState implements Parcelable { void dumpDebug(ProtoOutputStream proto, long fieldId) { final long token = proto.start(fieldId); - final InsetsSource source = mSources.get(ITYPE_IME); + final InsetsSource source = mSources.get(InsetsSource.ID_IME); if (source != null) { source.dumpDebug(proto, SOURCES); } @@ -886,16 +851,6 @@ public class InsetsState implements Parcelable { return "ITYPE_RIGHT_TAPPABLE_ELEMENT"; case ITYPE_BOTTOM_TAPPABLE_ELEMENT: return "ITYPE_BOTTOM_TAPPABLE_ELEMENT"; - case ITYPE_LEFT_DISPLAY_CUTOUT: - return "ITYPE_LEFT_DISPLAY_CUTOUT"; - case ITYPE_TOP_DISPLAY_CUTOUT: - return "ITYPE_TOP_DISPLAY_CUTOUT"; - case ITYPE_RIGHT_DISPLAY_CUTOUT: - return "ITYPE_RIGHT_DISPLAY_CUTOUT"; - case ITYPE_BOTTOM_DISPLAY_CUTOUT: - return "ITYPE_BOTTOM_DISPLAY_CUTOUT"; - case ITYPE_IME: - return "ITYPE_IME"; case ITYPE_CLIMATE_BAR: return "ITYPE_CLIMATE_BAR"; case ITYPE_EXTRA_NAVIGATION_BAR: @@ -924,8 +879,8 @@ public class InsetsState implements Parcelable { * excluded. * @param excludingCaptionInsets {@code true} if we want to compare two InsetsState objects but * ignore the caption insets source value. - * @param excludeInvisibleImeFrames If {@link #ITYPE_IME} frames should be ignored when IME is - * not visible. + * @param excludeInvisibleImeFrames If {@link WindowInsets.Type#ime()} frames should be ignored + * when IME is not visible. * @return {@code true} if the two InsetsState objects are equal, {@code false} otherwise. */ @VisibleForTesting diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index c2d49eb5b50c..37d9d6cbbe7b 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -22,7 +22,7 @@ import static android.os.IInputConstants.INVALID_INPUT_EVENT_ID; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.INVALID_DISPLAY; import static android.view.InputDevice.SOURCE_CLASS_NONE; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.View.PFLAG_DRAW_ANIMATION; import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN; import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; @@ -8957,7 +8957,7 @@ public final class ViewRootImpl implements ViewParent, if (mTranslator != null) { mTranslator.translateInsetsStateInScreenToAppWindow(insetsState); } - if (insetsState.isSourceOrDefaultVisible(ITYPE_IME, Type.ime())) { + if (insetsState.isSourceOrDefaultVisible(ID_IME, Type.ime())) { ImeTracing.getInstance().triggerClientDump("ViewRootImpl#dispatchResized", getInsetsController().getHost().getInputMethodManager(), null /* icProto */); } @@ -8989,7 +8989,7 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateInsetsStateInScreenToAppWindow(insetsState); mTranslator.translateSourceControlsInScreenToAppWindow(activeControls); } - if (insetsState != null && insetsState.isSourceOrDefaultVisible(ITYPE_IME, Type.ime())) { + if (insetsState != null && insetsState.isSourceOrDefaultVisible(ID_IME, Type.ime())) { ImeTracing.getInstance().triggerClientDump("ViewRootImpl#dispatchInsetsControlChanged", getInsetsController().getHost().getInputMethodManager(), null /* icProto */); } diff --git a/core/java/android/view/WindowLayout.java b/core/java/android/view/WindowLayout.java index 70778046d9f5..5ec52196d02c 100644 --- a/core/java/android/view/WindowLayout.java +++ b/core/java/android/view/WindowLayout.java @@ -16,7 +16,7 @@ package android.view; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; @@ -89,7 +89,7 @@ public class WindowLayout { if (attachedWindowFrame == null) { outParentFrame.set(outDisplayFrame); if ((pfl & PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME) != 0) { - final InsetsSource source = state.peekSource(ITYPE_IME); + final InsetsSource source = state.peekSource(ID_IME); if (source != null) { outParentFrame.inset(source.calculateInsets( outParentFrame, false /* ignoreVisibility */)); diff --git a/core/java/android/window/WindowMetricsController.java b/core/java/android/window/WindowMetricsController.java index 11bd47da9774..7f87a0ddfbd2 100644 --- a/core/java/android/window/WindowMetricsController.java +++ b/core/java/android/window/WindowMetricsController.java @@ -127,7 +127,7 @@ public final class WindowMetricsController { isScreenRound, alwaysConsumeSystemBars, SOFT_INPUT_ADJUST_NOTHING, 0 /* flags */, SYSTEM_UI_FLAG_VISIBLE, WindowManager.LayoutParams.INVALID_WINDOW_TYPE, windowingMode, - null /* typeSideMap */); + null /* idSideMap */); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java b/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java index 958fdc665cb2..a3eda8dfe8e0 100644 --- a/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java +++ b/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java @@ -17,7 +17,7 @@ package android.view; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; @@ -92,7 +92,7 @@ public class ImeInsetsSourceConsumerTest { @Test public void testImeVisibility() { - final InsetsSourceControl ime = new InsetsSourceControl(ITYPE_IME, WindowInsets.Type.ime(), + final InsetsSourceControl ime = new InsetsSourceControl(ID_IME, WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE); mController.onControlsChanged(new InsetsSourceControl[] { ime }); @@ -121,7 +121,7 @@ public class ImeInsetsSourceConsumerTest { mController.show(WindowInsets.Type.ime(), true /* fromIme */, null /* statsToken */); // set control and verify visibility is applied. - InsetsSourceControl control = new InsetsSourceControl(ITYPE_IME, + InsetsSourceControl control = new InsetsSourceControl(ID_IME, WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE); mController.onControlsChanged(new InsetsSourceControl[] { control }); // IME show animation should be triggered when control becomes available. @@ -161,7 +161,7 @@ public class ImeInsetsSourceConsumerTest { } // set control and verify visibility is applied. - InsetsSourceControl control = Mockito.spy(new InsetsSourceControl(ITYPE_IME, + InsetsSourceControl control = Mockito.spy(new InsetsSourceControl(ID_IME, WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE)); // Simulate IME source control set this flag when the target has starting window. control.setSkipAnimationOnce(true); diff --git a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java index bef3b4209bb8..1682135e2769 100644 --- a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java +++ b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java @@ -16,8 +16,6 @@ package android.view; -import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.WindowInsets.Type.navigationBars; import static android.view.WindowInsets.Type.statusBars; import static android.view.WindowInsets.Type.systemBars; @@ -68,6 +66,11 @@ import java.util.List; @RunWith(AndroidJUnit4.class) public class InsetsAnimationControlImplTest { + private static final int ID_STATUS_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, statusBars()); + private static final int ID_NAVIGATION_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, navigationBars()); + private InsetsAnimationControlImpl mController; private SurfaceSession mSession = new SurfaceSession(); @@ -89,31 +92,31 @@ public class InsetsAnimationControlImplTest { .setName("testSurface") .build(); mInsetsState = new InsetsState(); - mInsetsState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mInsetsState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 500, 100)); - mInsetsState.getOrCreateSource(ITYPE_NAVIGATION_BAR, navigationBars()) + mInsetsState.getOrCreateSource(ID_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(400, 0, 500, 500)); - InsetsSourceConsumer topConsumer = new InsetsSourceConsumer(ITYPE_STATUS_BAR, + InsetsSourceConsumer topConsumer = new InsetsSourceConsumer(ID_STATUS_BAR, WindowInsets.Type.statusBars(), mInsetsState, () -> mMockTransaction, mMockController); topConsumer.setControl( - new InsetsSourceControl(ITYPE_STATUS_BAR, WindowInsets.Type.statusBars(), + new InsetsSourceControl(ID_STATUS_BAR, WindowInsets.Type.statusBars(), mStatusLeash, true, new Point(0, 0), Insets.of(0, 100, 0, 0)), new int[1], new int[1]); - InsetsSourceConsumer navConsumer = new InsetsSourceConsumer(ITYPE_NAVIGATION_BAR, + InsetsSourceConsumer navConsumer = new InsetsSourceConsumer(ID_NAVIGATION_BAR, WindowInsets.Type.navigationBars(), mInsetsState, () -> mMockTransaction, mMockController); navConsumer.setControl( - new InsetsSourceControl(ITYPE_NAVIGATION_BAR, WindowInsets.Type.navigationBars(), + new InsetsSourceControl(ID_NAVIGATION_BAR, WindowInsets.Type.navigationBars(), mNavLeash, true, new Point(400, 0), Insets.of(0, 0, 100, 0)), new int[1], new int[1]); mMockController.setRequestedVisibleTypes(0, WindowInsets.Type.navigationBars()); navConsumer.applyLocalVisibilityOverride(); SparseArray<InsetsSourceControl> controls = new SparseArray<>(); - controls.put(ITYPE_STATUS_BAR, topConsumer.getControl()); - controls.put(ITYPE_NAVIGATION_BAR, navConsumer.getControl()); + controls.put(ID_STATUS_BAR, topConsumer.getControl()); + controls.put(ID_NAVIGATION_BAR, navConsumer.getControl()); mController = new InsetsAnimationControlImpl(controls, new Rect(0, 0, 500, 500), mInsetsState, mMockListener, systemBars(), mMockController, 10 /* durationMs */, new LinearInterpolator(), diff --git a/core/tests/coretests/src/android/view/InsetsControllerTest.java b/core/tests/coretests/src/android/view/InsetsControllerTest.java index d1a094c50d24..ca1367a710ec 100644 --- a/core/tests/coretests/src/android/view/InsetsControllerTest.java +++ b/core/tests/coretests/src/android/view/InsetsControllerTest.java @@ -22,15 +22,13 @@ import static android.view.InsetsController.ANIMATION_TYPE_NONE; import static android.view.InsetsController.ANIMATION_TYPE_RESIZE; import static android.view.InsetsController.ANIMATION_TYPE_SHOW; import static android.view.InsetsController.AnimationType; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsSourceConsumer.ShowResult.IME_SHOW_DELAYED; import static android.view.InsetsSourceConsumer.ShowResult.SHOW_IMMEDIATELY; -import static android.view.InsetsState.ITYPE_CAPTION_BAR; -import static android.view.InsetsState.ITYPE_IME; -import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.ViewRootImpl.CAPTION_ON_SHELL; import static android.view.WindowInsets.Type.SIZE; import static android.view.WindowInsets.Type.all; +import static android.view.WindowInsets.Type.captionBar; import static android.view.WindowInsets.Type.defaultVisible; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.navigationBars; @@ -99,6 +97,12 @@ import java.util.concurrent.CountDownLatch; @Presubmit @RunWith(AndroidJUnit4.class) public class InsetsControllerTest { + + private static final int ID_STATUS_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, statusBars()); + private static final int ID_NAVIGATION_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, navigationBars()); + private InsetsSource mStatusSource; private InsetsSource mNavSource; private InsetsSource mImeSource; @@ -151,11 +155,11 @@ public class InsetsControllerTest { } }, mTestHandler); final Rect rect = new Rect(5, 5, 5, 5); - mStatusSource = new InsetsSource(ITYPE_STATUS_BAR, statusBars()); + mStatusSource = new InsetsSource(ID_STATUS_BAR, statusBars()); mStatusSource.setFrame(new Rect(0, 0, 100, 10)); - mNavSource = new InsetsSource(ITYPE_NAVIGATION_BAR, navigationBars()); + mNavSource = new InsetsSource(ID_NAVIGATION_BAR, navigationBars()); mNavSource.setFrame(new Rect(0, 90, 100, 100)); - mImeSource = new InsetsSource(ITYPE_IME, ime()); + mImeSource = new InsetsSource(ID_IME, ime()); mImeSource.setFrame(new Rect(0, 0, 100, 10)); InsetsState state = new InsetsState(); state.addSource(mStatusSource); @@ -177,7 +181,7 @@ public class InsetsControllerTest { @Test public void testControlsChanged() { - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); assertNotNull(mController.getSourceConsumer(mStatusSource).getControl().getLeash()); mController.addOnControllableInsetsChangedListener( ((controller, typeMask) -> assertEquals(statusBars(), typeMask))); @@ -188,7 +192,7 @@ public class InsetsControllerTest { OnControllableInsetsChangedListener listener = mock(OnControllableInsetsChangedListener.class); mController.addOnControllableInsetsChangedListener(listener); - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); mController.onControlsChanged(new InsetsSourceControl[0]); assertNull(mController.getSourceConsumer(mStatusSource).getControl()); InOrder inOrder = Mockito.inOrder(listener); @@ -200,7 +204,7 @@ public class InsetsControllerTest { @Test public void testControlsRevoked_duringAnim() { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); ArgumentCaptor<WindowInsetsAnimationController> animationController = ArgumentCaptor.forClass(WindowInsetsAnimationController.class); @@ -229,7 +233,7 @@ public class InsetsControllerTest { InsetsSourceControl control = new InsetsSourceControl( - ITYPE_STATUS_BAR, statusBars(), mLeash, true, new Point(), + ID_STATUS_BAR, statusBars(), mLeash, true, new Point(), Insets.of(0, 10, 0, 0)); mController.onControlsChanged(new InsetsSourceControl[]{control}); mController.controlWindowInsetsAnimation(0, 0 /* durationMs */, @@ -282,7 +286,7 @@ public class InsetsControllerTest { @Test public void testApplyImeVisibility() { - InsetsSourceControl ime = createControl(ITYPE_IME, ime()); + InsetsSourceControl ime = createControl(ID_IME, ime()); mController.onControlsChanged(new InsetsSourceControl[] { ime }); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { mController.getSourceConsumer(mImeSource).onWindowFocusGained(true); @@ -421,28 +425,28 @@ public class InsetsControllerTest { @Test public void testRestoreStartsAnimation() { - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { mController.hide(statusBars()); mController.cancelExistingAnimations(); assertFalse(isRequestedVisible(mController, statusBars())); - assertFalse(mController.getState().peekSource(ITYPE_STATUS_BAR).isVisible()); + assertFalse(mController.getState().peekSource(ID_STATUS_BAR).isVisible()); // Loosing control InsetsState state = new InsetsState(mController.getState()); - state.setSourceVisible(ITYPE_STATUS_BAR, true); + state.setSourceVisible(ID_STATUS_BAR, true); mController.onStateChanged(state); mController.onControlsChanged(new InsetsSourceControl[0]); assertFalse(isRequestedVisible(mController, statusBars())); - assertTrue(mController.getState().peekSource(ITYPE_STATUS_BAR).isVisible()); + assertTrue(mController.getState().peekSource(ID_STATUS_BAR).isVisible()); // Gaining control - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); assertEquals(ANIMATION_TYPE_HIDE, mController.getAnimationType(statusBars())); mController.cancelExistingAnimations(); assertFalse(isRequestedVisible(mController, statusBars())); - assertFalse(mController.getState().peekSource(ITYPE_STATUS_BAR).isVisible()); + assertFalse(mController.getState().peekSource(ID_STATUS_BAR).isVisible()); }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); } @@ -453,18 +457,18 @@ public class InsetsControllerTest { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { mController.show(ime()); - assertFalse(mController.getState().peekSource(ITYPE_IME).isVisible()); + assertFalse(mController.getState().peekSource(ID_IME).isVisible()); // Pretend IME is calling mController.show(ime(), true /* fromIme */, null /* statsToken */); // Gaining control shortly after - mController.onControlsChanged(createSingletonControl(ITYPE_IME, ime())); + mController.onControlsChanged(createSingletonControl(ID_IME, ime())); assertEquals(ANIMATION_TYPE_SHOW, mController.getAnimationType(ime())); mController.cancelExistingAnimations(); assertTrue(isRequestedVisible(mController, ime())); - assertTrue(mController.getState().peekSource(ITYPE_IME).isVisible()); + assertTrue(mController.getState().peekSource(ID_IME).isVisible()); }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); } @@ -474,10 +478,10 @@ public class InsetsControllerTest { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { mController.show(ime()); - assertFalse(mController.getState().peekSource(ITYPE_IME).isVisible()); + assertFalse(mController.getState().peekSource(ID_IME).isVisible()); // Gaining control shortly after - mController.onControlsChanged(createSingletonControl(ITYPE_IME, ime())); + mController.onControlsChanged(createSingletonControl(ID_IME, ime())); // Pretend IME is calling mController.show(ime(), true /* fromIme */, null /* statsToken */); @@ -485,14 +489,14 @@ public class InsetsControllerTest { assertEquals(ANIMATION_TYPE_SHOW, mController.getAnimationType(ime())); mController.cancelExistingAnimations(); assertTrue(isRequestedVisible(mController, ime())); - assertTrue(mController.getState().peekSource(ITYPE_IME).isVisible()); + assertTrue(mController.getState().peekSource(ID_IME).isVisible()); }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); } @Test public void testAnimationEndState_controller() throws Exception { - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { WindowInsetsAnimationControlListener mockListener = @@ -518,7 +522,7 @@ public class InsetsControllerTest { @Test public void testCancellation_afterGainingControl() throws Exception { - mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars())); + mController.onControlsChanged(createSingletonControl(ID_STATUS_BAR, statusBars())); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { WindowInsetsAnimationControlListener mockListener = @@ -639,24 +643,24 @@ public class InsetsControllerTest { public void testFrameUpdateDuringAnimation() { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - mController.onControlsChanged(createSingletonControl(ITYPE_IME, ime())); + mController.onControlsChanged(createSingletonControl(ID_IME, ime())); // Pretend IME is calling mController.show(ime(), true /* fromIme */, null /* statsToken */); InsetsState copy = new InsetsState(mController.getState(), true /* copySources */); - copy.peekSource(ITYPE_IME).setFrame(0, 1, 2, 3); - copy.peekSource(ITYPE_IME).setVisibleFrame(new Rect(4, 5, 6, 7)); + copy.peekSource(ID_IME).setFrame(0, 1, 2, 3); + copy.peekSource(ID_IME).setVisibleFrame(new Rect(4, 5, 6, 7)); mController.onStateChanged(copy); assertNotEquals(new Rect(0, 1, 2, 3), - mController.getState().peekSource(ITYPE_IME).getFrame()); + mController.getState().peekSource(ID_IME).getFrame()); assertNotEquals(new Rect(4, 5, 6, 7), - mController.getState().peekSource(ITYPE_IME).getVisibleFrame()); + mController.getState().peekSource(ID_IME).getVisibleFrame()); mController.cancelExistingAnimations(); assertEquals(new Rect(0, 1, 2, 3), - mController.getState().peekSource(ITYPE_IME).getFrame()); + mController.getState().peekSource(ID_IME).getFrame()); assertEquals(new Rect(4, 5, 6, 7), - mController.getState().peekSource(ITYPE_IME).getVisibleFrame()); + mController.getState().peekSource(ID_IME).getVisibleFrame()); }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); } @@ -700,7 +704,7 @@ public class InsetsControllerTest { @Test public void testResizeAnimation_displayFrame() { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - final int id = ITYPE_STATUS_BAR; + final int id = ID_STATUS_BAR; final @InsetsType int type = statusBars(); final InsetsState state1 = new InsetsState(); state1.setDisplayFrame(new Rect(0, 0, 500, 1000)); @@ -724,7 +728,7 @@ public class InsetsControllerTest { @Test public void testResizeAnimation_visibility() { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - final int id = ITYPE_STATUS_BAR; + final int id = ID_STATUS_BAR; final @InsetsType int type = statusBars(); final InsetsState state1 = new InsetsState(); state1.getOrCreateSource(id, type).setVisible(true).setFrame(0, 0, 500, 50); @@ -759,22 +763,20 @@ public class InsetsControllerTest { return; } InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - mController.onFrameChanged(new Rect(0, 0, 100, 300)); - final InsetsState state = new InsetsState(mController.getState(), true); - final Rect captionFrame = new Rect(0, 0, 100, 100); - mController.setCaptionInsetsHeight(100); - mController.onStateChanged(state); - final InsetsState currentState = new InsetsState(mController.getState()); - // The caption bar source should be synced with the info in mAttachInfo. - assertEquals(captionFrame, currentState.peekSource(ITYPE_CAPTION_BAR).getFrame()); - assertTrue(currentState.equals(state, true /* excludingCaptionInsets*/, - true /* excludeInvisibleIme */)); + final Rect frame = new Rect(0, 0, 100, 300); + final int captionBarHeight = 100; + final InsetsState state = mController.getState(); + mController.onFrameChanged(frame); + mController.setCaptionInsetsHeight(captionBarHeight); + // The caption bar insets height should be the same as the caption bar height. + assertEquals(captionBarHeight, state.calculateInsets(frame, captionBar(), false).top); // Test update to remove the caption bar mController.setCaptionInsetsHeight(0); - mController.onStateChanged(state); // The caption bar source should not be there at all, because we don't add empty // caption to the state from the server. - assertNull(mController.getState().peekSource(ITYPE_CAPTION_BAR)); + for (int i = state.sourceSize() - 1; i >= 0; i--) { + assertNotEquals(captionBar(), state.sourceAt(i).getType()); + } }); } @@ -786,7 +788,6 @@ public class InsetsControllerTest { return; } InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - final InsetsState state = new InsetsState(mController.getState(), true); reset(mTestHost); mController.setCaptionInsetsHeight(100); verify(mTestHost).notifyInsetsChanged(); @@ -875,28 +876,28 @@ public class InsetsControllerTest { // Changing status bar frame should cause notifyInsetsChanged. clearInvocations(mTestHost); InsetsState newState = new InsetsState(localState, true /* copySources */); - newState.peekSource(ITYPE_STATUS_BAR).getFrame().bottom++; + newState.peekSource(ID_STATUS_BAR).getFrame().bottom++; mController.onStateChanged(newState); verify(mTestHost, times(1)).notifyInsetsChanged(); // Changing status bar visibility should cause notifyInsetsChanged. clearInvocations(mTestHost); newState = new InsetsState(localState, true /* copySources */); - newState.peekSource(ITYPE_STATUS_BAR).setVisible(false); + newState.peekSource(ID_STATUS_BAR).setVisible(false); mController.onStateChanged(newState); verify(mTestHost, times(1)).notifyInsetsChanged(); // Changing invisible IME frame should not cause notifyInsetsChanged. clearInvocations(mTestHost); newState = new InsetsState(localState, true /* copySources */); - newState.peekSource(ITYPE_IME).getFrame().top--; + newState.peekSource(ID_IME).getFrame().top--; mController.onStateChanged(newState); verify(mTestHost, never()).notifyInsetsChanged(); // Changing IME visibility should cause notifyInsetsChanged. clearInvocations(mTestHost); newState = new InsetsState(localState, true /* copySources */); - newState.peekSource(ITYPE_IME).setVisible(true); + newState.peekSource(ID_IME).setVisible(true); mController.onStateChanged(newState); verify(mTestHost, times(1)).notifyInsetsChanged(); }); @@ -941,9 +942,9 @@ public class InsetsControllerTest { } private InsetsSourceControl[] prepareControls() { - final InsetsSourceControl navBar = createControl(ITYPE_NAVIGATION_BAR, navigationBars()); - final InsetsSourceControl statusBar = createControl(ITYPE_STATUS_BAR, statusBars()); - final InsetsSourceControl ime = createControl(ITYPE_IME, ime()); + final InsetsSourceControl navBar = createControl(ID_NAVIGATION_BAR, navigationBars()); + final InsetsSourceControl statusBar = createControl(ID_STATUS_BAR, statusBars()); + final InsetsSourceControl ime = createControl(ID_IME, ime()); InsetsSourceControl[] controls = new InsetsSourceControl[3]; controls[0] = navBar; diff --git a/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java b/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java index 0486e3c73f97..988e69008008 100644 --- a/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java +++ b/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java @@ -18,9 +18,8 @@ package android.view; import static android.view.InsetsController.ANIMATION_TYPE_NONE; import static android.view.InsetsController.ANIMATION_TYPE_USER; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsSourceConsumer.ShowResult.SHOW_IMMEDIATELY; -import static android.view.InsetsState.ITYPE_IME; -import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.statusBars; @@ -69,6 +68,9 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidJUnit4.class) public class InsetsSourceConsumerTest { + private static final int ID_STATUS_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, statusBars()); + private InsetsSourceConsumer mConsumer; private SurfaceSession mSession = new SurfaceSession(); @@ -97,11 +99,11 @@ public class InsetsSourceConsumerTest { // activity isn't running, lets ignore BadTokenException. } mState = new InsetsState(); - mSpyInsetsSource = Mockito.spy(new InsetsSource(ITYPE_STATUS_BAR, statusBars())); + mSpyInsetsSource = Mockito.spy(new InsetsSource(ID_STATUS_BAR, statusBars())); mState.addSource(mSpyInsetsSource); mController = new InsetsController(new ViewRootInsetsControllerHost(mViewRoot)); - mConsumer = new InsetsSourceConsumer(ITYPE_STATUS_BAR, statusBars(), mState, + mConsumer = new InsetsSourceConsumer(ID_STATUS_BAR, statusBars(), mState, () -> mMockTransaction, mController) { @Override public void removeSurface() { @@ -113,7 +115,7 @@ public class InsetsSourceConsumerTest { instrumentation.waitForIdleSync(); mConsumer.setControl( - new InsetsSourceControl(ITYPE_STATUS_BAR, statusBars(), mLeash, + new InsetsSourceControl(ID_STATUS_BAR, statusBars(), mLeash, true /* initialVisible */, new Point(), Insets.NONE), new int[1], new int[1]); } @@ -147,25 +149,25 @@ public class InsetsSourceConsumerTest { InsetsController controller = new InsetsController(new ViewRootInsetsControllerHost( mViewRoot)); InsetsSourceConsumer consumer = new InsetsSourceConsumer( - ITYPE_IME, ime(), state, null, controller); + ID_IME, ime(), state, null, controller); - InsetsSource source = new InsetsSource(ITYPE_IME, ime()); + InsetsSource source = new InsetsSource(ID_IME, ime()); source.setFrame(0, 1, 2, 3); consumer.updateSource(new InsetsSource(source), ANIMATION_TYPE_NONE); // While we're animating, updates are delayed source.setFrame(4, 5, 6, 7); consumer.updateSource(new InsetsSource(source), ANIMATION_TYPE_USER); - assertEquals(new Rect(0, 1, 2, 3), state.peekSource(ITYPE_IME).getFrame()); + assertEquals(new Rect(0, 1, 2, 3), state.peekSource(ID_IME).getFrame()); // Finish the animation, now the pending frame should be applied assertTrue(consumer.onAnimationStateChanged(false /* running */)); - assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ITYPE_IME).getFrame()); + assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ID_IME).getFrame()); // Animating again, updates are delayed source.setFrame(8, 9, 10, 11); consumer.updateSource(new InsetsSource(source), ANIMATION_TYPE_USER); - assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ITYPE_IME).getFrame()); + assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ID_IME).getFrame()); // Updating with the current frame triggers a different code path, verify this clears // the pending 8, 9, 10, 11 frame: @@ -173,7 +175,7 @@ public class InsetsSourceConsumerTest { consumer.updateSource(new InsetsSource(source), ANIMATION_TYPE_USER); assertFalse(consumer.onAnimationStateChanged(false /* running */)); - assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ITYPE_IME).getFrame()); + assertEquals(new Rect(4, 5, 6, 7), state.peekSource(ID_IME).getFrame()); } @Test @@ -185,7 +187,7 @@ public class InsetsSourceConsumerTest { verifyZeroInteractions(mMockTransaction); int[] hideTypes = new int[1]; mConsumer.setControl( - new InsetsSourceControl(ITYPE_STATUS_BAR, statusBars(), mLeash, + new InsetsSourceControl(ID_STATUS_BAR, statusBars(), mLeash, true /* initialVisible */, new Point(), Insets.NONE), new int[1], hideTypes); assertEquals(statusBars(), hideTypes[0]); @@ -203,7 +205,7 @@ public class InsetsSourceConsumerTest { mRemoveSurfaceCalled = false; int[] hideTypes = new int[1]; mConsumer.setControl( - new InsetsSourceControl(ITYPE_STATUS_BAR, statusBars(), mLeash, + new InsetsSourceControl(ID_STATUS_BAR, statusBars(), mLeash, false /* initialVisible */, new Point(), Insets.NONE), new int[1], hideTypes); assertTrue(mRemoveSurfaceCalled); @@ -219,7 +221,7 @@ public class InsetsSourceConsumerTest { ViewRootInsetsControllerHost host = new ViewRootInsetsControllerHost(mViewRoot); InsetsController insetsController = new InsetsController(host, (controller, source) -> { if (source.getType() == ime()) { - return new InsetsSourceConsumer(ITYPE_IME, ime(), state, + return new InsetsSourceConsumer(ID_IME, ime(), state, () -> mMockTransaction, controller) { @Override public int requestShow(boolean fromController, @@ -231,11 +233,11 @@ public class InsetsSourceConsumerTest { return new InsetsSourceConsumer(source.getId(), source.getType(), controller.getState(), Transaction::new, controller); }, host.getHandler()); - InsetsSource imeSource = new InsetsSource(ITYPE_IME, ime()); + InsetsSource imeSource = new InsetsSource(ID_IME, ime()); InsetsSourceConsumer imeConsumer = insetsController.getSourceConsumer(imeSource); // Initial IME insets source control with its leash. - imeConsumer.setControl(new InsetsSourceControl(ITYPE_IME, ime(), mLeash, + imeConsumer.setControl(new InsetsSourceControl(ID_IME, ime(), mLeash, false /* initialVisible */, new Point(), Insets.NONE), new int[1], new int[1]); reset(mMockTransaction); @@ -244,7 +246,7 @@ public class InsetsSourceConsumerTest { insetsController.controlWindowInsetsAnimation(ime(), 0L, null /* interpolator */, null /* cancellationSignal */, null /* listener */); assertEquals(ANIMATION_TYPE_USER, insetsController.getAnimationType(ime())); - imeConsumer.setControl(new InsetsSourceControl(ITYPE_IME, ime(), mLeash, + imeConsumer.setControl(new InsetsSourceControl(ID_IME, ime(), mLeash, true /* initialVisible */, new Point(), Insets.NONE), new int[1], new int[1]); verify(mMockTransaction, never()).show(mLeash); }); diff --git a/core/tests/coretests/src/android/view/InsetsSourceTest.java b/core/tests/coretests/src/android/view/InsetsSourceTest.java index e01440cfb45a..6fa8f1117343 100644 --- a/core/tests/coretests/src/android/view/InsetsSourceTest.java +++ b/core/tests/coretests/src/android/view/InsetsSourceTest.java @@ -16,15 +16,20 @@ package android.view; +import static android.view.WindowInsets.Type.FIRST; +import static android.view.WindowInsets.Type.LAST; +import static android.view.WindowInsets.Type.SIZE; import static android.view.WindowInsets.Type.captionBar; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.navigationBars; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import android.graphics.Insets; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; +import android.util.SparseArray; import androidx.test.runner.AndroidJUnit4; @@ -206,6 +211,21 @@ public class InsetsSourceTest { assertEquals(Insets.of(0, 0, 0, 0), insets); } + @Test + public void testCreateId() { + final int numSourcePerType = 2048; + final int numTotalSources = SIZE * numSourcePerType; + final SparseArray<InsetsSource> sources = new SparseArray<>(numTotalSources); + final Object owner = new Object(); + for (int index = 0; index < numSourcePerType; index++) { + for (int type = FIRST; type <= LAST; type = type << 1) { + final int id = InsetsSource.createId(owner, index, type); + assertNull("Must not create the same ID.", sources.get(id)); + sources.append(id, new InsetsSource(id, type)); + } + } + assertEquals(numTotalSources, sources.size()); + } // Parcel and equals already tested via InsetsStateTest } diff --git a/core/tests/coretests/src/android/view/InsetsStateTest.java b/core/tests/coretests/src/android/view/InsetsStateTest.java index 2ea124d2fe8e..fde1a6d7b04c 100644 --- a/core/tests/coretests/src/android/view/InsetsStateTest.java +++ b/core/tests/coretests/src/android/view/InsetsStateTest.java @@ -18,15 +18,9 @@ package android.view; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ISIDE_BOTTOM; import static android.view.InsetsState.ISIDE_TOP; -import static android.view.InsetsState.ITYPE_BOTTOM_GESTURES; -import static android.view.InsetsState.ITYPE_CAPTION_BAR; -import static android.view.InsetsState.ITYPE_CLIMATE_BAR; -import static android.view.InsetsState.ITYPE_EXTRA_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_IME; -import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.RoundedCorner.POSITION_BOTTOM_LEFT; import static android.view.RoundedCorner.POSITION_BOTTOM_RIGHT; import static android.view.RoundedCorner.POSITION_TOP_LEFT; @@ -80,15 +74,28 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class InsetsStateTest { - private InsetsState mState = new InsetsState(); - private InsetsState mState2 = new InsetsState(); + private static final int ID_STATUS_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, statusBars()); + private static final int ID_NAVIGATION_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, navigationBars()); + private static final int ID_CAPTION_BAR = InsetsSource.createId( + null /* owner */, 0 /* index */, captionBar()); + private static final int ID_CLIMATE_BAR = InsetsSource.createId( + null /* owner */, 1 /* index */, statusBars()); + private static final int ID_EXTRA_NAVIGATION_BAR = InsetsSource.createId( + null /* owner */, 1 /* index */, navigationBars()); + private static final int ID_BOTTOM_GESTURES = InsetsSource.createId( + null /* owner */, 0 /* index */, systemGestures()); + + private final InsetsState mState = new InsetsState(); + private final InsetsState mState2 = new InsetsState(); @Test public void testCalculateInsets() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); SparseIntArray typeSideMap = new SparseIntArray(); @@ -97,18 +104,18 @@ public class InsetsStateTest { typeSideMap); assertEquals(Insets.of(0, 100, 0, 100), insets.getSystemWindowInsets()); assertEquals(Insets.of(0, 100, 0, 100), insets.getInsets(Type.all())); - assertEquals(ISIDE_TOP, typeSideMap.get(ITYPE_STATUS_BAR)); - assertEquals(ISIDE_BOTTOM, typeSideMap.get(ITYPE_IME)); + assertEquals(ISIDE_TOP, typeSideMap.get(ID_STATUS_BAR)); + assertEquals(ISIDE_BOTTOM, typeSideMap.get(ID_IME)); assertEquals(Insets.of(0, 100, 0, 0), insets.getInsets(statusBars())); assertEquals(Insets.of(0, 0, 0, 100), insets.getInsets(ime())); } @Test public void testCalculateInsets_imeAndNav() { - mState.getOrCreateSource(ITYPE_NAVIGATION_BAR, navigationBars()) + mState.getOrCreateSource(ID_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 100, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -124,10 +131,10 @@ public class InsetsStateTest { @Test public void testCalculateInsets_navRightStatusTop() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_NAVIGATION_BAR, navigationBars()) + mState.getOrCreateSource(ID_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(80, 0, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -139,16 +146,14 @@ public class InsetsStateTest { @Test public void testCalculateInsets_extraNavRightClimateTop() throws Exception { - mState.getOrCreateSource(ITYPE_CLIMATE_BAR, statusBars()) + mState.getOrCreateSource(ID_CLIMATE_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_EXTRA_NAVIGATION_BAR, navigationBars()) + mState.getOrCreateSource(ID_EXTRA_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(80, 0, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, false, 0, 0, 0, TYPE_APPLICATION, WINDOWING_MODE_UNDEFINED, null); - // ITYPE_CLIMATE_BAR is a type of status bar and ITYPE_EXTRA_NAVIGATION_BAR is a type - // of navigation bar. assertEquals(Insets.of(0, 100, 20, 0), insets.getSystemWindowInsets()); assertEquals(Insets.of(0, 100, 0, 0), insets.getInsets(Type.statusBars())); assertEquals(Insets.of(0, 0, 20, 0), insets.getInsets(Type.navigationBars())); @@ -156,10 +161,10 @@ public class InsetsStateTest { @Test public void testCalculateInsets_imeIgnoredWithoutAdjustResize() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -172,10 +177,10 @@ public class InsetsStateTest { @Test public void testCalculateInsets_systemUiFlagLayoutStable() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(false); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -190,7 +195,7 @@ public class InsetsStateTest { @Test public void testCalculateInsets_systemUiFlagLayoutStable_windowFlagFullscreen() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(false); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -205,7 +210,7 @@ public class InsetsStateTest { @Test public void testCalculateInsets_flagLayoutNoLimits() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -229,10 +234,10 @@ public class InsetsStateTest { @Test public void testCalculateInsets_captionStatusBarOverlap() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_CAPTION_BAR, captionBar()) + mState.getOrCreateSource(ID_CAPTION_BAR, captionBar()) .setFrame(new Rect(0, 0, 100, 300)) .setVisible(true); @@ -244,7 +249,7 @@ public class InsetsStateTest { @Test public void testCalculateInsets_captionBarOffset() { - mState.getOrCreateSource(ITYPE_CAPTION_BAR, captionBar()) + mState.getOrCreateSource(ID_CAPTION_BAR, captionBar()) .setFrame(new Rect(0, 0, 100, 300)) .setVisible(true); @@ -256,10 +261,10 @@ public class InsetsStateTest { @Test public void testCalculateInsets_extraNavRightStatusTop() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_EXTRA_NAVIGATION_BAR, navigationBars()) + mState.getOrCreateSource(ID_EXTRA_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(80, 0, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -271,10 +276,10 @@ public class InsetsStateTest { @Test public void testCalculateInsets_navigationRightClimateTop() { - mState.getOrCreateSource(ITYPE_CLIMATE_BAR, statusBars()) + mState.getOrCreateSource(ID_CLIMATE_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_NAVIGATION_BAR, navigationBars()) + mState.getOrCreateSource(ID_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(80, 0, 100, 300)) .setVisible(true); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, @@ -286,13 +291,13 @@ public class InsetsStateTest { @Test public void testStripForDispatch() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); - mState.removeSource(ITYPE_IME); + mState.removeSource(ID_IME); WindowInsets insets = mState.calculateInsets(new Rect(0, 0, 100, 300), null, false, false, SOFT_INPUT_ADJUST_RESIZE, 0, 0, TYPE_APPLICATION, WINDOWING_MODE_UNDEFINED, null); assertEquals(0, insets.getSystemWindowInsetBottom()); @@ -300,41 +305,41 @@ public class InsetsStateTest { @Test public void testEquals_differentRect() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)); - mState2.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState2.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 10, 10)); assertNotEqualsAndHashCode(); } @Test public void testEquals_differentSource() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)); - mState2.getOrCreateSource(ITYPE_IME, ime()) + mState2.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)); assertNotEqualsAndHashCode(); } @Test public void testEquals_sameButDifferentInsertOrder() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)); - mState2.getOrCreateSource(ITYPE_IME, ime()) + mState2.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)); - mState2.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState2.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)); assertEqualsAndHashCode(); } @Test public void testEquals_visibility() { - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState2.getOrCreateSource(ITYPE_IME, ime()) + mState2.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)); assertNotEqualsAndHashCode(); } @@ -400,10 +405,10 @@ public class InsetsStateTest { @Test public void testEquals_excludeInvisibleIme() { - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(false); - mState2.getOrCreateSource(ITYPE_IME, ime()) + mState2.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 200)) .setVisible(false); assertTrue(mState2.equals(mState, true, true /* excludeInvisibleIme */)); @@ -411,11 +416,11 @@ public class InsetsStateTest { @Test public void testParcelUnparcel() { - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)) .setVisibleFrame(new Rect(0, 0, 50, 10)) .setVisible(true); - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)); Parcel p = Parcel.obtain(); mState.writeToParcel(p, 0 /* flags */); @@ -427,13 +432,13 @@ public class InsetsStateTest { @Test public void testCopy() { - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 0, 100, 100)) .setVisibleFrame(new Rect(0, 0, 50, 10)) .setVisible(true); - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)); - mState2.getOrCreateSource(ITYPE_NAVIGATION_BAR, navigationBars()) + mState2.getOrCreateSource(ID_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(0, 0, 100, 100)); mState2.set(mState, true); assertEquals(mState, mState2); @@ -441,15 +446,15 @@ public class InsetsStateTest { @Test public void testCalculateVisibleInsets() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); // Make sure bottom gestures are ignored - mState.getOrCreateSource(ITYPE_BOTTOM_GESTURES, systemGestures()) + mState.getOrCreateSource(ID_BOTTOM_GESTURES, systemGestures()) .setFrame(new Rect(0, 100, 100, 300)) .setVisible(true); Insets visibleInsets = mState.calculateVisibleInsets( @@ -460,15 +465,15 @@ public class InsetsStateTest { @Test public void testCalculateVisibleInsets_adjustNothing() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); // Make sure bottom gestures are ignored - mState.getOrCreateSource(ITYPE_BOTTOM_GESTURES, systemGestures()) + mState.getOrCreateSource(ID_BOTTOM_GESTURES, systemGestures()) .setFrame(new Rect(0, 100, 100, 300)) .setVisible(true); Insets visibleInsets = mState.calculateVisibleInsets( @@ -479,15 +484,15 @@ public class InsetsStateTest { @Test public void testCalculateVisibleInsets_layoutNoLimits() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 100, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 100, 300)) .setVisible(true); // Make sure bottom gestures are ignored - mState.getOrCreateSource(ITYPE_BOTTOM_GESTURES, systemGestures()) + mState.getOrCreateSource(ID_BOTTOM_GESTURES, systemGestures()) .setFrame(new Rect(0, 100, 100, 300)) .setVisible(true); Insets visibleInsets = mState.calculateVisibleInsets( @@ -498,13 +503,13 @@ public class InsetsStateTest { @Test public void testCalculateUncontrollableInsets() { - mState.getOrCreateSource(ITYPE_STATUS_BAR, statusBars()) + mState.getOrCreateSource(ID_STATUS_BAR, statusBars()) .setFrame(new Rect(0, 0, 200, 100)) .setVisible(true); - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setFrame(new Rect(0, 200, 200, 300)) .setVisible(true); - mState.getOrCreateSource(ITYPE_NAVIGATION_BAR, navigationBars()) + mState.getOrCreateSource(ID_NAVIGATION_BAR, navigationBars()) .setFrame(new Rect(100, 0, 200, 300)) .setVisible(true); diff --git a/core/tests/coretests/src/android/view/SurfaceControlViewHostInsetsTest.java b/core/tests/coretests/src/android/view/SurfaceControlViewHostInsetsTest.java index 447cb0084e6d..4a00b00fbafe 100644 --- a/core/tests/coretests/src/android/view/SurfaceControlViewHostInsetsTest.java +++ b/core/tests/coretests/src/android/view/SurfaceControlViewHostInsetsTest.java @@ -16,7 +16,7 @@ package android.view; -import static android.view.InsetsState.ITYPE_STATUS_BAR; +import static android.view.WindowInsets.Type.statusBars; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -69,10 +69,12 @@ public class SurfaceControlViewHostInsetsTest { private InsetsState statusBarState(boolean visible) { final InsetsState insetsState = new InsetsState(); + final int id = InsetsSource.createId(null /* owner */, 0 /* index */, statusBars()); insetsState.setDisplayFrame(new Rect(0, 0, 1000, 1000)); - insetsState.getOrCreateSource(ITYPE_STATUS_BAR, WindowInsets.Type.statusBars()) - .setVisible(visible) - .setFrame(new Rect(0, 0, 100, 10)); + insetsState.getOrCreateSource( + InsetsSource.createId(null /* owner */, 0 /* index */, statusBars()), statusBars()) + .setVisible(visible) + .setFrame(new Rect(0, 0, 100, 10)); return insetsState; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java index 938576b380e2..a775db9e7128 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java @@ -141,7 +141,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged if (pd == null) { return false; } - final InsetsSource imeSource = pd.mInsetsState.peekSource(InsetsState.ITYPE_IME); + final InsetsSource imeSource = pd.mInsetsState.peekSource(InsetsSource.ID_IME); return imeSource != null && pd.mImeSourceControl != null && imeSource.isVisible(); } @@ -245,13 +245,13 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged return; } - updateImeVisibility(insetsState.isSourceOrDefaultVisible(InsetsState.ITYPE_IME, + updateImeVisibility(insetsState.isSourceOrDefaultVisible(InsetsSource.ID_IME, WindowInsets.Type.ime())); - final InsetsSource newSource = insetsState.peekSource(InsetsState.ITYPE_IME); + final InsetsSource newSource = insetsState.peekSource(InsetsSource.ID_IME); final Rect newFrame = newSource != null ? newSource.getFrame() : null; final boolean newSourceVisible = newSource != null && newSource.isVisible(); - final InsetsSource oldSource = mInsetsState.peekSource(InsetsState.ITYPE_IME); + final InsetsSource oldSource = mInsetsState.peekSource(InsetsSource.ID_IME); final Rect oldFrame = oldSource != null ? oldSource.getFrame() : null; mInsetsState.set(insetsState, true /* copySources */); @@ -354,7 +354,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged * Sends the local visibility state back to window manager. Needed for legacy adjustForIme. */ private void setVisibleDirectly(boolean visible) { - mInsetsState.setSourceVisible(InsetsState.ITYPE_IME, visible); + mInsetsState.setSourceVisible(InsetsSource.ID_IME, visible); mRequestedVisibleTypes = visible ? mRequestedVisibleTypes | WindowInsets.Type.ime() : mRequestedVisibleTypes & ~WindowInsets.Type.ime(); @@ -385,7 +385,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged private void startAnimation(final boolean show, final boolean forceRestart, @Nullable ImeTracker.Token statsToken) { - final InsetsSource imeSource = mInsetsState.peekSource(InsetsState.ITYPE_IME); + final InsetsSource imeSource = mInsetsState.peekSource(InsetsSource.ID_IME); if (imeSource == null || mImeSourceControl == null) { ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_WM_ANIMATION_CREATE); return; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java index 304a1f6f04f0..5933ac22dd83 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java @@ -223,7 +223,7 @@ public class DividerView extends FrameLayout implements View.OnTouchListener { // But there is no need to do it when IME showing because there are no rounded corners at // the bottom. This also avoids the problem of task bar height not changing when IME // floating. - if (!insetsState.isSourceOrDefaultVisible(InsetsState.ITYPE_IME, WindowInsets.Type.ime()) + if (!insetsState.isSourceOrDefaultVisible(InsetsSource.ID_IME, WindowInsets.Type.ime()) && taskBarInsetsSource != null && taskBarInsetsSource.getFrame().height() >= mExpandedTaskBarHeight) { mTempRect.inset(taskBarInsetsSource.calculateVisibleInsets(mTempRect)); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java index ffb1a4d66f1e..01e2f988fbfc 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java @@ -17,7 +17,7 @@ package com.android.wm.shell.common; import static android.view.Display.DEFAULT_DISPLAY; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.Surface.ROTATION_0; import static android.view.WindowInsets.Type.ime; @@ -138,15 +138,15 @@ public class DisplayImeControllerTest extends ShellTestCase { private InsetsSourceControl[] insetsSourceControl() { return new InsetsSourceControl[]{ new InsetsSourceControl( - ITYPE_IME, ime(), mock(SurfaceControl.class), false, new Point(0, 0), + ID_IME, ime(), mock(SurfaceControl.class), false, new Point(0, 0), Insets.NONE) }; } private InsetsState insetsStateWithIme(boolean visible) { InsetsState state = new InsetsState(); - state.addSource(new InsetsSource(ITYPE_IME, ime())); - state.setSourceVisible(ITYPE_IME, visible); + state.addSource(new InsetsSource(ID_IME, ime())); + state.setSourceVisible(ID_IME, visible); return state; } diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 8d9572b6cd12..a2c6487f47bf 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -46,7 +46,7 @@ import static android.view.Display.INVALID_DISPLAY; import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT; import static android.view.Display.STATE_UNKNOWN; import static android.view.Display.isSuspendedState; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_LEFT_GESTURES; import static android.view.InsetsState.ITYPE_RIGHT_GESTURES; import static android.view.Surface.ROTATION_0; @@ -3380,7 +3380,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp int getInputMethodWindowVisibleHeight() { final InsetsState state = getInsetsStateController().getRawInsetsState(); - final InsetsSource imeSource = state.peekSource(ITYPE_IME); + final InsetsSource imeSource = state.peekSource(ID_IME); if (imeSource == null || !imeSource.isVisible()) { return 0; } @@ -4034,7 +4034,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp final int imePid = mInputMethodWindow.mSession.mPid; mAtmService.onImeWindowSetOnDisplayArea(imePid, mImeWindowsContainer); } - mInsetsStateController.getSourceProvider(ITYPE_IME).setWindowContainer(win, + mInsetsStateController.getSourceProvider(ID_IME).setWindowContainer(win, mDisplayPolicy.getImeSourceFrameProvider(), null); computeImeTarget(true /* updateImeTarget */); updateImeControlTarget(); @@ -4284,7 +4284,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp // 3. The z-order of IME might have been changed. Update the above insets state. mInsetsStateController.updateAboveInsetsState( mInsetsStateController.getRawInsetsState().isSourceOrDefaultVisible( - ITYPE_IME, ime())); + ID_IME, ime())); // 4. Update the IME control target to apply any inset change and animation. // 5. Reparent the IME container surface to either the input target app, or the IME window // parent. @@ -4510,7 +4510,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp ProtoLog.i(WM_DEBUG_IME, "setInputMethodInputTarget %s", target); setImeInputTarget(target); mInsetsStateController.updateAboveInsetsState(mInsetsStateController - .getRawInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + .getRawInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); // Force updating the IME parent when the IME control target has been updated to the // remote target but updateImeParent not happen because ImeLayeringTarget and // ImeInputTarget are different. Then later updateImeParent would be ignored when there diff --git a/services/core/java/com/android/server/wm/DisplayFrames.java b/services/core/java/com/android/server/wm/DisplayFrames.java index de7db7f1d318..7f785af1671e 100644 --- a/services/core/java/com/android/server/wm/DisplayFrames.java +++ b/services/core/java/com/android/server/wm/DisplayFrames.java @@ -16,10 +16,7 @@ package com.android.server.wm; -import static android.view.InsetsState.ITYPE_BOTTOM_DISPLAY_CUTOUT; -import static android.view.InsetsState.ITYPE_LEFT_DISPLAY_CUTOUT; -import static android.view.InsetsState.ITYPE_RIGHT_DISPLAY_CUTOUT; -import static android.view.InsetsState.ITYPE_TOP_DISPLAY_CUTOUT; +import static android.view.InsetsSource.createId; import static android.view.WindowInsets.Type.displayCutout; import android.annotation.NonNull; @@ -39,6 +36,12 @@ import java.io.PrintWriter; * @hide */ public class DisplayFrames { + + private static final int ID_DISPLAY_CUTOUT_LEFT = createId(null, 0, displayCutout()); + private static final int ID_DISPLAY_CUTOUT_TOP = createId(null, 1, displayCutout()); + private static final int ID_DISPLAY_CUTOUT_RIGHT = createId(null, 2, displayCutout()); + private static final int ID_DISPLAY_CUTOUT_BOTTOM = createId(null, 3, displayCutout()); + public final InsetsState mInsetsState; /** @@ -98,28 +101,28 @@ public class DisplayFrames { state.setDisplayShape(displayShape); state.getDisplayCutoutSafe(safe); if (safe.left > unrestricted.left) { - state.getOrCreateSource(ITYPE_LEFT_DISPLAY_CUTOUT, displayCutout()).setFrame( + state.getOrCreateSource(ID_DISPLAY_CUTOUT_LEFT, displayCutout()).setFrame( unrestricted.left, unrestricted.top, safe.left, unrestricted.bottom); } else { - state.removeSource(ITYPE_LEFT_DISPLAY_CUTOUT); + state.removeSource(ID_DISPLAY_CUTOUT_LEFT); } if (safe.top > unrestricted.top) { - state.getOrCreateSource(ITYPE_TOP_DISPLAY_CUTOUT, displayCutout()).setFrame( + state.getOrCreateSource(ID_DISPLAY_CUTOUT_TOP, displayCutout()).setFrame( unrestricted.left, unrestricted.top, unrestricted.right, safe.top); } else { - state.removeSource(ITYPE_TOP_DISPLAY_CUTOUT); + state.removeSource(ID_DISPLAY_CUTOUT_TOP); } if (safe.right < unrestricted.right) { - state.getOrCreateSource(ITYPE_RIGHT_DISPLAY_CUTOUT, displayCutout()).setFrame( + state.getOrCreateSource(ID_DISPLAY_CUTOUT_RIGHT, displayCutout()).setFrame( safe.right, unrestricted.top, unrestricted.right, unrestricted.bottom); } else { - state.removeSource(ITYPE_RIGHT_DISPLAY_CUTOUT); + state.removeSource(ID_DISPLAY_CUTOUT_RIGHT); } if (safe.bottom < unrestricted.bottom) { - state.getOrCreateSource(ITYPE_BOTTOM_DISPLAY_CUTOUT, displayCutout()).setFrame( + state.getOrCreateSource(ID_DISPLAY_CUTOUT_BOTTOM, displayCutout()).setFrame( unrestricted.left, safe.bottom, unrestricted.right, unrestricted.bottom); } else { - state.removeSource(ITYPE_BOTTOM_DISPLAY_CUTOUT); + state.removeSource(ID_DISPLAY_CUTOUT_BOTTOM); } return true; } diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index d759ff555512..e87680ac5a16 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -1741,21 +1741,6 @@ public class DisplayPolicy { } /** - * Get the Navigation Bar Frame height. This dimension is the height of the navigation bar that - * is used for spacing to show additional buttons on the navigation bar (such as the ime - * switcher when ime is visible). - * - * @param rotation specifies rotation to return dimension from - * @return navigation bar frame height - */ - private int getNavigationBarFrameHeight(int rotation) { - if (mNavigationBar == null) { - return 0; - } - return mNavigationBar.mAttrs.forRotation(rotation).height; - } - - /** * Return corner radius in pixels that should be used on windows in order to cover the display. * * The radius is only valid for internal displays, since the corner radius of external displays diff --git a/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java b/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java index 85938e3bfd71..f38ae3f980a6 100644 --- a/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java +++ b/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java @@ -17,7 +17,7 @@ package com.android.server.wm; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_IME; import static com.android.server.wm.DisplayContent.IME_TARGET_CONTROL; @@ -57,7 +57,7 @@ final class ImeInsetsSourceProvider extends WindowContainerInsetsSourceProvider private Runnable mShowImeRunner; private boolean mIsImeLayoutDrawn; private boolean mImeShowing; - private final InsetsSource mLastSource = new InsetsSource(ITYPE_IME, WindowInsets.Type.ime()); + private final InsetsSource mLastSource = new InsetsSource(ID_IME, WindowInsets.Type.ime()); /** @see #setFrozen(boolean) */ private boolean mFrozen; diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index 50c4b1230967..bd821134f9b7 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -25,7 +25,7 @@ import static android.view.InsetsController.ANIMATION_TYPE_HIDE; import static android.view.InsetsController.ANIMATION_TYPE_SHOW; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_HIDDEN; import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.SyncRtSurfaceTransactionApplier.applyParams; @@ -315,12 +315,14 @@ class InsetsPolicy { // The caller should not receive the visible insets provided by itself. if (attrs.type == TYPE_INPUT_METHOD) { state = new InsetsState(state); - state.removeSource(ITYPE_IME); + state.removeSource(ID_IME); } else if (attrs.providedInsets != null) { for (InsetsFrameProvider provider : attrs.providedInsets) { // TODO(b/234093736): Let InsetsFrameProvider return the public type and the ID. final int sourceId = provider.type; - final @InsetsType int type = InsetsState.toPublicType(sourceId); + final @InsetsType int type = sourceId == ID_IME + ? WindowInsets.Type.ime() + : InsetsState.toPublicType(sourceId); if ((type & WindowInsets.Type.systemBars()) == 0) { continue; } @@ -399,7 +401,7 @@ class InsetsPolicy { // During switching tasks with gestural navigation, before the next IME input target // starts the input, we should adjust and freeze the last IME visibility of the window // in case delivering obsoleted IME insets state during transitioning. - final InsetsSource originalImeSource = originalState.peekSource(ITYPE_IME); + final InsetsSource originalImeSource = originalState.peekSource(ID_IME); if (originalImeSource != null) { final boolean imeVisibility = w.isRequestedVisible(Type.ime()); diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java index 49eaea2cfc9d..f5af2929c2bd 100644 --- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java +++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java @@ -16,7 +16,7 @@ package com.android.server.wm; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_WINDOW_INSETS; import static com.android.server.wm.InsetsSourceProviderProto.CAPTURED_LEASH; @@ -541,7 +541,7 @@ abstract class InsetsSourceProvider { return false; } for (int i = 0; i < providers.length; i++) { - if (providers[i].type == ITYPE_IME) { + if (providers[i].type == ID_IME) { return true; } } diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index 67a543c24b24..a3f62b2c5693 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -17,9 +17,9 @@ package com.android.server.wm; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_CLIMATE_BAR; import static android.view.InsetsState.ITYPE_EXTRA_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.WindowInsets.Type.displayCutout; @@ -38,7 +38,6 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.SparseArray; import android.util.proto.ProtoOutputStream; -import android.view.InsetsSource; import android.view.InsetsSourceControl; import android.view.InsetsState; import android.view.InsetsState.InternalInsetsType; @@ -97,14 +96,11 @@ class InsetsStateController { InsetsStateController(DisplayContent displayContent) { mDisplayContent = displayContent; - mSourceProviderFunc = type -> { - final InsetsSource source = mState.getOrCreateSource( - type, InsetsState.toPublicType(type)); - if (type == ITYPE_IME) { - return new ImeInsetsSourceProvider(source, this, mDisplayContent); - } - return new WindowContainerInsetsSourceProvider(source, this, mDisplayContent); - }; + mSourceProviderFunc = id -> (id == ID_IME) + ? new ImeInsetsSourceProvider(mState.getOrCreateSource( + id, ime()), this, mDisplayContent) + : new WindowContainerInsetsSourceProvider(mState.getOrCreateSource( + id, InsetsState.toPublicType(id)), this, mDisplayContent); } InsetsState getRawInsetsState() { @@ -129,14 +125,14 @@ class InsetsStateController { } /** - * @return The provider of a specific type. + * @return The provider of a specific source ID. */ - WindowContainerInsetsSourceProvider getSourceProvider(@InternalInsetsType int type) { - return mProviders.computeIfAbsent(type, mSourceProviderFunc); + WindowContainerInsetsSourceProvider getSourceProvider(int id) { + return mProviders.computeIfAbsent(id, mSourceProviderFunc); } ImeInsetsSourceProvider getImeSourceProvider() { - return (ImeInsetsSourceProvider) getSourceProvider(ITYPE_IME); + return (ImeInsetsSourceProvider) getSourceProvider(ID_IME); } /** @@ -221,7 +217,7 @@ class InsetsStateController { // Make sure that we always have a control target for the IME, even if the IME target is // null. Otherwise there is no leash that will hide it and IME becomes "randomly" visible. InsetsControlTarget target = imeTarget != null ? imeTarget : mEmptyImeControlTarget; - onControlChanged(ITYPE_IME, target); + onControlChanged(ID_IME, target); ProtoLog.d(WM_DEBUG_IME, "onImeControlTargetChanged %s", target != null ? target.getWindow() : "null"); notifyPendingInsetsControlChanged(); diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 2a51dcffd205..e206bbb733b6 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1879,8 +1879,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP return false; } for (int i = mProvidedInsetsSources.size() - 1; i >= 0; i--) { - final int type = mProvidedInsetsSources.keyAt(i); - if ((InsetsState.toPublicType(type) & WindowInsets.Type.navigationBars()) != 0) { + final InsetsSource source = mProvidedInsetsSources.valueAt(i); + if (source.getType() == WindowInsets.Type.navigationBars()) { return true; } } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 5c68d0e70ee5..56d59b41133a 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -48,7 +48,7 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS; import static android.os.Process.NOBODY_UID; import static android.view.Display.DEFAULT_DISPLAY; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.WindowInsets.Type.ime; import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; @@ -3177,11 +3177,11 @@ public class ActivityRecordTests extends WindowTestsBase { public void testImeInsetsFrozenFlag_resetWhenReportedToBeImeInputTarget() { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( + mDisplayContent.getInsetsStateController().getSourceProvider(ID_IME).setWindowContainer( mImeWindow, null, null); mImeWindow.getControllableInsetProvider().setServerVisible(true); - InsetsSource imeSource = new InsetsSource(ITYPE_IME, ime()); + InsetsSource imeSource = new InsetsSource(ID_IME, ime()); app.mAboveInsetsState.addSource(imeSource); mDisplayContent.setImeLayeringTarget(app); mDisplayContent.updateImeInputAndControlTarget(app); @@ -3211,8 +3211,8 @@ public class ActivityRecordTests extends WindowTestsBase { // Verify when IME is visible and the app can receive the right IME insets from policy. makeWindowVisibleAndDrawn(app, mImeWindow); state = app.getInsetsState(); - assertTrue(state.peekSource(ITYPE_IME).isVisible()); - assertEquals(state.peekSource(ITYPE_IME).getFrame(), imeSource.getFrame()); + assertTrue(state.peekSource(ID_IME).isVisible()); + assertEquals(state.peekSource(ID_IME).getFrame(), imeSource.getFrame()); } @SetupWindows(addWindows = { W_ACTIVITY, W_INPUT_METHOD }) @@ -3222,7 +3222,7 @@ public class ActivityRecordTests extends WindowTestsBase { final WindowState app1 = createWindow(null, TYPE_APPLICATION, "app1"); final WindowState app2 = createWindow(null, TYPE_APPLICATION, "app2"); - mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( + mDisplayContent.getInsetsStateController().getSourceProvider(ID_IME).setWindowContainer( mImeWindow, null, null); mImeWindow.getControllableInsetProvider().setServerVisible(true); @@ -3237,7 +3237,7 @@ public class ActivityRecordTests extends WindowTestsBase { mDisplayContent.getInsetsStateController().onInsetsModified(app1); // Verify app1's IME insets is visible and app2's IME insets frozen flag set. - assertTrue(app1.getInsetsState().peekSource(ITYPE_IME).isVisible()); + assertTrue(app1.getInsetsState().peekSource(ID_IME).isVisible()); assertTrue(app2.mActivityRecord.mImeInsetsFrozenUntilStartInput); // Simulate switching to app2 to make it visible to be IME targets. @@ -3256,7 +3256,7 @@ public class ActivityRecordTests extends WindowTestsBase { verify(app2.mClient, atLeastOnce()).resized(any(), anyBoolean(), any(), insetsStateCaptor.capture(), anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean()); - assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @Test @@ -3288,7 +3288,7 @@ public class ActivityRecordTests extends WindowTestsBase { makeWindowVisibleAndDrawn(app1, app2); final InsetsStateController controller = mDisplayContent.getInsetsStateController(); - controller.getSourceProvider(ITYPE_IME).setWindowContainer( + controller.getSourceProvider(ID_IME).setWindowContainer( ime, null, null); ime.getControllableInsetProvider().setServerVisible(true); @@ -3306,8 +3306,8 @@ public class ActivityRecordTests extends WindowTestsBase { controller.onInsetsModified(app1); // Expect all activities in split-screen will get IME insets visible state - assertTrue(app1.getInsetsState().peekSource(ITYPE_IME).isVisible()); - assertTrue(app2.getInsetsState().peekSource(ITYPE_IME).isVisible()); + assertTrue(app1.getInsetsState().peekSource(ID_IME).isVisible()); + assertTrue(app2.getInsetsState().peekSource(ID_IME).isVisible()); } @Test diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java index bd93523670f5..45cf530eddde 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java @@ -43,6 +43,7 @@ import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.view.DisplayInfo; import android.view.InsetsFrameProvider; +import android.view.InsetsSource; import android.view.InsetsState; import android.view.PrivacyIndicatorBounds; import android.view.RoundedCorners; @@ -255,7 +256,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mDisplayContent.getInsetsStateController().getRawInsetsState()); // Exclude comparing IME insets because currently the simulated layout only focuses on the // insets from status bar and navigation bar. - realInsetsState.removeSource(InsetsState.ITYPE_IME); + realInsetsState.removeSource(InsetsSource.ID_IME); realInsetsState.removeSource(InsetsState.ITYPE_CAPTION_BAR); assertEquals(new ToStringComparatorWrapper<>(realInsetsState), diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java index cf9ec81176c7..6bb77694b8cb 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java @@ -17,8 +17,8 @@ package com.android.server.wm; import static android.view.DisplayCutout.NO_CUTOUT; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_EXTRA_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.RoundedCorners.NO_ROUNDED_CORNERS; import static android.view.Surface.ROTATION_0; @@ -335,7 +335,7 @@ public class DisplayPolicyTests extends WindowTestsBase { displayPolicy.layoutWindowLw(mNavBarWindow, null, mDisplayContent.mDisplayFrames); displayPolicy.layoutWindowLw(mImeWindow, null, mDisplayContent.mDisplayFrames); - final InsetsSource imeSource = state.peekSource(ITYPE_IME); + final InsetsSource imeSource = state.peekSource(ID_IME); final InsetsSource navBarSource = state.peekSource(ITYPE_NAVIGATION_BAR); assertNotNull(imeSource); diff --git a/services/tests/wmtests/src/com/android/server/wm/ImeInsetsSourceProviderTest.java b/services/tests/wmtests/src/com/android/server/wm/ImeInsetsSourceProviderTest.java index d4e860e5ef21..20bb549301aa 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ImeInsetsSourceProviderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/ImeInsetsSourceProviderTest.java @@ -16,7 +16,7 @@ package com.android.server.wm; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.WindowInsets.Type.ime; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; @@ -39,7 +39,7 @@ import org.junit.runner.RunWith; @RunWith(WindowTestRunner.class) public class ImeInsetsSourceProviderTest extends WindowTestsBase { - private InsetsSource mImeSource = new InsetsSource(ITYPE_IME, ime()); + private InsetsSource mImeSource = new InsetsSource(ID_IME, ime()); private ImeInsetsSourceProvider mImeProvider; @Before diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java index 8b1a00dfd904..88ecd3fe2cea 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java @@ -19,9 +19,9 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_CLIMATE_BAR; import static android.view.InsetsState.ITYPE_EXTRA_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.WindowInsets.Type.ime; @@ -77,9 +77,9 @@ public class InsetsStateControllerTest extends WindowTestsBase { null); getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, null); - getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(ime, null, null); - assertNull(navBar.getInsetsState().peekSource(ITYPE_IME)); + assertNull(navBar.getInsetsState().peekSource(ID_IME)); assertNull(navBar.getInsetsState().peekSource(ITYPE_STATUS_BAR)); } @@ -97,7 +97,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { assertNull(app.getInsetsState().peekSource(ITYPE_STATUS_BAR)); assertNull(app.getInsetsState().peekSource(ITYPE_NAVIGATION_BAR)); - assertNull(app.getInsetsState().peekSource(ITYPE_IME)); + assertNull(app.getInsetsState().peekSource(ID_IME)); } @Test @@ -136,41 +136,41 @@ public class InsetsStateControllerTest extends WindowTestsBase { @SetupWindows(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_independentSources() { - getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(mImeWindow, null, null); final WindowState app1 = createWindow(null, TYPE_APPLICATION, "app1"); final WindowState app2 = createWindow(null, TYPE_APPLICATION, "app2"); - app1.mAboveInsetsState.addSource(getController().getRawInsetsState().peekSource(ITYPE_IME)); + app1.mAboveInsetsState.addSource(getController().getRawInsetsState().peekSource(ID_IME)); - getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertTrue(app1.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + getController().getRawInsetsState().setSourceVisible(ID_IME, true); + assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertTrue(app1.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @SetupWindows(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_belowIme() { - getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - app.mAboveInsetsState.getOrCreateSource(ITYPE_IME, ime()) + app.mAboveInsetsState.getOrCreateSource(ID_IME, ime()) .setVisible(true) .setFrame(mImeWindow.getFrame()); - getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + getController().getRawInsetsState().setSourceVisible(ID_IME, true); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @SetupWindows(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_aboveIme() { - getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertFalse(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + getController().getRawInsetsState().setSourceVisible(ID_IME, true); + assertFalse(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @SetupWindows(addWindows = W_INPUT_METHOD) @@ -184,7 +184,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { // Make IME and stay visible during the test. mImeWindow.setHasSurface(true); - getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(mImeWindow, null, null); getController().onImeControlTargetChanged( mDisplayContent.getImeInputTarget().getWindowState()); mDisplayContent.getImeInputTarget().getWindowState().setRequestedVisibleTypes(ime(), ime()); @@ -204,8 +204,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { mDisplayContent.applySurfaceChangesTransaction(); // app won't get visible IME insets while above IME even when IME is visible. - assertTrue(getController().getRawInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertFalse(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertTrue(getController().getRawInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertFalse(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); // Reset invocation counter. clearInvocations(app); @@ -214,7 +214,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; mDisplayContent.computeImeTarget(true); mDisplayContent.applySurfaceChangesTransaction(); - app.mAboveInsetsState.getOrCreateSource(ITYPE_IME, ime()) + app.mAboveInsetsState.getOrCreateSource(ID_IME, ime()) .setVisible(true) .setFrame(mImeWindow.getFrame()); @@ -222,13 +222,13 @@ public class InsetsStateControllerTest extends WindowTestsBase { verify(app, atLeastOnce()).notifyInsetsChanged(); // app will get visible IME insets while below IME. - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @SetupWindows(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_childWindow_altFocusable() { - getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); @@ -240,19 +240,19 @@ public class InsetsStateControllerTest extends WindowTestsBase { mDisplayContent.setLayoutNeeded(); mDisplayContent.applySurfaceChangesTransaction(); - getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertFalse(child.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + getController().getRawInsetsState().setSourceVisible(ID_IME, true); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertFalse(child.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @SetupWindows(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_childWindow_splitScreen() { - getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); - app.mAboveInsetsState.addSource(getController().getRawInsetsState().peekSource(ITYPE_IME)); + app.mAboveInsetsState.addSource(getController().getRawInsetsState().peekSource(ID_IME)); child.mAttrs.flags |= FLAG_NOT_FOCUSABLE; child.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); @@ -260,9 +260,9 @@ public class InsetsStateControllerTest extends WindowTestsBase { mDisplayContent.setLayoutNeeded(); mDisplayContent.applySurfaceChangesTransaction(); - getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertFalse(child.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + getController().getRawInsetsState().setSourceVisible(ID_IME, true); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertFalse(child.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @Test @@ -280,7 +280,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { imeOverrideProviders.put(TYPE_INPUT_METHOD, ((displayFrames, windowState, rect) -> rect.set(0, 1, 2, 3))); statusBarProvider.setWindowContainer(statusBar, null, imeOverrideProviders); - getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(ime, null, null); statusBar.setControllableInsetProvider(statusBarProvider); statusBar.updateSourceFrame(statusBar.getFrame()); @@ -409,11 +409,11 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState statusBar = createTestWindow("statusBar"); final WindowState navBar = createTestWindow("navBar"); - getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(ime, null, null); waitUntilHandlersIdle(); clearInvocations(mDisplayContent); - getController().getSourceProvider(ITYPE_IME).setClientVisible(true); + getController().getSourceProvider(ID_IME).setClientVisible(true); waitUntilHandlersIdle(); // The visibility change should trigger a traversal to notify the change. verify(mDisplayContent).notifyInsetsChanged(any()); @@ -426,9 +426,9 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().updateAboveInsetsState(false /* notifyInsetsChange */); // ime is below others. - assertNull(app.mAboveInsetsState.peekSource(ITYPE_IME)); - assertNull(statusBar.mAboveInsetsState.peekSource(ITYPE_IME)); - assertNull(navBar.mAboveInsetsState.peekSource(ITYPE_IME)); + assertNull(app.mAboveInsetsState.peekSource(ID_IME)); + assertNull(statusBar.mAboveInsetsState.peekSource(ID_IME)); + assertNull(navBar.mAboveInsetsState.peekSource(ID_IME)); assertNotNull(ime.mAboveInsetsState.peekSource(ITYPE_STATUS_BAR)); assertNotNull(ime.mAboveInsetsState.peekSource(ITYPE_NAVIGATION_BAR)); @@ -436,9 +436,9 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().updateAboveInsetsState(true /* notifyInsetsChange */); // ime is above others. - assertNotNull(app.mAboveInsetsState.peekSource(ITYPE_IME)); - assertNotNull(statusBar.mAboveInsetsState.peekSource(ITYPE_IME)); - assertNotNull(navBar.mAboveInsetsState.peekSource(ITYPE_IME)); + assertNotNull(app.mAboveInsetsState.peekSource(ID_IME)); + assertNotNull(statusBar.mAboveInsetsState.peekSource(ID_IME)); + assertNotNull(navBar.mAboveInsetsState.peekSource(ID_IME)); assertNull(ime.mAboveInsetsState.peekSource(ITYPE_STATUS_BAR)); assertNull(ime.mAboveInsetsState.peekSource(ITYPE_NAVIGATION_BAR)); @@ -454,7 +454,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState ime = createWindow(null, TYPE_INPUT_METHOD, imeToken, "ime"); final WindowState app = createTestWindow("app"); - getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); + getController().getSourceProvider(ID_IME).setWindowContainer(ime, null, null); ime.getControllableInsetProvider().setServerVisible(true); app.mActivityRecord.setVisibility(true); @@ -466,7 +466,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { assertTrue(ime.getControllableInsetProvider().getSource().isVisible()); getController().updateAboveInsetsState(true /* notifyInsetsChange */); - assertNotNull(app.getInsetsState().peekSource(ITYPE_IME)); + assertNotNull(app.getInsetsState().peekSource(ID_IME)); verify(app, atLeastOnce()).notifyInsetsChanged(); // Expect the app will still get IME insets even when the app was invisible. @@ -474,7 +474,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.mActivityRecord.setVisible(false); app.setHasSurface(false); getController().updateAboveInsetsState(true /* notifyInsetsChange */); - assertNotNull(app.getInsetsState().peekSource(ITYPE_IME)); + assertNotNull(app.getInsetsState().peekSource(ID_IME)); verify(app, atLeastOnce()).notifyInsetsChanged(); // Expect the app will get IME insets when the app is requesting visible. @@ -482,7 +482,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.mActivityRecord.setVisibility(true); assertTrue(app.isVisibleRequested()); getController().updateAboveInsetsState(true /* notifyInsetsChange */); - assertNotNull(app.getInsetsState().peekSource(ITYPE_IME)); + assertNotNull(app.getInsetsState().peekSource(ID_IME)); verify(app, atLeastOnce()).notifyInsetsChanged(); } @@ -504,7 +504,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState app2 = createTestWindow("app2"); makeWindowVisible(mImeWindow); - final InsetsSourceProvider imeInsetsProvider = getController().getSourceProvider(ITYPE_IME); + final InsetsSourceProvider imeInsetsProvider = getController().getSourceProvider(ID_IME); imeInsetsProvider.setWindowContainer(mImeWindow, null, null); imeInsetsProvider.updateSourceFrame(mImeWindow.getFrame()); diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContainerInsetsSourceProviderTest.java b/services/tests/wmtests/src/com/android/server/wm/WindowContainerInsetsSourceProviderTest.java index 19da7183a257..1e5ec4c4e48c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowContainerInsetsSourceProviderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowContainerInsetsSourceProviderTest.java @@ -16,7 +16,7 @@ package com.android.server.wm; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.statusBars; @@ -47,7 +47,7 @@ public class WindowContainerInsetsSourceProviderTest extends WindowTestsBase { private InsetsSource mSource = new InsetsSource(ITYPE_STATUS_BAR, statusBars()); private WindowContainerInsetsSourceProvider mProvider; - private InsetsSource mImeSource = new InsetsSource(ITYPE_IME, ime()); + private InsetsSource mImeSource = new InsetsSource(ID_IME, ime()); private WindowContainerInsetsSourceProvider mImeProvider; @Before diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java index 4d59c659e455..731a2351fc4d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowLayoutTests.java @@ -16,13 +16,9 @@ package com.android.server.wm; -import static android.view.InsetsState.ITYPE_BOTTOM_DISPLAY_CUTOUT; -import static android.view.InsetsState.ITYPE_IME; -import static android.view.InsetsState.ITYPE_LEFT_DISPLAY_CUTOUT; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; -import static android.view.InsetsState.ITYPE_RIGHT_DISPLAY_CUTOUT; import static android.view.InsetsState.ITYPE_STATUS_BAR; -import static android.view.InsetsState.ITYPE_TOP_DISPLAY_CUTOUT; import static android.view.WindowInsets.Type.displayCutout; import static android.view.WindowInsets.Type.ime; import static android.view.WindowInsets.Type.navigationBars; @@ -45,6 +41,7 @@ import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.view.DisplayCutout; import android.view.Gravity; +import android.view.InsetsSource; import android.view.InsetsState; import android.view.WindowInsets; import android.view.WindowLayout; @@ -122,14 +119,14 @@ public class WindowLayoutTests { new Rect(), WATERFALL_INSETS)); mState.getDisplayCutoutSafe(mDisplayCutoutSafe); - mState.getOrCreateSource(ITYPE_LEFT_DISPLAY_CUTOUT, displayCutout()).setFrame( - 0, 0, mDisplayCutoutSafe.left, DISPLAY_HEIGHT); - mState.getOrCreateSource(ITYPE_TOP_DISPLAY_CUTOUT, displayCutout()).setFrame( - 0, 0, DISPLAY_WIDTH, mDisplayCutoutSafe.top); - mState.getOrCreateSource(ITYPE_RIGHT_DISPLAY_CUTOUT, displayCutout()).setFrame( - mDisplayCutoutSafe.right, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT); - mState.getOrCreateSource(ITYPE_BOTTOM_DISPLAY_CUTOUT, displayCutout()).setFrame( - 0, mDisplayCutoutSafe.bottom, DISPLAY_WIDTH, DISPLAY_HEIGHT); + mState.getOrCreateSource(InsetsSource.createId(null, 0, displayCutout()), displayCutout()) + .setFrame(0, 0, mDisplayCutoutSafe.left, DISPLAY_HEIGHT); + mState.getOrCreateSource(InsetsSource.createId(null, 1, displayCutout()), displayCutout()) + .setFrame(0, 0, DISPLAY_WIDTH, mDisplayCutoutSafe.top); + mState.getOrCreateSource(InsetsSource.createId(null, 2, displayCutout()), displayCutout()) + .setFrame(mDisplayCutoutSafe.right, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT); + mState.getOrCreateSource(InsetsSource.createId(null, 3, displayCutout()), displayCutout()) + .setFrame(0, mDisplayCutoutSafe.bottom, DISPLAY_WIDTH, DISPLAY_HEIGHT); } private static void assertInsetByTopBottom(int top, int bottom, Rect actual) { @@ -294,7 +291,7 @@ public class WindowLayoutTests { @Test public void insetParentFrameByIme() { - mState.getOrCreateSource(ITYPE_IME, ime()) + mState.getOrCreateSource(ID_IME, ime()) .setVisible(true) .setFrame(0, DISPLAY_HEIGHT - IME_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT); mAttrs.privateFlags |= PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME; diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java index dacdd8209a7e..c44869b10642 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java @@ -20,7 +20,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; import static android.view.InsetsState.ITYPE_STATUS_BAR; import static android.view.Surface.ROTATION_0; @@ -1073,8 +1073,8 @@ public class WindowStateTests extends WindowTestsBase { controller.updateAboveInsetsState(false); // Expect all app windows behind IME can receive IME insets visible. - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertTrue(app2.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertTrue(app2.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); // Simulate app plays closing transition to app2. app.mActivityRecord.commitVisibility(false, false); @@ -1082,8 +1082,8 @@ public class WindowStateTests extends WindowTestsBase { assertTrue(app.mActivityRecord.mImeInsetsFrozenUntilStartInput); // Verify the IME insets is visible on app, but not for app2 during app task switching. - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @Test @@ -1112,8 +1112,8 @@ public class WindowStateTests extends WindowTestsBase { // Expect app windows behind IME can receive IME insets visible, // but not for app2 in background. - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); // Simulate app plays closing transition to app2. // And app2 is now IME layering target but not yet to be the IME input target. @@ -1123,8 +1123,8 @@ public class WindowStateTests extends WindowTestsBase { assertTrue(app.mActivityRecord.mImeInsetsFrozenUntilStartInput); // Verify the IME insets is still visible on app, but not for app2 during task switching. - assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); - assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertTrue(app.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); + assertFalse(app2.getInsetsState().isSourceOrDefaultVisible(ID_IME, ime())); } @SetupWindows(addWindows = W_ACTIVITY) @@ -1169,18 +1169,18 @@ public class WindowStateTests extends WindowTestsBase { mNotificationShadeWindow.setHasSurface(true); mNotificationShadeWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; assertTrue(mNotificationShadeWindow.canBeImeTarget()); - mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( + mDisplayContent.getInsetsStateController().getSourceProvider(ID_IME).setWindowContainer( mImeWindow, null, null); mDisplayContent.computeImeTarget(true); assertEquals(mNotificationShadeWindow, mDisplayContent.getImeTarget(IME_TARGET_LAYERING)); mDisplayContent.getInsetsStateController().getRawInsetsState() - .setSourceVisible(ITYPE_IME, true); + .setSourceVisible(ID_IME, true); // Verify notificationShade can still get IME insets even windowing mode is multi-window. InsetsState state = mNotificationShadeWindow.getInsetsState(); - assertNotNull(state.peekSource(ITYPE_IME)); - assertTrue(state.isSourceOrDefaultVisible(ITYPE_IME, ime())); + assertNotNull(state.peekSource(ID_IME)); + assertTrue(state.isSourceOrDefaultVisible(ID_IME, ime())); } @Test diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java index 3ff791b650ca..bd63560ee92f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java @@ -16,7 +16,7 @@ package com.android.server.wm; -import static android.view.InsetsState.ITYPE_IME; +import static android.view.InsetsSource.ID_IME; import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; @@ -262,7 +262,7 @@ public class WindowTokenTests extends WindowTestsBase { @Test public void testSetInsetsFrozen_notAffectImeWindowState() { // Pre-condition: make the IME window be controlled by IME insets provider. - mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( + mDisplayContent.getInsetsStateController().getSourceProvider(ID_IME).setWindowContainer( mDisplayContent.mInputMethodWindow, null, null); // Simulate an app window to be the IME layering target, assume the app window has no |