diff options
10 files changed, 158 insertions, 129 deletions
diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java index bf377b0bcfd7..d68e9032c19d 100644 --- a/core/java/android/view/InsetsState.java +++ b/core/java/android/view/InsetsState.java @@ -106,7 +106,9 @@ public class InsetsState implements Parcelable { public static final int ITYPE_NAVIGATION_BAR = 1; public static final int ITYPE_CAPTION_BAR = 2; - public static final int ITYPE_TOP_GESTURES = 3; + // The always visible types are visible to all windows regardless of the z-order. + public static final int FIRST_ALWAYS_VISIBLE_TYPE = 3; + public static final int ITYPE_TOP_GESTURES = FIRST_ALWAYS_VISIBLE_TYPE; public static final int ITYPE_BOTTOM_GESTURES = 4; public static final int ITYPE_LEFT_GESTURES = 5; public static final int ITYPE_RIGHT_GESTURES = 6; @@ -117,15 +119,16 @@ 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_TAPPABLE_ELEMENT = 11; - public static final int ITYPE_TOP_TAPPABLE_ELEMENT = 12; - public static final int ITYPE_RIGHT_TAPPABLE_ELEMENT = 13; - public static final int ITYPE_BOTTOM_TAPPABLE_ELEMENT = 14; + 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 LAST_ALWAYS_VISIBLE_TYPE = ITYPE_BOTTOM_DISPLAY_CUTOUT; - public static final int ITYPE_LEFT_DISPLAY_CUTOUT = 15; - public static final int ITYPE_TOP_DISPLAY_CUTOUT = 16; - public static final int ITYPE_RIGHT_DISPLAY_CUTOUT = 17; - public static final int ITYPE_BOTTOM_DISPLAY_CUTOUT = 18; + 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; @@ -182,6 +185,18 @@ public class InsetsState implements Parcelable { } /** + * Mirror the always visible sources from the other state. They will share the same object for + * the always visible types. + * + * @param other the state to mirror the mirrored sources from. + */ + public void mirrorAlwaysVisibleInsetsSources(InsetsState other) { + for (int type = FIRST_ALWAYS_VISIBLE_TYPE; type <= LAST_ALWAYS_VISIBLE_TYPE; type++) { + mSources[type] = other.mSources[type]; + } + } + + /** * Calculates {@link WindowInsets} based on the current source configuration. * * @param frame The frame to calculate the insets relative to. diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index ece101d2e605..2a018d93755a 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -670,8 +670,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp // Used in updating override configurations private final Configuration mTempConfig = new Configuration(); - // Used in performing layout - private boolean mTmpWindowsBehindIme; + // Used in performing layout, to record the insets provided by other windows above the current + // window. + private InsetsState mTmpAboveInsetsState = new InsetsState(); /** * Used to prevent recursions when calling @@ -770,17 +771,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp + " parentHidden=" + w.isParentWindowHidden()); } - // Sets mBehindIme for each window. Windows behind IME can get IME insets. - if (w.mBehindIme != mTmpWindowsBehindIme) { - w.mBehindIme = mTmpWindowsBehindIme; - if (getInsetsStateController().getRawInsetsState().getSourceOrDefaultVisibility( - ITYPE_IME)) { - // If IME is invisible, behind IME or not doesn't make the insets different. - mWinInsetsChanged.add(w); - } - } - if (w == mInputMethodWindow) { - mTmpWindowsBehindIme = true; + // Sets mAboveInsets for each window. Windows behind the window providing the insets can + // receive the insets. + if (!w.mAboveInsetsState.equals(mTmpAboveInsetsState)) { + w.mAboveInsetsState.set(mTmpAboveInsetsState); + mWinInsetsChanged.add(w); } // If this view is GONE, then skip it -- keep the current frame, and let the caller know @@ -816,8 +811,16 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp + " mContainingFrame=" + w.getContainingFrame() + " mDisplayFrame=" + w.getDisplayFrame()); } + provideInsetsByWindow(w); }; + private void provideInsetsByWindow(WindowState w) { + for (int i = 0; i < w.mProvidedInsetsSources.size(); i++) { + final InsetsSource providedSource = w.mProvidedInsetsSources.valueAt(i); + mTmpAboveInsetsState.addSource(providedSource); + } + } + private final Consumer<WindowState> mPerformLayoutAttached = w -> { if (w.mLayoutAttached) { if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame @@ -4283,14 +4286,20 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp + " dh=" + mDisplayInfo.logicalHeight); } + // Used to indicate that we have processed the insets windows. This needs to be after + // beginLayoutLw to ensure the raw insets state display related info is initialized. + final InsetsState rawInsetsState = getInsetsStateController().getRawInsetsState(); + mTmpAboveInsetsState = new InsetsState(); + mTmpAboveInsetsState.setDisplayFrame(rawInsetsState.getDisplayFrame()); + mTmpAboveInsetsState.setDisplayCutout(rawInsetsState.getDisplayCutout()); + mTmpAboveInsetsState.mirrorAlwaysVisibleInsetsSources(rawInsetsState); + int seq = mLayoutSeq + 1; if (seq < 0) seq = 0; mLayoutSeq = seq; mTmpInitial = initial; - // Used to indicate that we have processed the IME window. - mTmpWindowsBehindIme = false; // First perform layout of any root windows (not attached to another window). forAllWindows(mPerformLayout, true /* traverseTopToBottom */); diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java index 1692df6d82cd..c6c7fe083b16 100644 --- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java +++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java @@ -151,6 +151,7 @@ class InsetsSourceProvider { // animate-out as new one animates-in. mWin.cancelAnimation(); mWin.mPendingPositionChanged = null; + mWin.mProvidedInsetsSources.remove(mSource.getType()); } ProtoLog.d(WM_DEBUG_IME, "InsetsSource setWin %s", win); mWin = win; @@ -160,11 +161,14 @@ class InsetsSourceProvider { setServerVisible(false); mSource.setFrame(new Rect()); mSource.setVisibleFrame(null); - } else if (mControllable) { - mWin.setControllableInsetProvider(this); - if (mPendingControlTarget != null) { - updateControlForTarget(mPendingControlTarget, true /* force */); - mPendingControlTarget = null; + } else { + mWin.mProvidedInsetsSources.put(mSource.getType(), mSource); + if (mControllable) { + mWin.setControllableInsetProvider(this); + if (mPendingControlTarget != null) { + updateControlForTarget(mPendingControlTarget, true /* force */); + mPendingControlTarget = null; + } } } } diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index 267f67759a24..3ba7b7d96e47 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -104,6 +104,8 @@ class InsetsStateController { * visible to the target. e.g., the source which represents the target window itself, and the * IME source when the target is above IME. We also need to exclude certain types of insets * source for client within specific windowing modes. + * This is to get the insets for a window layout on the screen. If the window is not there, use + * the {@link #getInsetsForWindowMetrics} to get insets instead. * * @param target The window associate with the perspective. * @return The state stripped of the necessary information. @@ -117,8 +119,8 @@ class InsetsStateController { final @InternalInsetsType int type = provider != null ? provider.getSource().getType() : ITYPE_INVALID; return getInsetsForTarget(type, target.getWindowingMode(), target.isAlwaysOnTop(), - isAboveIme(target), - target.getFrozenInsetsState() != null ? target.getFrozenInsetsState() : mState); + target.getFrozenInsetsState() != null ? target.getFrozenInsetsState() : + target.mAboveInsetsState); } InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) { @@ -133,19 +135,7 @@ class InsetsStateController { final @WindowingMode int windowingMode = token != null ? token.getWindowingMode() : WINDOWING_MODE_UNDEFINED; final boolean alwaysOnTop = token != null && token.isAlwaysOnTop(); - return getInsetsForTarget(type, windowingMode, alwaysOnTop, isAboveIme(token), mState); - } - - private boolean isAboveIme(WindowContainer target) { - final WindowState imeWindow = mDisplayContent.mInputMethodWindow; - if (target == null || imeWindow == null) { - return false; - } - if (target instanceof WindowState) { - final WindowState win = (WindowState) target; - return win.needsRelativeLayeringToIme() || !win.mBehindIme; - } - return false; + return getInsetsForTarget(type, windowingMode, alwaysOnTop, mState); } private static @InternalInsetsType @@ -181,10 +171,12 @@ class InsetsStateController { * @see #getInsetsForWindowMetrics */ private InsetsState getInsetsForTarget(@InternalInsetsType int type, - @WindowingMode int windowingMode, boolean isAlwaysOnTop, boolean aboveIme, - @NonNull InsetsState state) { + @WindowingMode int windowingMode, boolean isAlwaysOnTop, InsetsState state) { + boolean stateCopied = false; + if (type != ITYPE_INVALID) { state = new InsetsState(state); + stateCopied = true; state.removeSource(type); // Navigation bar doesn't get influenced by anything else @@ -219,23 +211,15 @@ class InsetsStateController { if (WindowConfiguration.isFloating(windowingMode) || (windowingMode == WINDOWING_MODE_MULTI_WINDOW && isAlwaysOnTop)) { - state = new InsetsState(state); + if (!stateCopied) { + state = new InsetsState(state); + stateCopied = true; + } state.removeSource(ITYPE_STATUS_BAR); state.removeSource(ITYPE_NAVIGATION_BAR); state.removeSource(ITYPE_EXTRA_NAVIGATION_BAR); } - if (aboveIme) { - InsetsSource imeSource = state.peekSource(ITYPE_IME); - if (imeSource != null && imeSource.isVisible()) { - imeSource = new InsetsSource(imeSource); - imeSource.setVisible(false); - imeSource.setFrame(0, 0, 0, 0); - state = new InsetsState(state); - state.addSource(imeSource); - } - } - return state; } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 9a7823e35a01..1495b71ce9b3 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -212,6 +212,7 @@ import android.os.Trace; import android.os.WorkSource; import android.provider.Settings; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.ArraySet; import android.util.DisplayMetrics; import android.util.MergedConfiguration; @@ -647,9 +648,14 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP boolean mSeamlesslyRotated = false; /** - * Indicates if this window is behind IME. Only windows behind IME can get insets from IME. + * The insets state of sources provided by windows above the current window. */ - boolean mBehindIme = false; + InsetsState mAboveInsetsState = new InsetsState(); + + /** + * The insets sources provided by this window. + */ + ArrayMap<Integer, InsetsSource> mProvidedInsetsSources = new ArrayMap<>(); /** * Surface insets from the previous call to relayout(), used to track 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 82ffa765cc27..37fb0e930acc 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java @@ -123,6 +123,15 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { updateDisplayFrames(); } + void addWindowWithRawInsetsState(WindowState win) { + addWindow(win); + // Without mPerformLayout in display content, the window cannot see any insets. Override the + // insets state with the global one. + final InsetsState insetsState = + win.getDisplayContent().getInsetsStateController().getRawInsetsState(); + win.mAboveInsetsState = insetsState; + } + public void setRotation(int rotation, boolean includingWindows) { mRotation = rotation; updateDisplayFrames(); @@ -272,7 +281,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitStatusBars() { mWindow.mAttrs.setFitInsetsTypes(Type.statusBars()); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -283,7 +292,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitNavigationBars() { mWindow.mAttrs.setFitInsetsTypes(Type.navigationBars()); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -294,7 +303,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitAllSides() { mWindow.mAttrs.setFitInsetsSides(Side.all()); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -305,7 +314,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitTopOnly() { mWindow.mAttrs.setFitInsetsSides(Side.TOP); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -315,11 +324,12 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitInsetsIgnoringVisibility() { - final InsetsState state = mWindow.getInsetsState(); + final InsetsState state = + mDisplayContent.getInsetsStateController().getRawInsetsState(); state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false); mWindow.mAttrs.setFitInsetsIgnoringVisibility(true); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -329,11 +339,12 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitInsetsNotIgnoringVisibility() { - final InsetsState state = mWindow.getInsetsState(); + final InsetsState state = + mDisplayContent.getInsetsStateController().getRawInsetsState(); state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false); mWindow.mAttrs.setFitInsetsIgnoringVisibility(false); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -349,8 +360,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { state.getSource(InsetsState.ITYPE_IME).setFrame( 0, DISPLAY_HEIGHT - IME_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT); mWindow.mAttrs.privateFlags |= PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME; - mWindow.mBehindIme = true; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -364,7 +374,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.setFitInsetsTypes(Type.displayCutout()); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -379,7 +389,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -395,7 +405,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -411,7 +421,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -427,7 +437,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -442,7 +452,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -457,11 +467,12 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - mWindow.getInsetsState().getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); + mDisplayContent.getInsetsStateController().getRawInsetsState() + .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); final InsetsState requestedState = new InsetsState(); requestedState.getSource(ITYPE_STATUS_BAR).setVisible(false); mWindow.updateRequestedVisibility(requestedState); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -476,12 +487,13 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - mWindow.getInsetsState().getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); + mDisplayContent.getInsetsStateController().getRawInsetsState() + .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); final InsetsState requestedState = new InsetsState(); requestedState.getSource(ITYPE_STATUS_BAR).setVisible(false); mWindow.updateRequestedVisibility(requestedState); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -497,7 +509,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -513,7 +525,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -529,7 +541,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -545,7 +557,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.type = TYPE_APPLICATION_OVERLAY; mWindow.mAttrs.width = DISPLAY_WIDTH; mWindow.mAttrs.height = DISPLAY_HEIGHT; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -562,7 +574,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -576,7 +588,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -592,7 +604,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -608,7 +620,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -624,7 +636,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); @@ -638,7 +650,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; mWindow.mAttrs.setFitInsetsTypes(0 /* types */); mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING; - addWindow(mWindow); + addWindowWithRawInsetsState(mWindow); final int forwardedInsetBottom = 50; mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom)); @@ -776,9 +788,13 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { public void testFixedRotationInsetsSourceFrame() { doReturn((mDisplayContent.getRotation() + 1) % 4).when(mDisplayContent) .rotationForActivityInDifferentOrientation(eq(mWindow.mActivityRecord)); - final Rect frame = mWindow.getInsetsState().getSource(ITYPE_STATUS_BAR).getFrame(); + mWindow.mAboveInsetsState.addSource(mDisplayContent.getInsetsStateController() + .getRawInsetsState().peekSource(ITYPE_STATUS_BAR)); + final Rect frame = mDisplayPolicy.getInsetsPolicy().getInsetsForWindow(mWindow) + .getSource(ITYPE_STATUS_BAR).getFrame(); mDisplayContent.rotateInDifferentOrientationIfNeeded(mWindow.mActivityRecord); - final Rect rotatedFrame = mWindow.getInsetsState().getSource(ITYPE_STATUS_BAR).getFrame(); + final Rect rotatedFrame = mDisplayPolicy.getInsetsPolicy().getInsetsForWindow(mWindow) + .getSource(ITYPE_STATUS_BAR).getFrame(); assertEquals(DISPLAY_WIDTH, frame.width()); assertEquals(DISPLAY_HEIGHT, rotatedFrame.width()); 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 77537a9de6be..499507e969cf 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java @@ -300,6 +300,7 @@ public class DisplayPolicyTests extends WindowTestsBase { displayPolicy.addWindowLw(mNavBarWindow, mNavBarWindow.mAttrs); mNavBarWindow.getControllableInsetProvider().setServerVisible(true); final InsetsState state = mDisplayContent.getInsetsStateController().getRawInsetsState(); + mImeWindow.mAboveInsetsState = state; mDisplayContent.mDisplayFrames = new DisplayFrames(mDisplayContent.getDisplayId(), state, displayInfo, null /* displayCutout */); diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java index e0fd3796f2aa..bf3ed692dc8e 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java @@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify; import android.app.StatusBarManager; import android.platform.test.annotations.Presubmit; +import android.view.InsetsSource; import android.view.InsetsSourceControl; import android.view.InsetsState; @@ -272,7 +273,6 @@ public class InsetsPolicyTest extends WindowTestsBase { final WindowState navBar = addNonFocusableWindow(TYPE_NAVIGATION_BAR, "navBar"); navBar.setHasSurface(true); navBar.getControllableInsetProvider().setServerVisible(true); - final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); doNothing().when(policy).startAnimation(anyBoolean(), any()); @@ -337,11 +337,14 @@ public class InsetsPolicyTest extends WindowTestsBase { @UseTestDisplay(addWindows = W_ACTIVITY) @Test public void testAbortTransientBars_bothCanBeAborted_appGetsBothRealControls() { - addNonFocusableWindow(TYPE_STATUS_BAR, "statusBar") - .getControllableInsetProvider().getSource().setVisible(false); - addNonFocusableWindow(TYPE_NAVIGATION_BAR, "navBar") - .getControllableInsetProvider().getSource().setVisible(false); - + final InsetsSource statusBarSource = addNonFocusableWindow(TYPE_STATUS_BAR, "statusBar") + .getControllableInsetProvider().getSource(); + final InsetsSource navBarSource = addNonFocusableWindow(TYPE_NAVIGATION_BAR, "navBar") + .getControllableInsetProvider().getSource(); + statusBarSource.setVisible(false); + navBarSource.setVisible(false); + mAppWindow.mAboveInsetsState.addSource(navBarSource); + mAppWindow.mAboveInsetsState.addSource(statusBarSource); final InsetsPolicy policy = spy(mDisplayContent.getInsetsPolicy()); doNothing().when(policy).startAnimation(anyBoolean(), any()); policy.updateBarControlTarget(mAppWindow); 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 276643847712..2107ab1eeeea 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java @@ -59,25 +59,6 @@ import org.junit.runner.RunWith; public class InsetsStateControllerTest extends WindowTestsBase { @Test - public void testStripForDispatch_notOwn() { - final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); - final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); - assertNotNull(getController().getInsetsForWindow(app).peekSource(ITYPE_STATUS_BAR)); - } - - @Test - public void testStripForDispatch_own() { - final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); - mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR) - .setWindow(statusBar, null, null); - statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); - final InsetsState state = getController().getInsetsForWindow(statusBar); - assertNull(state.peekSource(ITYPE_STATUS_BAR)); - } - - @Test public void testStripForDispatch_navBar() { final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); @@ -142,14 +123,15 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); final WindowState app1 = createWindow(null, TYPE_APPLICATION, "app1"); - app1.mBehindIme = true; - final WindowState app2 = createWindow(null, TYPE_APPLICATION, "app2"); - app2.mBehindIme = false; + + app1.mAboveInsetsState.addSource(getController().getRawInsetsState().getSource(ITYPE_IME)); getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertFalse(getController().getInsetsForWindow(app2).getSource(ITYPE_IME).isVisible()); - assertTrue(getController().getInsetsForWindow(app1).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(app2).getSource(ITYPE_IME) + .isVisible()); + assertTrue(getController().getInsetsForWindow(app1).getSource(ITYPE_IME) + .isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -158,7 +140,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - app.mBehindIme = true; + app.mAboveInsetsState.getSource(ITYPE_IME).setVisible(true); + app.mAboveInsetsState.getSource(ITYPE_IME).setFrame(mImeWindow.getFrame()); getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); @@ -170,10 +153,10 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - app.mBehindIme = false; getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertFalse(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(app).getSource(ITYPE_IME) + .isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -210,7 +193,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { // app won't get visible IME insets while above IME even when IME is visible. assertTrue(getController().getRawInsetsState().getSourceOrDefaultVisibility(ITYPE_IME)); - assertFalse(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(app).getSource(ITYPE_IME) + .isVisible()); // Reset invocation counter. clearInvocations(app); @@ -219,6 +203,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; mDisplayContent.computeImeTarget(true); mDisplayContent.applySurfaceChangesTransaction(); + app.mAboveInsetsState.getSource(ITYPE_IME).setVisible(true); + app.mAboveInsetsState.getSource(ITYPE_IME).setFrame(mImeWindow.getFrame()); // Make sure app got notified. verify(app, atLeast(1)).notifyInsetsChanged(); @@ -234,6 +220,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); + app.mAboveInsetsState.set(getController().getRawInsetsState()); + child.mAboveInsetsState.set(getController().getRawInsetsState()); child.mAttrs.flags |= FLAG_ALT_FOCUSABLE_IM; mDisplayContent.computeImeTarget(true); @@ -242,7 +230,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); - assertFalse(getController().getInsetsForWindow(child).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(child).getSource(ITYPE_IME) + .isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -252,6 +241,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); + app.mAboveInsetsState.addSource(getController().getRawInsetsState().peekSource(ITYPE_IME)); child.mAttrs.flags |= FLAG_NOT_FOCUSABLE; child.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); @@ -261,7 +251,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); - assertFalse(getController().getInsetsForWindow(child).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(child).getSource(ITYPE_IME) + .isVisible()); } @Test diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java index 1607f013ee81..a1f89ec75784 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowFrameTests.java @@ -275,7 +275,7 @@ public class WindowFrameTests extends WindowTestsBase { imeSource.setFrame(imeFrame); imeSource.setVisible(true); w.updateRequestedVisibility(state); - w.mBehindIme = true; + w.mAboveInsetsState.addSource(imeSource); // With no insets or system decor all the frames incoming from PhoneWindowManager // are identical. |