From f60944f1426dcc635735ab61f37ad2d118e1ab7f Mon Sep 17 00:00:00 2001 From: Gaurav Bhola Date: Wed, 1 Dec 2021 01:38:42 +0000 Subject: [PATCH] Move insets related logic from WindowState to WindowContainer. - This will help to make the insets flow through the hierarchy. Bug: 199449177 Test: atest InsetsStateControllerTest Test: atest InsetsPolicyTest Test: atest InsetsSourceProviderTest Test: atest WindowStateTests Change-Id: I8a8385b6688504457a8597afd53ae00a65d4dc42 --- .../com/android/server/wm/DisplayContent.java | 14 +- .../com/android/server/wm/DisplayPolicy.java | 49 +++-- .../server/wm/ImeInsetsSourceProvider.java | 16 +- .../com/android/server/wm/InsetsPolicy.java | 5 +- .../server/wm/InsetsSourceProvider.java | 180 +++++++++++------- .../server/wm/InsetsStateController.java | 6 +- .../android/server/wm/WindowContainer.java | 48 ++++- .../com/android/server/wm/WindowState.java | 25 --- .../server/wm/ActivityRecordTests.java | 2 +- .../wm/ImeInsetsSourceProviderTest.java | 2 +- .../server/wm/InsetsSourceProviderTest.java | 22 +-- .../server/wm/InsetsStateControllerTest.java | 84 ++++---- .../android/server/wm/WindowStateTests.java | 21 +- .../android/server/wm/WindowTokenTests.java | 2 +- 14 files changed, 284 insertions(+), 192 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 2a06d8b8653d1..5c9251e479538 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1362,8 +1362,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp return mDisplayRotation; } - void setInsetProvider(@InternalInsetsType int type, WindowState win, - @Nullable TriConsumer frameProvider){ + void setInsetProvider(@InternalInsetsType int type, WindowContainer win, + @Nullable TriConsumer frameProvider) { setInsetProvider(type, win, frameProvider, null /* imeFrameProvider */); } @@ -1377,10 +1377,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp * @param imeFrameProvider Function to compute the frame when dispatching insets to the IME, or * {@code null} if the normal frame should be taken. */ - void setInsetProvider(@InternalInsetsType int type, WindowState win, - @Nullable TriConsumer frameProvider, - @Nullable TriConsumer imeFrameProvider) { - mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider, + void setInsetProvider(@InternalInsetsType int type, WindowContainer win, + @Nullable TriConsumer frameProvider, + @Nullable TriConsumer imeFrameProvider) { + mInsetsStateController.getSourceProvider(type).setWindowContainer(win, frameProvider, imeFrameProvider); } @@ -3822,7 +3822,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp final int imePid = mInputMethodWindow.mSession.mPid; mAtmService.onImeWindowSetOnDisplayArea(imePid, mImeWindowsContainer); } - mInsetsStateController.getSourceProvider(ITYPE_IME).setWindow(win, + mInsetsStateController.getSourceProvider(ITYPE_IME).setWindowContainer(win, mDisplayPolicy.getImeSourceFrameProvider(), null /* imeFrameProvider */); computeImeTarget(true /* updateImeTarget */); updateImeControlTarget(); diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 30fffd32a2580..4148d8b7d8534 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -1106,8 +1106,8 @@ public class DisplayPolicy { break; case TYPE_STATUS_BAR: mStatusBar = win; - final TriConsumer gestureFrameProvider = - (displayFrames, windowState, rect) -> { + final TriConsumer gestureFrameProvider = + (displayFrames, windowContainer, rect) -> { rect.bottom = rect.top + getStatusBarHeight(displayFrames); final DisplayCutout cutout = displayFrames.mInsetsState.getDisplayCutout(); @@ -1128,24 +1128,25 @@ public class DisplayPolicy { case TYPE_NAVIGATION_BAR: mNavigationBar = win; mDisplayContent.setInsetProvider(ITYPE_NAVIGATION_BAR, win, - (displayFrames, windowState, inOutFrame) -> { + (displayFrames, windowContainer, inOutFrame) -> { if (!mNavButtonForcedVisible) { - inOutFrame.inset(windowState.getLayoutingAttrs( + inOutFrame.inset(win.getLayoutingAttrs( displayFrames.mRotation).providedInternalInsets); inOutFrame.inset(win.mGivenContentInsets); } }, // For IME we use regular frame. - (displayFrames, windowState, inOutFrame) -> - inOutFrame.set(windowState.getFrame())); + (displayFrames, windowContainer, inOutFrame) -> { + inOutFrame.set(win.getFrame()); + }); mDisplayContent.setInsetProvider(ITYPE_BOTTOM_MANDATORY_GESTURES, win, - (displayFrames, windowState, inOutFrame) -> { + (displayFrames, windowContainer, inOutFrame) -> { inOutFrame.top -= mBottomGestureAdditionalInset; }); mDisplayContent.setInsetProvider(ITYPE_LEFT_GESTURES, win, - (displayFrames, windowState, inOutFrame) -> { + (displayFrames, windowContainer, inOutFrame) -> { final int leftSafeInset = Math.max(displayFrames.mDisplayCutoutSafe.left, 0); inOutFrame.left = 0; @@ -1154,7 +1155,7 @@ public class DisplayPolicy { inOutFrame.right = leftSafeInset + mLeftGestureInset; }); mDisplayContent.setInsetProvider(ITYPE_RIGHT_GESTURES, win, - (displayFrames, windowState, inOutFrame) -> { + (displayFrames, windowContainer, inOutFrame) -> { final int rightSafeInset = Math.min(displayFrames.mDisplayCutoutSafe.right, displayFrames.mUnrestricted.right); @@ -1164,8 +1165,8 @@ public class DisplayPolicy { inOutFrame.right = displayFrames.mDisplayWidth; }); mDisplayContent.setInsetProvider(ITYPE_BOTTOM_TAPPABLE_ELEMENT, win, - (displayFrames, windowState, inOutFrame) -> { - if ((windowState.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 + (displayFrames, windowContainer, inOutFrame) -> { + if ((win.getAttrs().flags & FLAG_NOT_TOUCHABLE) != 0 || mNavigationBarLetsThroughTaps) { inOutFrame.setEmpty(); } @@ -1176,11 +1177,13 @@ public class DisplayPolicy { default: if (attrs.providesInsetsTypes != null) { for (@InternalInsetsType int insetsType : attrs.providesInsetsTypes) { - final TriConsumer imeFrameProvider = + final TriConsumer imeFrameProvider = !attrs.providedInternalImeInsets.equals(Insets.NONE) - ? (displayFrames, windowState, inOutFrame) -> - inOutFrame.inset(windowState.getLayoutingAttrs( - displayFrames.mRotation).providedInternalImeInsets) + ? (displayFrames, windowContainer, inOutFrame) -> { + inOutFrame.inset(win.getLayoutingAttrs( + displayFrames.mRotation) + .providedInternalImeInsets); + } : null; switch (insetsType) { case ITYPE_STATUS_BAR: @@ -1201,10 +1204,9 @@ public class DisplayPolicy { break; } mDisplayContent.setInsetProvider(insetsType, win, (displayFrames, - windowState, inOutFrame) -> { - inOutFrame.inset( - windowState.getLayoutingAttrs(displayFrames.mRotation) - .providedInternalInsets); + windowContainer, inOutFrame) -> { + inOutFrame.inset(win.getLayoutingAttrs( + displayFrames.mRotation).providedInternalInsets); inOutFrame.inset(win.mGivenContentInsets); }, imeFrameProvider); mInsetsSourceWindowsExceptIme.add(win); @@ -1230,8 +1232,13 @@ public class DisplayPolicy { } } - TriConsumer getImeSourceFrameProvider() { - return (displayFrames, windowState, inOutFrame) -> { + TriConsumer getImeSourceFrameProvider() { + return (displayFrames, windowContainer, inOutFrame) -> { + WindowState windowState = windowContainer.asWindowState(); + if (windowState == null) { + throw new IllegalArgumentException("IME insets must be provided by a window."); + } + if (mNavigationBar != null && navigationBarPosition(displayFrames.mRotation) == NAV_BAR_BOTTOM) { // In gesture navigation, nav bar frame is larger than frame to calculate insets. diff --git a/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java b/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java index cbefe7f3ade4d..8f972209d124e 100644 --- a/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java +++ b/services/core/java/com/android/server/wm/ImeInsetsSourceProvider.java @@ -113,8 +113,8 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider { private void reportImeDrawnForOrganizer(InsetsControlTarget caller) { if (caller.getWindow() != null && caller.getWindow().getTask() != null) { if (caller.getWindow().getTask().isOrganized()) { - mWin.mWmService.mAtmService.mTaskOrganizerController.reportImeDrawnOnTask( - caller.getWindow().getTask()); + mWindowContainer.mWmService.mAtmService.mTaskOrganizerController + .reportImeDrawnOnTask(caller.getWindow().getTask()); } } } @@ -173,12 +173,18 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider { } void checkShowImePostLayout() { + if (mWindowContainer == null) { + return; + } + WindowState windowState = mWindowContainer.asWindowState(); + if (windowState == null) { + throw new IllegalArgumentException("IME insets must be provided by a window."); + } // check if IME is drawn if (mIsImeLayoutDrawn || (isReadyToShowIme() - && mWin != null - && mWin.isDrawn() - && !mWin.mGivenInsetsPending)) { + && windowState.isDrawn() + && !windowState.mGivenInsetsPending)) { mIsImeLayoutDrawn = true; // show IME if InputMethodService requested it to be shown. if (mShowImeRunner != null) { diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index 7d2d13f70b70a..433f107133cca 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -176,8 +176,9 @@ class InsetsPolicy { } boolean isHidden(@InternalInsetsType int type) { - final InsetsSourceProvider provider = mStateController.peekSourceProvider(type); - return provider != null && provider.hasWindow() && !provider.getSource().isVisible(); + final InsetsSourceProvider provider = mStateController.peekSourceProvider(type); + return provider != null && provider.hasWindowContainer() + && !provider.getSource().isVisible(); } void showTransient(@InternalInsetsType int[] types, boolean isGestureOnSystemBar) { diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java index 21eea940f1357..4c7a297542343 100644 --- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java +++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java @@ -69,7 +69,7 @@ class InsetsSourceProvider { protected final DisplayContent mDisplayContent; protected final @NonNull InsetsSource mSource; - protected WindowState mWin; + protected WindowContainer mWindowContainer; private final Rect mTmpRect = new Rect(); private final InsetsStateController mStateController; @@ -80,8 +80,8 @@ class InsetsSourceProvider { private @Nullable InsetsControlTarget mFakeControlTarget; private @Nullable ControlAdapter mAdapter; - private TriConsumer mFrameProvider; - private TriConsumer mImeFrameProvider; + private TriConsumer mFrameProvider; + private TriConsumer mImeFrameProvider; private final Rect mImeOverrideFrame = new Rect(); private boolean mIsLeashReadyForDispatching; private final Rect mLastSourceFrame = new Rect(); @@ -100,7 +100,8 @@ class InsetsSourceProvider { private boolean mClientVisible; /** - * Whether the window is available and considered visible as in {@link WindowState#isVisible}. + * Whether the window container is available and considered visible as in + * {@link WindowContainer#isVisible}. */ private boolean mServerVisible; @@ -109,8 +110,8 @@ class InsetsSourceProvider { private final boolean mControllable; /** - * Whether to forced the dimensions of the source window to the inset frame and crop out any - * overflow. + * Whether to forced the dimensions of the source window container to the inset frame and crop + * out any overflow. * Used to crop the taskbar inset source when a task animation is occurring to hide the taskbar * rounded corners overlays. * @@ -152,42 +153,42 @@ class InsetsSourceProvider { } /** - * Updates the window that currently backs this source. + * Updates the window container that currently backs this source. * - * @param win The window that links to this source. + * @param windowContainer The window container that links to this source. * @param frameProvider Based on display frame state and the window, calculates the resulting * frame that should be reported to clients. * @param imeFrameProvider Based on display frame state and the window, calculates the resulting * frame that should be reported to IME. */ - void setWindow(@Nullable WindowState win, - @Nullable TriConsumer frameProvider, - @Nullable TriConsumer imeFrameProvider) { - if (mWin != null) { + void setWindowContainer(@Nullable WindowContainer windowContainer, + @Nullable TriConsumer frameProvider, + @Nullable TriConsumer imeFrameProvider) { + if (mWindowContainer != null) { if (mControllable) { - mWin.setControllableInsetProvider(null); + mWindowContainer.setControllableInsetProvider(null); } - // The window may be animating such that we can hand out the leash to the control - // target. Revoke the leash by cancelling the animation to correct the state. + // The window container may be animating such that we can hand out the leash to the + // control target. Revoke the leash by cancelling the animation to correct the state. // TODO: Ideally, we should wait for the animation to finish so previous window can // animate-out as new one animates-in. - mWin.cancelAnimation(); - mWin.mProvidedInsetsSources.remove(mSource.getType()); + mWindowContainer.cancelAnimation(); + mWindowContainer.getProvidedInsetsSources().remove(mSource.getType()); mSeamlessRotating = false; } - ProtoLog.d(WM_DEBUG_WINDOW_INSETS, "InsetsSource setWin %s for type %s", win, - InsetsState.typeToString(mSource.getType())); - mWin = win; + ProtoLog.d(WM_DEBUG_WINDOW_INSETS, "InsetsSource setWin %s for type %s", + windowContainer, InsetsState.typeToString(mSource.getType())); + mWindowContainer = windowContainer; mFrameProvider = frameProvider; mImeFrameProvider = imeFrameProvider; - if (win == null) { + if (windowContainer == null) { setServerVisible(false); mSource.setFrame(new Rect()); mSource.setVisibleFrame(null); } else { - mWin.mProvidedInsetsSources.put(mSource.getType(), mSource); + mWindowContainer.getProvidedInsetsSources().put(mSource.getType(), mSource); if (mControllable) { - mWin.setControllableInsetProvider(this); + mWindowContainer.setControllableInsetProvider(this); if (mPendingControlTarget != null) { updateControlForTarget(mPendingControlTarget, true /* force */); mPendingControlTarget = null; @@ -197,18 +198,39 @@ class InsetsSourceProvider { } /** - * @return Whether there is a window which backs this source. + * @return Whether there is a window container which backs this source. */ - boolean hasWindow() { - return mWin != null; + boolean hasWindowContainer() { + return mWindowContainer != null; } /** * The source frame can affect the layout of other windows, so this should be called once the - * window gets laid out. + * window container gets laid out. */ void updateSourceFrame() { - if (mWin == null || mWin.mGivenInsetsPending) { + if (mWindowContainer == null) { + return; + } + WindowState win = mWindowContainer.asWindowState(); + + if (win == null) { + // For all the non window WindowContainers. + if (mServerVisible) { + mTmpRect.set(mWindowContainer.getBounds()); + if (mFrameProvider != null) { + mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames, + mWindowContainer, mTmpRect); + } + } else { + mTmpRect.setEmpty(); + } + mSource.setFrame(mTmpRect); + mSource.setVisibleFrame(null); + return; + } + + if (win.mGivenInsetsPending) { // If the given insets are pending, they are not reliable for now. The source frame // should be updated after the new given insets are sent to window manager. return; @@ -218,11 +240,12 @@ class InsetsSourceProvider { // frame may not yet determined that server side doesn't think the window is ready to // visible. (i.e. No surface, pending insets that were given during layout, etc..) if (mServerVisible) { - mTmpRect.set(mWin.getFrame()); + mTmpRect.set(win.getFrame()); if (mFrameProvider != null) { - mFrameProvider.accept(mWin.getDisplayContent().mDisplayFrames, mWin, mTmpRect); + mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames, + mWindowContainer, mTmpRect); } else { - mTmpRect.inset(mWin.mGivenContentInsets); + mTmpRect.inset(win.mGivenContentInsets); } } else { mTmpRect.setEmpty(); @@ -230,15 +253,17 @@ class InsetsSourceProvider { mSource.setFrame(mTmpRect); if (mImeFrameProvider != null) { - mImeOverrideFrame.set(mWin.getFrame()); - mImeFrameProvider.accept(mWin.getDisplayContent().mDisplayFrames, mWin, + mImeOverrideFrame.set(win.getFrame()); + mImeFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames, + mWindowContainer, mImeOverrideFrame); } - if (mWin.mGivenVisibleInsets.left != 0 || mWin.mGivenVisibleInsets.top != 0 - || mWin.mGivenVisibleInsets.right != 0 || mWin.mGivenVisibleInsets.bottom != 0) { - mTmpRect.set(mWin.getFrame()); - mTmpRect.inset(mWin.mGivenVisibleInsets); + if (win.mGivenVisibleInsets.left != 0 || win.mGivenVisibleInsets.top != 0 + || win.mGivenVisibleInsets.right != 0 + || win.mGivenVisibleInsets.bottom != 0) { + mTmpRect.set(win.getFrame()); + mTmpRect.inset(win.mGivenVisibleInsets); mSource.setVisibleFrame(mTmpRect); } else { mSource.setVisibleFrame(null); @@ -253,7 +278,7 @@ class InsetsSourceProvider { source.setVisible(mSource.isVisible()); mTmpRect.set(winFrame); if (mFrameProvider != null) { - mFrameProvider.accept(displayFrames, mWin, mTmpRect); + mFrameProvider.accept(displayFrames, mWindowContainer, mTmpRect); } source.setFrame(mTmpRect); return source; @@ -263,27 +288,30 @@ class InsetsSourceProvider { * Called when a layout pass has occurred. */ void onPostLayout() { - if (mWin == null) { + if (mWindowContainer == null) { return; } - - setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.isVisibleByPolicy()); + WindowState windowState = mWindowContainer.asWindowState(); + boolean isServerVisible = windowState != null + ? windowState.wouldBeVisibleIfPolicyIgnored() && windowState.isVisibleByPolicy() + : mWindowContainer.isVisibleRequested(); + setServerVisible(isServerVisible); updateSourceFrame(); if (mControl != null) { boolean changed = false; final Point position = getWindowFrameSurfacePosition(); if (mControl.setSurfacePosition(position.x, position.y) && mControlTarget != null) { changed = true; - if (mWin.getWindowFrames().didFrameSizeChange() && mWin.mWinAnimator.getShown() - && mWin.okToDisplay()) { - mWin.applyWithNextDraw(mSetLeashPositionConsumer); + if (windowState != null && windowState.getWindowFrames().didFrameSizeChange() + && windowState.mWinAnimator.getShown() && mWindowContainer.okToDisplay()) { + windowState.applyWithNextDraw(mSetLeashPositionConsumer); } else { - mSetLeashPositionConsumer.accept(mWin.getSyncTransaction()); + mSetLeashPositionConsumer.accept(mWindowContainer.getSyncTransaction()); } } if (mServerVisible && !mLastSourceFrame.equals(mSource.getFrame())) { final Insets insetsHint = mSource.calculateInsets( - mWin.getBounds(), true /* ignoreVisibility */); + mWindowContainer.getBounds(), true /* ignoreVisibility */); if (!insetsHint.equals(mControl.getInsetsHint())) { changed = true; mControl.setInsetsHint(insetsHint); @@ -297,17 +325,19 @@ class InsetsSourceProvider { } private Point getWindowFrameSurfacePosition() { + WindowState win = mWindowContainer.asWindowState(); if (mControl != null) { final AsyncRotationController controller = - mWin.mDisplayContent.getAsyncRotationController(); - if (controller != null && controller.shouldFreezeInsetsPosition(mWin)) { + win.mDisplayContent.getAsyncRotationController(); + if (controller != null && controller.shouldFreezeInsetsPosition(win)) { // Use previous position because the fade-out animation runs in old rotation. return mControl.getSurfacePosition(); } } - final Rect frame = mWin.getFrame(); + final Rect frame = mWindowContainer.asWindowState() != null + ? mWindowContainer.asWindowState().getFrame() : mWindowContainer.getBounds(); final Point position = new Point(); - mWin.transformFrameToSurfacePosition(frame.left, frame.top, position); + mWindowContainer.transformFrameToSurfacePosition(frame.left, frame.top, position); return position; } @@ -322,8 +352,8 @@ class InsetsSourceProvider { } /** - * Ensures that the inset source window is cropped so that anything that doesn't fit within the - * inset frame is cropped out until removeCropToProvidingInsetsBounds is called. + * Ensures that the inset source window container is cropped so that anything that doesn't fit + * within the inset frame is cropped out until removeCropToProvidingInsetsBounds is called. * * The inset source surface will get cropped to the be of the size of the insets it's providing. * @@ -342,9 +372,10 @@ class InsetsSourceProvider { void setCropToProvidingInsetsBounds(Transaction t) { mCropToProvidingInsets = true; - if (mWin != null && mWin.mSurfaceAnimator.hasLeash()) { + if (mWindowContainer != null && mWindowContainer.mSurfaceAnimator.hasLeash()) { // apply to existing leash - t.setWindowCrop(mWin.mSurfaceAnimator.mLeash, getProvidingInsetsBoundsCropRect()); + t.setWindowCrop(mWindowContainer.mSurfaceAnimator.mLeash, + getProvidingInsetsBoundsCropRect()); } } @@ -359,13 +390,15 @@ class InsetsSourceProvider { mCropToProvidingInsets = false; // apply to existing leash - if (mWin != null && mWin.mSurfaceAnimator.hasLeash()) { - t.setWindowCrop(mWin.mSurfaceAnimator.mLeash, null); + if (mWindowContainer != null && mWindowContainer.mSurfaceAnimator.hasLeash()) { + t.setWindowCrop(mWindowContainer.mSurfaceAnimator.mLeash, null); } } private Rect getProvidingInsetsBoundsCropRect() { - Rect sourceWindowFrame = mWin.getFrame(); + Rect sourceWindowFrame = mWindowContainer.asWindowState() != null + ? mWindowContainer.asWindowState().getFrame() + : mWindowContainer.getBounds(); Rect insetFrame = getSource().getFrame(); // The rectangle in buffer space we want to crop to @@ -384,11 +417,11 @@ class InsetsSourceProvider { return; } - if (mWin != null && mWin.getSurfaceControl() == null) { + if (mWindowContainer != null && mWindowContainer.getSurfaceControl() == null) { // if window doesn't have a surface, set it null and return. - setWindow(null, null, null); + setWindowContainer(null, null, null); } - if (mWin == null) { + if (mWindowContainer == null) { mPendingControlTarget = target; return; } @@ -397,7 +430,7 @@ class InsetsSourceProvider { } if (target == null) { // Cancelling the animation will invoke onAnimationCancelled, resetting all the fields. - mWin.cancelAnimation(); + mWindowContainer.cancelAnimation(); setClientVisible(InsetsState.getDefaultVisibility(mSource.getType())); return; } @@ -407,7 +440,7 @@ class InsetsSourceProvider { setClientVisible(target.getRequestedVisibility(mSource.getType())); } final Transaction t = mDisplayContent.getSyncTransaction(); - mWin.startAnimation(t, mAdapter, !mClientVisible /* hidden */, + mWindowContainer.startAnimation(t, mAdapter, !mClientVisible /* hidden */, ANIMATION_TYPE_INSETS_CONTROL); // The leash was just created. We cannot dispatch it until its surface transaction is @@ -418,16 +451,16 @@ class InsetsSourceProvider { mControlTarget = target; updateVisibility(); mControl = new InsetsSourceControl(mSource.getType(), leash, surfacePosition, - mSource.calculateInsets(mWin.getBounds(), true /* ignoreVisibility */)); + mSource.calculateInsets(mWindowContainer.getBounds(), true /* ignoreVisibility */)); ProtoLog.d(WM_DEBUG_WINDOW_INSETS, "InsetsSource Control %s for target %s", mControl, mControlTarget); } void startSeamlessRotation() { - if (!mSeamlessRotating) { - mSeamlessRotating = true; - mWin.cancelAnimation(); - } + if (!mSeamlessRotating) { + mSeamlessRotating = true; + mWindowContainer.cancelAnimation(); + } } void finishSeamlessRotation() { @@ -475,10 +508,13 @@ class InsetsSourceProvider { } private boolean isMirroredSource() { - if (mWin == null) { + if (mWindowContainer == null) { return false; } - final int[] provides = mWin.mAttrs.providesInsetsTypes; + if (mWindowContainer.asWindowState() == null) { + return false; + } + final int[] provides = ((WindowState) mWindowContainer).mAttrs.providesInsetsTypes; if (provides == null) { return false; } @@ -542,9 +578,9 @@ class InsetsSourceProvider { pw.print("mIsLeashReadyForDispatching="); pw.print(mIsLeashReadyForDispatching); pw.print(" mImeOverrideFrame="); pw.print(mImeOverrideFrame.toShortString()); pw.println(); - if (mWin != null) { - pw.print(prefix + "mWin="); - pw.println(mWin); + if (mWindowContainer != null) { + pw.print(prefix + "mWindowContainer="); + pw.println(mWindowContainer); } if (mAdapter != null) { pw.print(prefix + "mAdapter="); diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index f2f273772f8e5..32e70d926f2d0 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -167,7 +167,7 @@ class InsetsStateController { final InsetsState aboveInsetsState = new InsetsState(); aboveInsetsState.set(mState, displayCutout() | systemGestures() | mandatorySystemGestures()); - final SparseArray winProvidedSources = win.mProvidedInsetsSources; + final SparseArray winProvidedSources = win.getProvidedInsetsSources(); final ArrayList insetsChangedWindows = new ArrayList<>(); mDisplayContent.forAllWindows(w -> { if (aboveWin[0]) { @@ -179,7 +179,7 @@ class InsetsStateController { } return winProvidedSources.size() == 0; } else { - final SparseArray providedSources = w.mProvidedInsetsSources; + final SparseArray providedSources = w.getProvidedInsetsSources(); for (int i = providedSources.size() - 1; i >= 0; i--) { aboveInsetsState.addSource(providedSources.valueAt(i)); } @@ -246,7 +246,7 @@ class InsetsStateController { final InsetsState state = displayFrames.mInsetsState; for (int i = mProviders.size() - 1; i >= 0; i--) { final InsetsSourceProvider provider = mProviders.valueAt(i); - if (provider.mWin == win) { + if (provider.mWindowContainer == win) { state.addSource(provider.createSimulatedSource(displayFrames, winFrame)); } } diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index e1746cca455a3..45fdc04671c33 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -81,8 +81,10 @@ import android.util.Pair; import android.util.Pools; import android.util.RotationUtils; import android.util.Slog; +import android.util.SparseArray; import android.util.proto.ProtoOutputStream; import android.view.DisplayInfo; +import android.view.InsetsSource; import android.view.MagnificationSpec; import android.view.RemoteAnimationDefinition; import android.view.RemoteAnimationTarget; @@ -127,7 +129,8 @@ import java.util.function.Predicate; * changes are made to this class. */ class WindowContainer extends ConfigurationContainer - implements Comparable, Animatable, SurfaceFreezer.Freezable { + implements Comparable, Animatable, SurfaceFreezer.Freezable, + InsetsControlTarget { private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowContainer" : TAG_WM; @@ -145,6 +148,13 @@ class WindowContainer extends ConfigurationContainer< // onParentChanged() notification. boolean mReparenting; + protected @Nullable InsetsSourceProvider mControllableInsetProvider; + + /** + * The insets sources provided by this windowContainer. + */ + private SparseArray mProvidedInsetsSources = null; + // List of children for this window container. List is in z-order as the children appear on // screen with the top-most window container at the tail of the list. protected final WindowList mChildren = new WindowList(); @@ -329,6 +339,25 @@ class WindowContainer extends ConfigurationContainer< mSurfaceFreezer = new SurfaceFreezer(this, wms); } + /** + * Set's an {@link InsetsSourceProvider} to be associated with this window, but only if the + * provider itself is controllable, as one window can be the provider of more than one inset + * type (i.e. gesture insets). If this window is controllable, all its animations must be + * controlled by its control target, and the visibility of this window should be taken account + * into the state of the control target. + * + * @param insetProvider the provider which should not be visible to the client. + * @see #getInsetsState() + */ + void setControllableInsetProvider(InsetsSourceProvider insetProvider) { + mControllableInsetProvider = insetProvider; + } + + InsetsSourceProvider getControllableInsetProvider() { + return mControllableInsetProvider; + } + + @Override final protected WindowContainer getParent() { return mParent; @@ -858,6 +887,13 @@ class WindowContainer extends ConfigurationContainer< } } + public SparseArray getProvidedInsetsSources() { + if (mProvidedInsetsSources == null) { + mProvidedInsetsSources = new SparseArray<>(); + } + return mProvidedInsetsSources; + } + DisplayContent getDisplayContent() { return mDisplayContent; } @@ -2962,6 +2998,16 @@ class WindowContainer extends ConfigurationContainer< scheduleAnimation(); } + void transformFrameToSurfacePosition(int left, int top, Point outPoint) { + outPoint.set(left, top); + final WindowContainer parentWindowContainer = getParent(); + if (parentWindowContainer == null) { + return; + } + final Rect parentBounds = parentWindowContainer.getBounds(); + outPoint.offset(-parentBounds.left, -parentBounds.top); + } + void reassignLayer(Transaction t) { final WindowContainer parent = getParent(); if (parent != null) { diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 15af70dac5779..1ab8cbf31dadc 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -217,7 +217,6 @@ import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.MergedConfiguration; import android.util.Slog; -import android.util.SparseArray; import android.util.TimeUtils; import android.util.proto.ProtoOutputStream; import android.view.Display; @@ -680,11 +679,6 @@ class WindowState extends WindowContainer implements WindowManagerP */ final InsetsState mAboveInsetsState = new InsetsState(); - /** - * The insets sources provided by this window. - */ - final SparseArray mProvidedInsetsSources = new SparseArray<>(); - /** * Surface insets from the previous call to relayout(), used to track * if we are changing the Surface insets. @@ -739,7 +733,6 @@ class WindowState extends WindowContainer implements WindowManagerP */ private boolean mIsDimming = false; - private @Nullable InsetsSourceProvider mControllableInsetProvider; private final InsetsVisibilities mRequestedVisibilities = new InsetsVisibilities(); /** @@ -5687,24 +5680,6 @@ class WindowState extends WindowContainer implements WindowManagerP mWindowFrames.setContentChanged(false); } - /** - * Set's an {@link InsetsSourceProvider} to be associated with this window, but only if the - * provider itself is controllable, as one window can be the provider of more than one inset - * type (i.e. gesture insets). If this window is controllable, all its animations must be - * controlled by its control target, and the visibility of this window should be taken account - * into the state of the control target. - * - * @param insetProvider the provider which should not be visible to the client. - * @see #getInsetsState() - */ - void setControllableInsetProvider(InsetsSourceProvider insetProvider) { - mControllableInsetProvider = insetProvider; - } - - InsetsSourceProvider getControllableInsetProvider() { - return mControllableInsetProvider; - } - private final class MoveAnimationSpec implements AnimationSpec { private final long mDuration; 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 d5fce82952173..ffc10d791ef9c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -3091,7 +3091,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).setWindow( + mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( mImeWindow, null, null); mImeWindow.getControllableInsetProvider().setServerVisible(true); 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 5f96267118964..ca8481a8c50b1 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ImeInsetsSourceProviderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/ImeInsetsSourceProviderTest.java @@ -71,7 +71,7 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase { public void testIsImeShowing() { WindowState ime = createWindow(null, TYPE_INPUT_METHOD, "ime"); makeWindowVisibleAndDrawn(ime); - mImeProvider.setWindow(ime, null, null); + mImeProvider.setWindowContainer(ime, null, null); WindowState target = createWindow(null, TYPE_APPLICATION, "app"); mDisplayContent.setImeLayeringTarget(target); diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java index 2987f943f1c54..c61b88b3d3a25 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java @@ -63,7 +63,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); statusBar.getFrame().set(0, 0, 500, 100); statusBar.mHasSurface = true; - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); mProvider.onPostLayout(); assertEquals(new Rect(0, 0, 500, 100), mProvider.getSource().getFrame()); assertEquals(Insets.of(0, 100, 0, 0), @@ -80,7 +80,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { ime.mGivenContentInsets.set(0, 0, 0, 60); ime.mGivenVisibleInsets.set(0, 0, 0, 75); ime.mHasSurface = true; - mProvider.setWindow(ime, null, null); + mProvider.setWindowContainer(ime, null, null); mProvider.onPostLayout(); assertEquals(new Rect(0, 0, 500, 40), mProvider.getSource().getFrame()); assertEquals(new Rect(0, 0, 500, 25), mProvider.getSource().getVisibleFrame()); @@ -95,10 +95,10 @@ public class InsetsSourceProviderTest extends WindowTestsBase { public void testPostLayout_invisible() { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); statusBar.getFrame().set(0, 0, 500, 100); - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); mProvider.onPostLayout(); assertEquals(Insets.NONE, mProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500), - false /* ignoreVisibility */)); + false /* ignoreVisibility */)); } @Test @@ -106,7 +106,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); statusBar.getFrame().set(0, 0, 500, 100); statusBar.mHasSurface = true; - mProvider.setWindow(statusBar, + mProvider.setWindowContainer(statusBar, (displayFrames, windowState, rect) -> { rect.set(10, 10, 20, 20); }, null); @@ -126,7 +126,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { assertNull(mProvider.getControlTarget()); // We can have the control or the control target after we have the insets source window. - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); mProvider.updateControlForTarget(target, false /* force */); assertNotNull(mProvider.getControl(target)); assertNotNull(mProvider.getControlTarget()); @@ -164,7 +164,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); final WindowState target = createWindow(null, TYPE_APPLICATION, "target"); statusBar.getFrame().set(0, 0, 500, 100); - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); mProvider.updateControlForFakeTarget(target); assertNotNull(mProvider.getControl(target)); assertNull(mProvider.getControl(target).getLeash()); @@ -178,7 +178,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { inputMethod.getFrame().set(new Rect(0, 400, 500, 500)); - mImeProvider.setWindow(inputMethod, null, null); + mImeProvider.setWindowContainer(inputMethod, null, null); mImeProvider.setServerVisible(false); mImeSource.setVisible(true); mImeProvider.updateSourceFrame(); @@ -201,7 +201,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); final WindowState target = createWindow(null, TYPE_APPLICATION, "target"); statusBar.getFrame().set(0, 0, 500, 100); - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); mProvider.updateControlForTarget(target, false /* force */); final InsetsVisibilities requestedVisibilities = new InsetsVisibilities(); requestedVisibilities.setVisibility(ITYPE_STATUS_BAR, false); @@ -215,7 +215,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); final WindowState target = createWindow(null, TYPE_APPLICATION, "target"); statusBar.getFrame().set(0, 0, 500, 100); - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); final InsetsVisibilities requestedVisibilities = new InsetsVisibilities(); requestedVisibilities.setVisibility(ITYPE_STATUS_BAR, false); target.setRequestedVisibilities(requestedVisibilities); @@ -228,7 +228,7 @@ public class InsetsSourceProviderTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); statusBar.getFrame().set(0, 0, 500, 100); statusBar.mHasSurface = true; - mProvider.setWindow(statusBar, null, null); + mProvider.setWindowContainer(statusBar, null, null); mProvider.onPostLayout(); assertEquals(new Rect(0, 0, 500, 100), mProvider.getSource().getFrame()); // Still apply top insets if window overlaps even if it's top doesn't exactly match 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 a11397e8c17c0..c7a1b07fd439f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java @@ -68,9 +68,11 @@ public class InsetsStateControllerTest extends WindowTestsBase { // IME cannot be the IME target. ime.mAttrs.flags |= FLAG_NOT_FOCUSABLE; - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); - getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); assertNull(navBar.getInsetsState().peekSource(ITYPE_IME)); assertNull(navBar.getInsetsState().peekSource(ITYPE_STATUS_BAR)); @@ -82,8 +84,10 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); app.setWindowingMode(WINDOWING_MODE_PINNED); assertNull(app.getInsetsState().peekSource(ITYPE_STATUS_BAR)); @@ -97,8 +101,10 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); app.setWindowingMode(WINDOWING_MODE_FREEFORM); assertNull(app.getInsetsState().peekSource(ITYPE_STATUS_BAR)); @@ -111,8 +117,10 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); app.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); app.setAlwaysOnTop(true); @@ -123,7 +131,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { @UseTestDisplay(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_independentSources() { - getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); final WindowState app1 = createWindow(null, TYPE_APPLICATION, "app1"); final WindowState app2 = createWindow(null, TYPE_APPLICATION, "app2"); @@ -140,7 +148,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { @UseTestDisplay(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_belowIme() { - getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); app.mAboveInsetsState.getSource(ITYPE_IME).setVisible(true); @@ -153,7 +161,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { @UseTestDisplay(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_aboveIme() { - getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); @@ -173,7 +181,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { // Make IME and stay visible during the test. mImeWindow.setHasSurface(true); - getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); getController().onImeControlTargetChanged(mDisplayContent.getImeTarget(IME_TARGET_INPUT)); final InsetsVisibilities requestedVisibilities = new InsetsVisibilities(); requestedVisibilities.setVisibility(ITYPE_IME, true); @@ -219,7 +227,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { @UseTestDisplay(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_childWindow_altFocusable() { - getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); @@ -240,7 +248,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { @UseTestDisplay(addWindows = W_INPUT_METHOD) @Test public void testStripForDispatch_childWindow_splitScreen() { - getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(mImeWindow, null, null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); @@ -268,9 +276,9 @@ public class InsetsStateControllerTest extends WindowTestsBase { InsetsSourceProvider statusBarProvider = getController().getSourceProvider(ITYPE_STATUS_BAR); - statusBarProvider.setWindow(statusBar, null, ((displayFrames, windowState, rect) -> - rect.set(0, 1, 2, 3))); - getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); + statusBarProvider.setWindowContainer(statusBar, null, ((displayFrames, windowState, rect) -> + rect.set(0, 1, 2, 3))); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); statusBar.setControllableInsetProvider(statusBarProvider); statusBarProvider.onPostLayout(); @@ -286,10 +294,14 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState climateBar = createWindow(null, TYPE_APPLICATION, "climateBar"); final WindowState extraNavBar = createWindow(null, TYPE_APPLICATION, "extraNavBar"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); - getController().getSourceProvider(ITYPE_CLIMATE_BAR).setWindow(climateBar, null, null); - getController().getSourceProvider(ITYPE_EXTRA_NAVIGATION_BAR).setWindow(extraNavBar, null, + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); + getController().getSourceProvider(ITYPE_CLIMATE_BAR).setWindowContainer(climateBar, null, + null); + getController().getSourceProvider(ITYPE_EXTRA_NAVIGATION_BAR).setWindowContainer( + extraNavBar, null, null); getController().onBarControlTargetChanged(app, null, app, null); InsetsSourceControl[] controls = getController().getControlsForDispatch(app); @@ -300,7 +312,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { public void testControlRevoked() { 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); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); getController().onBarControlTargetChanged(app, null, null, null); assertNotNull(getController().getControlsForDispatch(app)); getController().onBarControlTargetChanged(null, null, null, null); @@ -311,7 +324,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { public void testControlRevoked_animation() { 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); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); getController().onBarControlTargetChanged(app, null, null, null); assertNotNull(getController().getControlsForDispatch(app)); statusBar.cancelAnimation(); @@ -323,7 +337,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final InsetsSourceProvider provider = getController().getSourceProvider(ITYPE_STATUS_BAR); - provider.setWindow(statusBar, null, null); + provider.setWindowContainer(statusBar, null, null); final InsetsState rotatedState = new InsetsState(app.getInsetsState(), true /* copySources */); @@ -345,7 +359,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState statusBar = createTestWindow("statusBar"); final WindowState navBar = createTestWindow("navBar"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); assertNull(app.mAboveInsetsState.peekSource(ITYPE_STATUS_BAR)); assertNull(statusBar.mAboveInsetsState.peekSource(ITYPE_STATUS_BAR)); @@ -366,8 +381,10 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState statusBar = createTestWindow("statusBar"); final WindowState navBar = createTestWindow("navBar"); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); assertNull(app.mAboveInsetsState.peekSource(ITYPE_STATUS_BAR)); assertNull(app.mAboveInsetsState.peekSource(ITYPE_NAVIGATION_BAR)); @@ -387,10 +404,12 @@ public class InsetsStateControllerTest extends WindowTestsBase { final WindowState statusBar = createTestWindow("statusBar"); final WindowState navBar = createTestWindow("navBar"); - getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); + getController().getSourceProvider(ITYPE_IME).setWindowContainer(ime, null, null); getController().getSourceProvider(ITYPE_IME).setClientVisible(true); - getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); + getController().getSourceProvider(ITYPE_STATUS_BAR).setWindowContainer(statusBar, null, + null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); getController().updateAboveInsetsState(ime, false /* notifyInsetsChange */); getController().updateAboveInsetsState(statusBar, false /* notifyInsetsChange */); getController().updateAboveInsetsState(navBar, false /* notifyInsetsChange */); @@ -421,7 +440,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { @Test public void testDispatchGlobalInsets() { final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); - getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); + getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindowContainer(navBar, null, + null); final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); assertNull(app.getInsetsState().peekSource(ITYPE_NAVIGATION_BAR)); app.mAttrs.receiveInsetsIgnoringZOrder = true; 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 68ddbc6801edd..459e3a5131cc9 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowStateTests.java @@ -105,7 +105,7 @@ import java.util.List; * Tests for the {@link WindowState} class. * * Build/Install/Run: - * atest WmTests:WindowStateTests + * atest WmTests:WindowStateTests */ @SmallTest @Presubmit @@ -411,7 +411,7 @@ public class WindowStateTests extends WindowTestsBase { assertFalse(app.canAffectSystemUiFlags()); } - @UseTestDisplay(addWindows = { W_ACTIVITY, W_STATUS_BAR }) + @UseTestDisplay(addWindows = {W_ACTIVITY, W_STATUS_BAR}) @Test public void testVisibleWithInsetsProvider() { final WindowState statusBar = mStatusBarWindow; @@ -419,7 +419,8 @@ public class WindowStateTests extends WindowTestsBase { statusBar.mHasSurface = true; assertTrue(statusBar.isVisible()); mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR) - .setWindow(statusBar, null /* frameProvider */, null /* imeFrameProvider */); + .setWindowContainer(statusBar, null /* frameProvider */, + null /* imeFrameProvider */); mDisplayContent.getInsetsStateController().onBarControlTargetChanged( app, null /* fakeTopControlling */, app, null /* fakeNavControlling */); final InsetsVisibilities requestedVisibilities = new InsetsVisibilities(); @@ -623,7 +624,7 @@ public class WindowStateTests extends WindowTestsBase { assertEquals(w.getWindowConfiguration().getBounds(), unscaledClientBounds); } - @UseTestDisplay(addWindows = { W_ABOVE_ACTIVITY, W_NOTIFICATION_SHADE }) + @UseTestDisplay(addWindows = {W_ABOVE_ACTIVITY, W_NOTIFICATION_SHADE}) @Test public void testRequestDrawIfNeeded() { final WindowState startingApp = createWindow(null /* parent */, @@ -831,7 +832,7 @@ public class WindowStateTests extends WindowTestsBase { assertFalse(sameTokenWindow.needsRelativeLayeringToIme()); } - @UseTestDisplay(addWindows = { W_ACTIVITY, W_INPUT_METHOD }) + @UseTestDisplay(addWindows = {W_ACTIVITY, W_INPUT_METHOD}) @Test public void testNeedsRelativeLayeringToIme_startingWindow() { WindowState sameTokenWindow = createWindow(null, TYPE_APPLICATION_STARTING, @@ -864,7 +865,7 @@ public class WindowStateTests extends WindowTestsBase { verify(app).notifyInsetsChanged(); } - @UseTestDisplay(addWindows = { W_INPUT_METHOD, W_ACTIVITY }) + @UseTestDisplay(addWindows = {W_INPUT_METHOD, W_ACTIVITY}) @Test public void testImeAlwaysReceivesVisibleNavigationBarInsets() { final InsetsSource navSource = new InsetsSource(ITYPE_NAVIGATION_BAR); @@ -890,7 +891,7 @@ public class WindowStateTests extends WindowTestsBase { mDisplayContent.mInputMethodWindow = imeWindow; final InsetsStateController controller = mDisplayContent.getInsetsStateController(); - controller.getImeSourceProvider().setWindow(imeWindow, null, null); + controller.getImeSourceProvider().setWindowContainer(imeWindow, null, null); // Simulate app requests IME with updating all windows Insets State when IME is above app. mDisplayContent.setImeLayeringTarget(app); @@ -914,7 +915,7 @@ public class WindowStateTests extends WindowTestsBase { assertFalse(app2.getInsetsState().getSource(ITYPE_IME).isVisible()); } - @UseTestDisplay(addWindows = { W_ACTIVITY }) + @UseTestDisplay(addWindows = {W_ACTIVITY}) @Test public void testUpdateImeControlTargetWhenLeavingMultiWindow() { WindowState app = createWindow(null, TYPE_BASE_APPLICATION, @@ -940,7 +941,7 @@ public class WindowStateTests extends WindowTestsBase { assertEquals(mAppWindow, mDisplayContent.getImeTarget(IME_TARGET_CONTROL).getWindow()); } - @UseTestDisplay(addWindows = { W_ACTIVITY, W_INPUT_METHOD, W_NOTIFICATION_SHADE }) + @UseTestDisplay(addWindows = {W_ACTIVITY, W_INPUT_METHOD, W_NOTIFICATION_SHADE}) @Test public void testNotificationShadeHasImeInsetsWhenMultiWindow() { WindowState app = createWindow(null, TYPE_BASE_APPLICATION, @@ -954,7 +955,7 @@ public class WindowStateTests extends WindowTestsBase { mNotificationShadeWindow.setHasSurface(true); mNotificationShadeWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; assertTrue(mNotificationShadeWindow.canBeImeTarget()); - mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindow( + mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( mImeWindow, null, null); mDisplayContent.computeImeTarget(true); 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 74cff10f994f2..4b5f330a2ddc8 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java @@ -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).setWindow( + mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_IME).setWindowContainer( mDisplayContent.mInputMethodWindow, null, null); // Simulate an app window to be the IME layering target, assume the app window has no