diff options
author | Tiger Huang <tigerhuang@google.com> | 2020-10-21 15:23:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-10-21 15:23:27 +0000 |
commit | 9e2c966d61fdb4b1408cc50ecc5622bf6697ef2f (patch) | |
tree | ed16b5a08c7a725e602f2304ce9322e5d4050024 | |
parent | 6993eecd1f349d03ff28a561f7f51903aff5ff4a (diff) | |
parent | 2bf8c796c559c35cf8b3af4da8f54b31cc5d620a (diff) |
Merge "Don't dispatch legacy insets to client"
32 files changed, 347 insertions, 361 deletions
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java index 6f0001dcc0ad..29606030a041 100644 --- a/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java +++ b/apct-tests/perftests/windowmanager/src/android/wm/WindowAddRemovePerfTest.java @@ -86,8 +86,6 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase final WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(); final InsetsState mRequestedVisibility = new InsetsState(); final Rect mOutFrame = new Rect(); - final Rect mOutContentInsets = new Rect(); - final Rect mOutStableInsets = new Rect(); final DisplayCutout.ParcelableWrapper mOutDisplayCutout = new DisplayCutout.ParcelableWrapper(); final InsetsState mOutInsetsState = new InsetsState(); @@ -110,7 +108,6 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase long startTime = SystemClock.elapsedRealtimeNanos(); session.addToDisplay(this, mLayoutParams, View.VISIBLE, Display.DEFAULT_DISPLAY, mRequestedVisibility, mOutFrame, - mOutContentInsets, mOutStableInsets, mOutDisplayCutout, inputChannel, mOutInsetsState, mOutControls); final long elapsedTimeNsOfAdd = SystemClock.elapsedRealtimeNanos() - startTime; state.addExtraResult("add", elapsedTimeNsOfAdd); diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java index ccb8cdd71278..f8ed27a6646b 100644 --- a/core/java/android/content/res/CompatibilityInfo.java +++ b/core/java/android/content/res/CompatibilityInfo.java @@ -28,6 +28,7 @@ import android.os.Build.VERSION_CODES; import android.os.Parcel; import android.os.Parcelable; import android.util.DisplayMetrics; +import android.view.InsetsState; import android.view.MotionEvent; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; @@ -330,15 +331,7 @@ public class CompatibilityInfo implements Parcelable { } /** - * Translate the screen rect to the application frame. - */ - @UnsupportedAppUsage - public void translateRectInScreenToAppWinFrame(Rect rect) { - rect.scale(applicationInvertedScale); - } - - /** - * Translate the region in window to screen. + * Translate the region in window to screen. */ @UnsupportedAppUsage public void translateRegionInWindowToScreen(Region transparentRegion) { @@ -388,7 +381,14 @@ public class CompatibilityInfo implements Parcelable { public void translateWindowLayout(WindowManager.LayoutParams params) { params.scale(applicationScale); } - + + /** + * Translate a length in application's window to screen. + */ + public float translateLengthInAppWindowToScreen(float length) { + return length * applicationScale; + } + /** * Translate a Rect in application's window to screen. */ @@ -396,7 +396,7 @@ public class CompatibilityInfo implements Parcelable { public void translateRectInAppWindowToScreen(Rect rect) { rect.scale(applicationScale); } - + /** * Translate a Rect in screen coordinates into the app window's coordinates. */ @@ -406,6 +406,13 @@ public class CompatibilityInfo implements Parcelable { } /** + * Translate an InsetsState in screen coordinates into the app window's coordinates. + */ + public void translateInsetsStateInScreenToAppWindow(InsetsState state) { + state.scale(applicationInvertedScale); + } + + /** * Translate a Point in screen coordinates into the app window's coordinates. */ public void translatePointInScreenToAppWindow(PointF point) { diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 6a70a856e09a..4249e5c20d3b 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -20,6 +20,7 @@ import static android.graphics.Matrix.MSCALE_X; import static android.graphics.Matrix.MSCALE_Y; import static android.graphics.Matrix.MSKEW_X; import static android.graphics.Matrix.MSKEW_Y; +import static android.view.View.SYSTEM_UI_FLAG_VISIBLE; import android.annotation.FloatRange; import android.annotation.Nullable; @@ -33,6 +34,7 @@ import android.app.WallpaperManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -878,7 +880,6 @@ public abstract class WallpaperService extends Service { if (mSession.addToDisplay(mWindow, mLayout, View.VISIBLE, mDisplay.getDisplayId(), mInsetsState, mWinFrames.frame, - mWinFrames.contentInsets, mWinFrames.stableInsets, mWinFrames.displayCutout, inputChannel, mInsetsState, mTempControls) < 0) { Log.w(TAG, "Failed to add window while updating wallpaper surface."); @@ -914,20 +915,22 @@ public abstract class WallpaperService extends Service { int w = mWinFrames.frame.width(); int h = mWinFrames.frame.height(); + final DisplayCutout rawCutout = mWinFrames.displayCutout.get(); + final Configuration config = getResources().getConfiguration(); + final Rect visibleFrame = new Rect(mWinFrames.frame); + visibleFrame.intersect(mInsetsState.getDisplayFrame()); + WindowInsets windowInsets = mInsetsState.calculateInsets(visibleFrame, + null /* ignoringVisibilityState */, config.isScreenRound(), + false /* alwaysConsumeSystemBars */, rawCutout, mLayout.softInputMode, + mLayout.flags, SYSTEM_UI_FLAG_VISIBLE, mLayout.type, + config.windowConfiguration.getWindowingMode(), null /* typeSideMap */); + if (!fixedSize) { final Rect padding = mIWallpaperEngine.mDisplayPadding; w += padding.left + padding.right; h += padding.top + padding.bottom; - mWinFrames.contentInsets.left += padding.left; - mWinFrames.contentInsets.top += padding.top; - mWinFrames.contentInsets.right += padding.right; - mWinFrames.contentInsets.bottom += padding.bottom; - mWinFrames.stableInsets.left += padding.left; - mWinFrames.stableInsets.top += padding.top; - mWinFrames.stableInsets.right += padding.right; - mWinFrames.stableInsets.bottom += padding.bottom; - mWinFrames.displayCutout.set(mWinFrames.displayCutout.get().inset( - -padding.left, -padding.top, -padding.right, -padding.bottom)); + windowInsets = windowInsets.insetUnchecked( + -padding.left, -padding.top, -padding.right, -padding.bottom); } else { w = myWidth; h = myHeight; @@ -946,9 +949,12 @@ public abstract class WallpaperService extends Service { Log.v(TAG, "Wallpaper size has changed: (" + mCurWidth + ", " + mCurHeight); } - final DisplayCutout displayCutout = mWinFrames.displayCutout.get(); - insetsChanged |= !mDispatchedContentInsets.equals(mWinFrames.contentInsets); - insetsChanged |= !mDispatchedStableInsets.equals(mWinFrames.stableInsets); + final Rect contentInsets = windowInsets.getSystemWindowInsets().toRect(); + final Rect stableInsets = windowInsets.getStableInsets().toRect(); + final DisplayCutout displayCutout = windowInsets.getDisplayCutout() != null + ? windowInsets.getDisplayCutout() : rawCutout; + insetsChanged |= !mDispatchedContentInsets.equals(contentInsets); + insetsChanged |= !mDispatchedStableInsets.equals(stableInsets); insetsChanged |= !mDispatchedDisplayCutout.equals(displayCutout); mSurfaceHolder.setSurfaceFrameSize(w, h); @@ -1008,18 +1014,13 @@ public abstract class WallpaperService extends Service { } if (insetsChanged) { - mDispatchedContentInsets.set(mWinFrames.contentInsets); - mDispatchedStableInsets.set(mWinFrames.stableInsets); + mDispatchedContentInsets.set(contentInsets); + mDispatchedStableInsets.set(stableInsets); mDispatchedDisplayCutout = displayCutout; - mFinalStableInsets.set(mDispatchedStableInsets); - WindowInsets insets = new WindowInsets(mFinalSystemInsets, - mFinalStableInsets, - getResources().getConfiguration().isScreenRound(), false, - mDispatchedDisplayCutout); if (DEBUG) { - Log.v(TAG, "dispatching insets=" + insets); + Log.v(TAG, "dispatching insets=" + windowInsets); } - onApplyWindowInsets(insets); + onApplyWindowInsets(windowInsets); } if (redrawNeeded) { diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index 3c5d336b840d..f572eb91ef34 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -729,7 +729,6 @@ interface IWindowManager * @return {@code true} if system bars are always comsumed. */ boolean getWindowInsets(in WindowManager.LayoutParams attrs, int displayId, - out Rect outContentInsets, out Rect outStableInsets, out DisplayCutout.ParcelableWrapper outDisplayCutout, out InsetsState outInsetsState); /** diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl index 7f36169ada50..9febc9f09ef3 100644 --- a/core/java/android/view/IWindowSession.aidl +++ b/core/java/android/view/IWindowSession.aidl @@ -46,18 +46,16 @@ import java.util.List; interface IWindowSession { int addToDisplay(IWindow window, in WindowManager.LayoutParams attrs, in int viewVisibility, in int layerStackId, in InsetsState requestedVisibility, - out Rect outFrame, out Rect outContentInsets, out Rect outStableInsets, + out Rect outFrame, out DisplayCutout.ParcelableWrapper displayCutout, + out InputChannel outInputChannel, out InsetsState insetsState, + out InsetsSourceControl[] activeControls); + int addToDisplayAsUser(IWindow window, in WindowManager.LayoutParams attrs, + in int viewVisibility, in int layerStackId, in int userId, + in InsetsState requestedVisibility, out Rect outFrame, out DisplayCutout.ParcelableWrapper displayCutout, out InputChannel outInputChannel, out InsetsState insetsState, out InsetsSourceControl[] activeControls); - int addToDisplayAsUser(IWindow window, in WindowManager.LayoutParams attrs, - in int viewVisibility, in int layerStackId, in int userId, - in InsetsState requestedVisibility, - out Rect outFrame, out Rect outContentInsets, out Rect outStableInsets, - out DisplayCutout.ParcelableWrapper displayCutout, out InputChannel outInputChannel, - out InsetsState insetsState, out InsetsSourceControl[] activeControls); int addToDisplayWithoutInputChannel(IWindow window, in WindowManager.LayoutParams attrs, - in int viewVisibility, in int layerStackId, out Rect outContentInsets, - out Rect outStableInsets, out InsetsState insetsState); + in int viewVisibility, in int layerStackId, out InsetsState insetsState); @UnsupportedAppUsage void remove(IWindow window); diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 878583be87c9..06ddf3c69f8e 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -38,6 +38,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; import android.annotation.Nullable; +import android.content.res.CompatibilityInfo; import android.graphics.Insets; import android.graphics.Matrix; import android.graphics.Rect; @@ -90,6 +91,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll private final WindowInsetsAnimation mAnimation; /** @see WindowInsetsAnimationController#hasZeroInsetsIme */ private final boolean mHasZeroInsetsIme; + private final CompatibilityInfo.Translator mTranslator; private Insets mCurrentInsets; private Insets mPendingInsets; private float mPendingFraction; @@ -107,7 +109,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll InsetsState state, WindowInsetsAnimationControlListener listener, @InsetsType int types, InsetsAnimationControlCallbacks controller, long durationMs, Interpolator interpolator, - @AnimationType int animationType) { + @AnimationType int animationType, CompatibilityInfo.Translator translator) { mControls = controls; mListener = listener; mTypes = types; @@ -131,6 +133,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll durationMs); mAnimation.setAlpha(getCurrentAlpha()); mAnimationType = animationType; + mTranslator = translator; mController.startAnimation(this, listener, types, mAnimation, new Bounds(mHiddenInsets, mShownInsets)); @@ -396,21 +399,23 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll private void addTranslationToMatrix(@InternalInsetsSide int side, int inset, Matrix m, Rect frame) { + final float surfaceOffset = mTranslator != null + ? mTranslator.translateLengthInAppWindowToScreen(inset) : inset; switch (side) { case ISIDE_LEFT: - m.postTranslate(-inset, 0); + m.postTranslate(-surfaceOffset, 0); frame.offset(-inset, 0); break; case ISIDE_TOP: - m.postTranslate(0, -inset); + m.postTranslate(0, -surfaceOffset); frame.offset(0, -inset); break; case ISIDE_RIGHT: - m.postTranslate(inset, 0); + m.postTranslate(surfaceOffset, 0); frame.offset(inset, 0); break; case ISIDE_BOTTOM: - m.postTranslate(0, inset); + m.postTranslate(0, surfaceOffset); frame.offset(0, inset); break; } diff --git a/core/java/android/view/InsetsAnimationThreadControlRunner.java b/core/java/android/view/InsetsAnimationThreadControlRunner.java index 1307052a25cc..4a5fa0f971ae 100644 --- a/core/java/android/view/InsetsAnimationThreadControlRunner.java +++ b/core/java/android/view/InsetsAnimationThreadControlRunner.java @@ -20,6 +20,7 @@ import static android.view.InsetsController.DEBUG; import static android.view.SyncRtSurfaceTransactionApplier.applyParams; import android.annotation.UiThread; +import android.content.res.CompatibilityInfo; import android.graphics.Rect; import android.os.Handler; import android.os.Trace; @@ -102,11 +103,12 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro InsetsState state, WindowInsetsAnimationControlListener listener, @InsetsType int types, InsetsAnimationControlCallbacks controller, long durationMs, Interpolator interpolator, - @AnimationType int animationType, Handler mainThreadHandler) { + @AnimationType int animationType, CompatibilityInfo.Translator translator, + Handler mainThreadHandler) { mMainThreadHandler = mainThreadHandler; mOuterCallbacks = controller; mControl = new InsetsAnimationControlImpl(controls, frame, state, listener, - types, mCallbacks, durationMs, interpolator, animationType); + types, mCallbacks, durationMs, interpolator, animationType, translator); InsetsAnimationThread.getHandler().post(() -> { Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "InsetsAsyncAnimation: " + WindowInsets.Type.toString(types), types); diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 5037d9e5bfe8..b5bf08443a6c 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -33,6 +33,7 @@ import android.animation.ValueAnimator; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.content.res.CompatibilityInfo; import android.graphics.Insets; import android.graphics.Rect; import android.os.CancellationSignal; @@ -176,6 +177,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation */ @Nullable IBinder getWindowToken(); + + /** + * @return Translator associated with the host, if it has one. + */ + @Nullable + default CompatibilityInfo.Translator getTranslator() { + return null; + } } private static final String TAG = "InsetsController"; @@ -994,10 +1003,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation final InsetsAnimationControlRunner runner = useInsetsAnimationThread ? new InsetsAnimationThreadControlRunner(controls, frame, mState, listener, typesReady, this, durationMs, interpolator, - animationType, mHost.getHandler()) + animationType, mHost.getTranslator(), mHost.getHandler()) : new InsetsAnimationControlImpl(controls, frame, mState, listener, typesReady, this, durationMs, interpolator, - animationType); + animationType, mHost.getTranslator()); mRunningAnimations.add(new RunningAnimation(runner, animationType)); if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: " + useInsetsAnimationThread); diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java index b9f1f6a43992..ac29f2eb5c0b 100644 --- a/core/java/android/view/InsetsState.java +++ b/core/java/android/view/InsetsState.java @@ -427,6 +427,25 @@ public class InsetsState implements Parcelable { } } + /** + * Scales the frame and the visible frame (if there is one) of each source. + * + * @param scale the scale to be applied + */ + public void scale(float scale) { + mDisplayFrame.scale(scale); + for (int i = 0; i < SIZE; i++) { + final InsetsSource source = mSources[i]; + if (source != null) { + source.getFrame().scale(scale); + final Rect visibleFrame = source.getVisibleFrame(); + if (visibleFrame != null) { + visibleFrame.scale(scale); + } + } + } + } + public void set(InsetsState other) { set(other, false /* copySources */); } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index cf5ca56eb188..cc679d84760c 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -14861,15 +14861,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void getWindowVisibleDisplayFrame(Rect outRect) { if (mAttachInfo != null) { - mAttachInfo.mViewRootImpl.getDisplayFrame(outRect); - // XXX This is really broken, and probably all needs to be done - // in the window manager, and we need to know more about whether - // we want the area behind or in front of the IME. - final Rect insets = mAttachInfo.mVisibleInsets; - outRect.left += insets.left; - outRect.top += insets.top; - outRect.right -= insets.right; - outRect.bottom -= insets.bottom; + mAttachInfo.mViewRootImpl.getWindowVisibleDisplayFrame(outRect); return; } // The view is not attached to a display so we don't have a context. diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index f0203011b4f2..9bc07702feee 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -562,6 +562,9 @@ public final class ViewRootImpl implements ViewParent, = new ViewTreeObserver.InternalInsetsInfo(); private WindowInsets mLastWindowInsets; + private final Rect mSystemInsetsCache = new Rect(); + private final Rect mVisibleInsetsCache = new Rect(); + private final Rect mStableInsetsCache = new Rect(); // Insets types hidden by legacy window flags or system UI flags. private @InsetsType int mTypesHiddenByFlags = 0; @@ -1025,9 +1028,12 @@ public final class ViewRootImpl implements ViewParent, res = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes, getHostVisibility(), mDisplay.getDisplayId(), userId, mInsetsController.getRequestedVisibility(), mTmpFrames.frame, - mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, mAttachInfo.mDisplayCutout, inputChannel, mTempInsets, mTempControls); + if (mTranslator != null) { + mTranslator.translateRectInScreenToAppWindow(mTmpFrames.frame); + mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets); + } setFrame(mTmpFrames.frame); } catch (RemoteException e) { mAdded = false; @@ -1044,9 +1050,6 @@ public final class ViewRootImpl implements ViewParent, } } - if (mTranslator != null) { - mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); - } mPendingDisplayCutout.set(mAttachInfo.mDisplayCutout); mAttachInfo.mAlwaysConsumeSystemBars = (res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_SYSTEM_BARS) != 0; @@ -2313,12 +2316,10 @@ public final class ViewRootImpl implements ViewParent, (mWindowAttributes.systemUiVisibility | mWindowAttributes.subtreeSystemUiVisibility)); - Rect visibleInsets = mInsetsController.calculateVisibleInsets( - mWindowAttributes.softInputMode); - - mAttachInfo.mVisibleInsets.set(visibleInsets); - mAttachInfo.mContentInsets.set(mLastWindowInsets.getSystemWindowInsets().toRect()); - mAttachInfo.mStableInsets.set(mLastWindowInsets.getStableInsets().toRect()); + mSystemInsetsCache.set(mLastWindowInsets.getSystemWindowInsets().toRect()); + mStableInsetsCache.set(mLastWindowInsets.getStableInsets().toRect()); + mVisibleInsetsCache.set(mInsetsController.calculateVisibleInsets( + mWindowAttributes.softInputMode)); } return mLastWindowInsets; } @@ -2826,8 +2827,7 @@ public final class ViewRootImpl implements ViewParent, && mWinFrame.height() == mPendingBackDropFrame.height(); // TODO: Need cutout? startDragResizing(mPendingBackDropFrame, !backdropSizeMatchesFrame, - mLastWindowInsets.getSystemWindowInsets().toRect(), - mLastWindowInsets.getStableInsets().toRect(), mResizeMode); + mSystemInsetsCache, mStableInsetsCache, mResizeMode); } else { // We shouldn't come here, but if we come we should end the resize. endDragResizing(); @@ -3234,9 +3234,6 @@ public final class ViewRootImpl implements ViewParent, final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left || mAttachInfo.mWindowTop != frame.top; if (windowMoved) { - if (mTranslator != null) { - mTranslator.translateRectInScreenToAppWinFrame(frame); - } mAttachInfo.mWindowLeft = frame.left; mAttachInfo.mWindowTop = frame.top; } @@ -4450,8 +4447,8 @@ public final class ViewRootImpl implements ViewParent, } boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { - final Rect ci = getWindowInsets(false).getSystemWindowInsetsAsRect(); - final Rect vi = mAttachInfo.mVisibleInsets; + final Rect ci = mSystemInsetsCache; + final Rect vi = mVisibleInsetsCache; int scrollY = 0; boolean handled = false; @@ -7516,7 +7513,8 @@ public final class ViewRootImpl implements ViewParent, } if (mTranslator != null) { - mTranslator.translateRectInScreenToAppWinFrame(mTmpFrames.frame); + mTranslator.translateRectInScreenToAppWindow(mTmpFrames.frame); + mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets); } setFrame(mTmpFrames.frame); mInsetsController.onStateChanged(mTempInsets); @@ -7538,6 +7536,22 @@ public final class ViewRootImpl implements ViewParent, } /** + * Gets the current display size in which the window is being laid out, accounting for screen + * decorations around it. + */ + void getWindowVisibleDisplayFrame(Rect outFrame) { + outFrame.set(mTmpFrames.displayFrame); + // XXX This is really broken, and probably all needs to be done + // in the window manager, and we need to know more about whether + // we want the area behind or in front of the IME. + final Rect insets = mVisibleInsetsCache; + outFrame.left += insets.left; + outFrame.top += insets.top; + outFrame.right -= insets.right; + outFrame.bottom -= insets.bottom; + } + + /** * {@inheritDoc} */ @Override @@ -7856,13 +7870,8 @@ public final class ViewRootImpl implements ViewParent, MergedConfiguration mergedConfiguration, boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId) { final Rect frame = frames.frame; - final Rect contentInsets = frames.contentInsets; - final Rect visibleInsets = frames.visibleInsets; - final Rect stableInsets = frames.stableInsets; final Rect backDropFrame = frames.backdropFrame; if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() - + " contentInsets=" + contentInsets.toShortString() - + " visibleInsets=" + visibleInsets.toShortString() + " reportDraw=" + reportDraw + " backDropFrame=" + backDropFrame); @@ -7873,7 +7882,7 @@ public final class ViewRootImpl implements ViewParent, synchronized (mWindowCallbacks) { for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, - visibleInsets, stableInsets); + mVisibleInsetsCache, mStableInsetsCache); } } } @@ -7881,8 +7890,6 @@ public final class ViewRootImpl implements ViewParent, Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); if (mTranslator != null) { mTranslator.translateRectInScreenToAppWindow(frame); - mTranslator.translateRectInScreenToAppWindow(contentInsets); - mTranslator.translateRectInScreenToAppWindow(visibleInsets); } SomeArgs args = SomeArgs.obtain(); final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); @@ -7900,6 +7907,9 @@ public final class ViewRootImpl implements ViewParent, if (Binder.getCallingPid() == android.os.Process.myPid()) { insetsState = new InsetsState(insetsState, true /* copySource */); } + if (mTranslator != null) { + mTranslator.translateInsetsStateInScreenToAppWindow(insetsState); + } mHandler.obtainMessage(MSG_INSETS_CHANGED, insetsState).sendToTarget(); } @@ -7913,6 +7923,9 @@ public final class ViewRootImpl implements ViewParent, } } } + if (mTranslator != null) { + mTranslator.translateInsetsStateInScreenToAppWindow(insetsState); + } SomeArgs args = SomeArgs.obtain(); args.arg1 = insetsState; args.arg2 = activeControls; diff --git a/core/java/android/view/ViewRootInsetsControllerHost.java b/core/java/android/view/ViewRootInsetsControllerHost.java index 8f58df466ee3..514fb29029d0 100644 --- a/core/java/android/view/ViewRootInsetsControllerHost.java +++ b/core/java/android/view/ViewRootInsetsControllerHost.java @@ -21,6 +21,7 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_APPEARANCE_CO import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_BEHAVIOR_CONTROLLED; import android.annotation.NonNull; +import android.content.res.CompatibilityInfo; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; @@ -251,4 +252,12 @@ public class ViewRootInsetsControllerHost implements InsetsController.Host { } return view.getWindowToken(); } + + @Override + public CompatibilityInfo.Translator getTranslator() { + if (mViewRoot != null) { + return mViewRoot.mTranslator; + } + return null; + } } diff --git a/core/java/android/view/WindowInsets.java b/core/java/android/view/WindowInsets.java index 94c518483429..8b0cf3bb86dc 100644 --- a/core/java/android/view/WindowInsets.java +++ b/core/java/android/view/WindowInsets.java @@ -924,6 +924,15 @@ public final class WindowInsets { Preconditions.checkArgumentNonnegative(right); Preconditions.checkArgumentNonnegative(bottom); + return insetUnchecked(left, top, right, bottom); + } + + /** + * @see #inset(int, int, int, int) + * @hide + */ + @NonNull + public WindowInsets insetUnchecked(int left, int top, int right, int bottom) { return new WindowInsets( mSystemWindowInsetsConsumed ? null diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java index 59e022645544..7dfae002b554 100644 --- a/core/java/android/view/WindowManagerImpl.java +++ b/core/java/android/view/WindowManagerImpl.java @@ -262,14 +262,11 @@ public final class WindowManagerImpl implements WindowManager { private WindowInsets getWindowInsetsFromServer(WindowManager.LayoutParams attrs, Rect bounds) { try { - final Rect systemWindowInsets = new Rect(); - final Rect stableInsets = new Rect(); final DisplayCutout.ParcelableWrapper displayCutout = new DisplayCutout.ParcelableWrapper(); final InsetsState insetsState = new InsetsState(); final boolean alwaysConsumeSystemBars = WindowManagerGlobal.getWindowManagerService() - .getWindowInsets(attrs, mContext.getDisplayId(), systemWindowInsets, - stableInsets, displayCutout, insetsState); + .getWindowInsets(attrs, mContext.getDisplayId(), displayCutout, insetsState); final Configuration config = mContext.getResources().getConfiguration(); final boolean isScreenRound = config.isScreenRound(); final int windowingMode = config.windowConfiguration.getWindowingMode(); diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java index 814787347b75..5e5d14f55240 100644 --- a/core/java/android/view/WindowlessWindowManager.java +++ b/core/java/android/view/WindowlessWindowManager.java @@ -131,7 +131,6 @@ public class WindowlessWindowManager implements IWindowSession { @Override public int addToDisplay(IWindow window, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, InsetsState requestedVisibility, Rect outFrame, - Rect outContentInsets, Rect outStableInsets, DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) { final SurfaceControl.Builder b = new SurfaceControl.Builder(mSurfaceSession) @@ -167,18 +166,16 @@ public class WindowlessWindowManager implements IWindowSession { @Override public int addToDisplayAsUser(IWindow window, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, int userId, InsetsState requestedVisibility, - Rect outFrame, Rect outContentInsets, Rect outStableInsets, - DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, - InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) { + Rect outFrame, DisplayCutout.ParcelableWrapper outDisplayCutout, + InputChannel outInputChannel, InsetsState outInsetsState, + InsetsSourceControl[] outActiveControls) { return addToDisplay(window, attrs, viewVisibility, displayId, requestedVisibility, - outFrame, outContentInsets, outStableInsets, outDisplayCutout, outInputChannel, - outInsetsState, outActiveControls); + outFrame, outDisplayCutout, outInputChannel, outInsetsState, outActiveControls); } @Override public int addToDisplayWithoutInputChannel(android.view.IWindow window, android.view.WindowManager.LayoutParams attrs, int viewVisibility, int layerStackId, - android.graphics.Rect outContentInsets, android.graphics.Rect outStableInsets, android.view.InsetsState insetsState) { return 0; } diff --git a/core/java/android/window/ClientWindowFrames.java b/core/java/android/window/ClientWindowFrames.java index 0523e64f3e7a..5d7025b57f91 100644 --- a/core/java/android/window/ClientWindowFrames.java +++ b/core/java/android/window/ClientWindowFrames.java @@ -42,19 +42,11 @@ public class ClientWindowFrames implements Parcelable { /** The area cut from the display. */ public final @NonNull DisplayCutout.ParcelableWrapper displayCutout; - // TODO(b/149813814): Remove legacy insets. - public final Rect contentInsets; - public final Rect visibleInsets; - public final Rect stableInsets; - public ClientWindowFrames() { frame = new Rect(); displayFrame = new Rect(); backdropFrame = new Rect(); displayCutout = new DisplayCutout.ParcelableWrapper(); - contentInsets = new Rect(); - visibleInsets = new Rect(); - stableInsets = new Rect(); } public ClientWindowFrames(ClientWindowFrames other) { @@ -62,9 +54,6 @@ public class ClientWindowFrames implements Parcelable { displayFrame = new Rect(other.displayFrame); backdropFrame = new Rect(other.backdropFrame); displayCutout = new DisplayCutout.ParcelableWrapper(other.displayCutout.get()); - contentInsets = new Rect(other.contentInsets); - visibleInsets = new Rect(other.visibleInsets); - stableInsets = new Rect(other.stableInsets); } private ClientWindowFrames(Parcel in) { @@ -72,9 +61,6 @@ public class ClientWindowFrames implements Parcelable { displayFrame = Rect.CREATOR.createFromParcel(in); backdropFrame = Rect.CREATOR.createFromParcel(in); displayCutout = DisplayCutout.ParcelableWrapper.CREATOR.createFromParcel(in); - contentInsets = Rect.CREATOR.createFromParcel(in); - visibleInsets = Rect.CREATOR.createFromParcel(in); - stableInsets = Rect.CREATOR.createFromParcel(in); } /** Needed for AIDL out parameters. */ @@ -83,9 +69,6 @@ public class ClientWindowFrames implements Parcelable { displayFrame.set(Rect.CREATOR.createFromParcel(in)); backdropFrame.set(Rect.CREATOR.createFromParcel(in)); displayCutout.set(DisplayCutout.ParcelableWrapper.CREATOR.createFromParcel(in)); - contentInsets.set(Rect.CREATOR.createFromParcel(in)); - visibleInsets.set(Rect.CREATOR.createFromParcel(in)); - stableInsets.set(Rect.CREATOR.createFromParcel(in)); } @Override @@ -94,9 +77,6 @@ public class ClientWindowFrames implements Parcelable { displayFrame.writeToParcel(dest, flags); backdropFrame.writeToParcel(dest, flags); displayCutout.writeToParcel(dest, flags); - contentInsets.writeToParcel(dest, flags); - visibleInsets.writeToParcel(dest, flags); - stableInsets.writeToParcel(dest, flags); } @Override diff --git a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java index b98ce308ae3b..873627eae696 100644 --- a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java +++ b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java @@ -109,7 +109,7 @@ public class InsetsAnimationControlImplTest { mController = new InsetsAnimationControlImpl(controls, new Rect(0, 0, 500, 500), mInsetsState, mMockListener, systemBars(), mMockController, 10 /* durationMs */, new LinearInterpolator(), - 0 /* animationType */); + 0 /* animationType */, null /* translator */); mController.mReadyDispatched = true; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java index eaf5d7960aa9..24381d937e2f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java @@ -270,25 +270,6 @@ public class SystemWindows { mDisplayId = displayId; } - @Override - public int relayout(IWindow window, WindowManager.LayoutParams attrs, - int requestedWidth, int requestedHeight, int viewVisibility, int flags, - long frameNumber, ClientWindowFrames outFrames, - MergedConfiguration mergedConfiguration, - SurfaceControl outSurfaceControl, InsetsState outInsetsState, - InsetsSourceControl[] outActiveControls, Point outSurfaceSize) { - int res = super.relayout(window, attrs, requestedWidth, requestedHeight, - viewVisibility, flags, frameNumber, outFrames, - mergedConfiguration, outSurfaceControl, outInsetsState, - outActiveControls, outSurfaceSize); - if (res != 0) { - return res; - } - DisplayLayout dl = mDisplayController.getDisplayLayout(mDisplayId); - outFrames.stableInsets.set(dl.stableInsets()); - return 0; - } - void updateConfiguration(Configuration configuration) { setConfiguration(configuration); } diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 4e07d8e1f5a8..eeac55d359a4 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -621,6 +621,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * 1920x1080, and the actually size on the screen is 960x540, then the scale is 0.5. */ private float mSizeCompatScale = 1f; + /** * The bounds in global coordinates for activity in size compatibility mode. * @see ActivityRecord#hasSizeCompatBounds() @@ -6491,6 +6492,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A && !mAtmService.mForceResizableActivities; } + @Override boolean hasSizeCompatBounds() { return mSizeCompatBounds != null; } diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index 0801f68681ab..b0ddb61d34bd 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -188,7 +188,6 @@ import com.android.server.policy.WindowOrientationListener; import com.android.server.statusbar.StatusBarManagerInternal; import com.android.server.wallpaper.WallpaperManagerInternal; import com.android.server.wm.InputMonitor.EventReceiverInputConsumer; -import com.android.server.wm.utils.InsetUtils; import java.io.PrintWriter; import java.util.function.Consumer; @@ -1439,25 +1438,15 @@ public class DisplayPolicy { * @param attrs The LayoutParams of the window. * @param windowToken The token of the window. * @param outFrame The frame of the window. - * @param outContentInsets The areas covered by system windows, expressed as positive insets. - * @param outStableInsets The areas covered by stable system windows irrespective of their - * current visibility. Expressed as positive insets. * @param outDisplayCutout The area that has been cut away from the display. + * @param outInsetsState The insets state of this display from the client's perspective. + * @param localClient Whether the client is from the our process. * @return Whether to always consume the system bars. * See {@link #areSystemBarsForcedShownLw(WindowState)}. */ boolean getLayoutHint(LayoutParams attrs, WindowToken windowToken, Rect outFrame, - Rect outContentInsets, Rect outStableInsets, - DisplayCutout.ParcelableWrapper outDisplayCutout) { - final int fl = attrs.flags; - final int pfl = attrs.privateFlags; - final int sysUiVis = attrs.systemUiVisibility | attrs.subtreeSystemUiVisibility; - - final boolean layoutInScreen = (fl & FLAG_LAYOUT_IN_SCREEN) != 0; - final boolean layoutInScreenAndInsetDecor = layoutInScreen - && (fl & FLAG_LAYOUT_INSET_DECOR) != 0; - final boolean screenDecor = (pfl & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0; - + DisplayCutout.ParcelableWrapper outDisplayCutout, InsetsState outInsetsState, + boolean localClient) { final boolean isFixedRotationTransforming = windowToken != null && windowToken.isFixedRotationTransforming(); final ActivityRecord activity = windowToken != null ? windowToken.asActivityRecord() : null; @@ -1466,56 +1455,36 @@ public class DisplayPolicy { // Use token (activity) bounds if it is rotated because its task is not rotated. ? windowToken.getBounds() : (task != null ? task.getBounds() : null); + final InsetsState state = + mDisplayContent.getInsetsPolicy().getInsetsForWindowMetrics(attrs); + computeWindowBounds(attrs, state, outFrame); + if (taskBounds != null) { + outFrame.intersect(taskBounds); + } + + final int fl = attrs.flags; + final int pfl = attrs.privateFlags; + final boolean layoutInScreenAndInsetDecor = (fl & FLAG_LAYOUT_IN_SCREEN) != 0 + && (fl & FLAG_LAYOUT_INSET_DECOR) != 0; + final boolean screenDecor = (pfl & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0; final DisplayFrames displayFrames = isFixedRotationTransforming ? windowToken.getFixedRotationTransformDisplayFrames() : mDisplayContent.mDisplayFrames; - if (layoutInScreenAndInsetDecor && !screenDecor) { - if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 - || (attrs.getFitInsetsTypes() & Type.navigationBars()) == 0) { - outFrame.set(displayFrames.mUnrestricted); - } else { - outFrame.set(displayFrames.mRestricted); - } - - final boolean isFloatingTask = task != null && task.isFloating(); - final Rect sf = isFloatingTask ? null : displayFrames.mStable; - final Rect cf; - if (isFloatingTask) { - cf = null; - } else if ((sysUiVis & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { - if ((fl & FLAG_FULLSCREEN) != 0) { - cf = displayFrames.mStableFullscreen; - } else { - cf = displayFrames.mStable; - } - } else if ((fl & FLAG_FULLSCREEN) != 0) { - cf = displayFrames.mUnrestricted; - } else { - cf = displayFrames.mCurrent; - } - - if (taskBounds != null) { - outFrame.intersect(taskBounds); - } - InsetUtils.insetsBetweenFrames(outFrame, cf, outContentInsets); - InsetUtils.insetsBetweenFrames(outFrame, sf, outStableInsets); - outDisplayCutout.set(displayFrames.mDisplayCutout.calculateRelativeTo(outFrame) - .getDisplayCutout()); + outDisplayCutout.set( + displayFrames.mDisplayCutout.calculateRelativeTo(outFrame).getDisplayCutout()); } else { - if (layoutInScreen) { - outFrame.set(displayFrames.mUnrestricted); - } else { - outFrame.set(displayFrames.mStable); - } - if (taskBounds != null) { - outFrame.intersect(taskBounds); - } - - outContentInsets.setEmpty(); - outStableInsets.setEmpty(); outDisplayCutout.set(DisplayCutout.NO_CUTOUT); } + + final boolean inSizeCompatMode = WindowState.inSizeCompatMode(attrs, windowToken); + outInsetsState.set(state, inSizeCompatMode || localClient); + if (inSizeCompatMode) { + final float compatScale = windowToken != null + ? windowToken.getSizeCompatScale() + : mDisplayContent.mCompatibleScreenScale; + outInsetsState.scale(1f / compatScale); + } return mForceShowSystemBars; } @@ -1616,8 +1585,9 @@ public class DisplayPolicy { */ public void beginLayoutLw(DisplayFrames displayFrames, int uiMode) { displayFrames.onBeginLayout(); - updateInsetsStateForDisplayCutout(displayFrames, - mDisplayContent.getInsetsStateController().getRawInsetsState()); + final InsetsState state = mDisplayContent.getInsetsStateController().getRawInsetsState(); + updateInsetsStateForDisplayCutout(displayFrames, state); + state.setDisplayFrame(displayFrames.mUnrestricted); mSystemGestures.screenWidth = displayFrames.mUnrestricted.width(); mSystemGestures.screenHeight = displayFrames.mUnrestricted.height(); @@ -1981,6 +1951,28 @@ public class DisplayPolicy { return !notFocusableForIm; } + private void computeWindowBounds(WindowManager.LayoutParams attrs, InsetsState state, + Rect outBounds) { + final @InsetsType int typesToFit = attrs.getFitInsetsTypes(); + final @InsetsSide int sidesToFit = attrs.getFitInsetsSides(); + final ArraySet<Integer> types = InsetsState.toInternalType(typesToFit); + final Rect dfu = state.getDisplayFrame(); + Insets insets = Insets.of(0, 0, 0, 0); + for (int i = types.size() - 1; i >= 0; i--) { + final InsetsSource source = state.peekSource(types.valueAt(i)); + if (source == null) { + continue; + } + insets = Insets.max(insets, source.calculateInsets( + dfu, attrs.isFitInsetsIgnoringVisibility())); + } + final int left = (sidesToFit & Side.LEFT) != 0 ? insets.left : 0; + final int top = (sidesToFit & Side.TOP) != 0 ? insets.top : 0; + final int right = (sidesToFit & Side.RIGHT) != 0 ? insets.right : 0; + final int bottom = (sidesToFit & Side.BOTTOM) != 0 ? insets.bottom : 0; + outBounds.set(dfu.left + left, dfu.top + top, dfu.right - right, dfu.bottom - bottom); + } + /** * Called for each window attached to the window manager as layout is proceeding. The * implementation of this function must take care of setting the window's frame, either here or @@ -2027,31 +2019,12 @@ public class DisplayPolicy { sf.set(displayFrames.mStable); - final @InsetsType int typesToFit = attrs.getFitInsetsTypes(); - final @InsetsSide int sidesToFit = attrs.getFitInsetsSides(); - final ArraySet<Integer> types = InsetsState.toInternalType(typesToFit); - getRotatedWindowBounds(displayFrames, win, sTmpRect); - final Rect dfu = sTmpRect; - Insets insets = Insets.of(0, 0, 0, 0); - for (int i = types.size() - 1; i >= 0; i--) { - final InsetsSource source = mDisplayContent.getInsetsPolicy() - .getInsetsForDispatch(win).peekSource(types.valueAt(i)); - if (source == null) { - continue; - } - insets = Insets.max(insets, source.calculateInsets( - dfu, attrs.isFitInsetsIgnoringVisibility())); - } - final int left = (sidesToFit & Side.LEFT) != 0 ? insets.left : 0; - final int top = (sidesToFit & Side.TOP) != 0 ? insets.top : 0; - final int right = (sidesToFit & Side.RIGHT) != 0 ? insets.right : 0; - final int bottom = (sidesToFit & Side.BOTTOM) != 0 ? insets.bottom : 0; - df.set(dfu.left + left, dfu.top + top, dfu.right - right, dfu.bottom - bottom); + final InsetsState state = mDisplayContent.getInsetsPolicy().getInsetsForWindow(win); + computeWindowBounds(attrs, state, df); if (attached == null) { pf.set(df); if ((pfl & PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME) != 0) { - final InsetsSource source = mDisplayContent.getInsetsPolicy() - .getInsetsForDispatch(win).peekSource(ITYPE_IME); + final InsetsSource source = state.peekSource(ITYPE_IME); if (source != null) { pf.inset(source.calculateInsets(pf, false /* ignoreVisibility */)); } @@ -2126,6 +2099,7 @@ public class DisplayPolicy { // They will later be cropped or shifted using the displayFrame in WindowState, // which prevents overlap with the DisplayCutout. if (!attachedInParent && !floatingInScreenWindow) { + getRotatedWindowBounds(displayFrames, win, sTmpRect); sTmpRect.set(pf); pf.intersectUnchecked(displayCutoutSafeExceptMaybeBars); windowFrames.setParentFrameWasClippedByDisplayCutout(!sTmpRect.equals(pf)); diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index bd05da9fe50a..a2b9cf9c5b3c 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -28,6 +28,7 @@ import static android.view.SyncRtSurfaceTransactionApplier.applyParams; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_STATUS_FORCE_SHOW_NAVIGATION; +import android.annotation.NonNull; import android.annotation.Nullable; import android.app.StatusBarManager; import android.util.IntArray; @@ -202,10 +203,22 @@ class InsetsPolicy { } /** - * @see InsetsStateController#getInsetsForDispatch + * @see InsetsStateController#getInsetsForWindow */ - InsetsState getInsetsForDispatch(WindowState target) { - final InsetsState originalState = mStateController.getInsetsForDispatch(target); + InsetsState getInsetsForWindow(WindowState target) { + final InsetsState originalState = mStateController.getInsetsForWindow(target); + return adjustVisibilityForTransientTypes(originalState); + } + + /** + * @see InsetsStateController#getInsetsForWindowMetrics + */ + InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) { + final InsetsState originalState = mStateController.getInsetsForWindowMetrics(attrs); + return adjustVisibilityForTransientTypes(originalState); + } + + private InsetsState adjustVisibilityForTransientTypes(InsetsState originalState) { InsetsState state = originalState; for (int i = mShowingTransientTypes.size() - 1; i >= 0; i--) { final @InternalInsetsType int type = mShowingTransientTypes.get(i); @@ -481,7 +494,7 @@ class InsetsPolicy { mFocusedWin.getDisplayContent().getBounds(), mFocusedWin.getInsetsState(), mListener, typesReady, this, mListener.getDurationMs(), InsetsController.SYSTEM_BARS_INTERPOLATOR, - show ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE); + show ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE, null /* translator */); SurfaceAnimationThread.getHandler().post( () -> mListener.onReady(mAnimationControl, typesReady)); } diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index b9c2093fe435..e7f140f989cc 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -97,14 +97,16 @@ class InsetsStateController { } /** - * When dispatching window state to the client, we'll need to exclude the source that represents - * the window that is being dispatched. We also need to exclude certain types of insets source - * for client within specific windowing modes. + * Gets the insets state from the perspective of the target. When performing layout of the + * target or dispatching insets to the target, we need to exclude sources which should not be + * 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. * - * @param target The client we dispatch the state to. + * @param target The window associate with the perspective. * @return The state stripped of the necessary information. */ - InsetsState getInsetsForDispatch(@NonNull WindowState target) { + InsetsState getInsetsForWindow(@NonNull WindowState target) { final InsetsState rotatedState = target.mToken.getFixedRotationTransformInsetsState(); if (rotatedState != null) { return rotatedState; @@ -112,17 +114,23 @@ class InsetsStateController { final InsetsSourceProvider provider = target.getControllableInsetProvider(); final @InternalInsetsType int type = provider != null ? provider.getSource().getType() : ITYPE_INVALID; - return getInsetsForDispatchInner(type, target.getWindowingMode(), target.isAlwaysOnTop(), + return getInsetsForTarget(type, target.getWindowingMode(), target.isAlwaysOnTop(), isAboveIme(target)); } InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) { final @InternalInsetsType int type = getInsetsTypeForLayoutParams(attrs); final WindowToken token = mDisplayContent.getWindowToken(attrs.token); + if (token != null) { + final InsetsState rotatedState = token.getFixedRotationTransformInsetsState(); + if (rotatedState != null) { + return rotatedState; + } + } final @WindowingMode int windowingMode = token != null ? token.getWindowingMode() : WINDOWING_MODE_UNDEFINED; final boolean alwaysOnTop = token != null && token.isAlwaysOnTop(); - return getInsetsForDispatchInner(type, windowingMode, alwaysOnTop, isAboveIme(token)); + return getInsetsForTarget(type, windowingMode, alwaysOnTop, isAboveIme(token)); } private boolean isAboveIme(WindowContainer target) { @@ -165,8 +173,11 @@ class InsetsStateController { return ITYPE_INVALID; } - /** @see #getInsetsForDispatch */ - private InsetsState getInsetsForDispatchInner(@InternalInsetsType int type, + /** + * @see #getInsetsForWindow + * @see #getInsetsForWindowMetrics + */ + private InsetsState getInsetsForTarget(@InternalInsetsType int type, @WindowingMode int windowingMode, boolean isAlwaysOnTop, boolean aboveIme) { InsetsState state = mState; @@ -270,7 +281,6 @@ class InsetsStateController { * Called when a layout pass has occurred. */ void onPostLayout() { - mState.setDisplayFrame(mDisplayContent.getBounds()); for (int i = mProviders.size() - 1; i >= 0; i--) { mProviders.valueAt(i).onPostLayout(); } diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java index 1b887a7c9172..70dbf683d6ec 100644 --- a/services/core/java/com/android/server/wm/Session.java +++ b/services/core/java/com/android/server/wm/Session.java @@ -165,36 +165,32 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient { @Override public int addToDisplay(IWindow window, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, InsetsState requestedVisibility, Rect outFrame, - Rect outContentInsets, Rect outStableInsets, DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) { return mService.addWindow(this, window, attrs, viewVisibility, displayId, - UserHandle.getUserId(mUid), requestedVisibility, outFrame, - outContentInsets, outStableInsets, outDisplayCutout, outInputChannel, - outInsetsState, outActiveControls); + UserHandle.getUserId(mUid), requestedVisibility, outFrame, outDisplayCutout, + outInputChannel, outInsetsState, outActiveControls); } @Override public int addToDisplayAsUser(IWindow window, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, int userId, InsetsState requestedVisibility, - Rect outFrame, Rect outContentInsets, Rect outStableInsets, - DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, - InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) { + Rect outFrame, DisplayCutout.ParcelableWrapper outDisplayCutout, + InputChannel outInputChannel, InsetsState outInsetsState, + InsetsSourceControl[] outActiveControls) { return mService.addWindow(this, window, attrs, viewVisibility, displayId, userId, - requestedVisibility, outFrame, outContentInsets, outStableInsets, outDisplayCutout, - outInputChannel, outInsetsState, outActiveControls); + requestedVisibility, outFrame, outDisplayCutout, outInputChannel, outInsetsState, + outActiveControls); } @Override public int addToDisplayWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, - int viewVisibility, int displayId, Rect outContentInsets, Rect outStableInsets, - InsetsState outInsetsState) { + int viewVisibility, int displayId, InsetsState outInsetsState) { return mService.addWindow(this, window, attrs, viewVisibility, displayId, UserHandle.getUserId(mUid), mDummyRequestedVisibility, - new Rect() /* outFrame */, outContentInsets, outStableInsets, - new DisplayCutout.ParcelableWrapper() /* cutout */, null /* outInputChannel */, - outInsetsState, mDummyControls); + new Rect() /* outFrame */, new DisplayCutout.ParcelableWrapper() /* cutout */, + null /* outInputChannel */, outInsetsState, mDummyControls); } @Override diff --git a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java index e8c4491d3677..aab5da6de214 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java @@ -242,9 +242,8 @@ class TaskSnapshotSurface implements StartingSurface { try { final int res = session.addToDisplay(window, layoutParams, View.GONE, activity.getDisplayContent().getDisplayId(), mTmpInsetsState, - tmpFrames.frame, tmpFrames.contentInsets, tmpFrames.stableInsets, - tmpFrames.displayCutout, null /* outInputChannel */, mTmpInsetsState, - mTempControls); + tmpFrames.frame, tmpFrames.displayCutout, null /* outInputChannel */, + mTmpInsetsState, mTempControls); if (res < 0) { Slog.w(TAG, "Failed to add snapshot starting window res=" + res); return null; diff --git a/services/core/java/com/android/server/wm/WindowFrames.java b/services/core/java/com/android/server/wm/WindowFrames.java index d96b6457f9db..259dee48fb39 100644 --- a/services/core/java/com/android/server/wm/WindowFrames.java +++ b/services/core/java/com/android/server/wm/WindowFrames.java @@ -207,28 +207,6 @@ public class WindowFrames { return (mLastFrame.width() != mFrame.width()) || (mLastFrame.height() != mFrame.height()); } - // TODO(b/118118435): Remove after migration. - /** - * Calculate the insets for the type - * {@link android.view.WindowManager.LayoutParams#TYPE_DOCK_DIVIDER} - * - * @param cutoutInsets The insets for the cutout. - */ - void calculateDockedDividerInsets(Rect cutoutInsets) { - // For the docked divider, we calculate the stable insets like a full-screen window - // so it can use it to calculate the snap positions. - mTmpRect.set(mDisplayFrame); - mTmpRect.inset(cutoutInsets); - mTmpRect.intersectUnchecked(mStableFrame); - InsetUtils.insetsBetweenFrames(mDisplayFrame, mTmpRect, mStableInsets); - - // The divider doesn't care about insets in any case, so set it to empty so we don't - // trigger a relayout when moving it. - mContentInsets.setEmpty(); - mVisibleInsets.setEmpty(); - mDisplayCutout = WmDisplayCutout.NO_CUTOUT; - } - /** * Calculate the insets for a window. * diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index ad624d50f7fd..6860365fdda5 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1376,7 +1376,6 @@ public class WindowManagerService extends IWindowManager.Stub public int addWindow(Session session, IWindow client, LayoutParams attrs, int viewVisibility, int displayId, int requestUserId, InsetsState requestedVisibility, Rect outFrame, - Rect outContentInsets, Rect outStableInsets, DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, InsetsState outInsetsState, InsetsSourceControl[] outActiveControls) { Arrays.fill(outActiveControls, null); @@ -1691,11 +1690,10 @@ public class WindowManagerService extends IWindowManager.Stub prepareNoneTransitionForRelaunching(activity); } - if (displayPolicy.getLayoutHint(win.mAttrs, token, outFrame, outContentInsets, - outStableInsets, outDisplayCutout)) { + if (displayPolicy.getLayoutHint(win.mAttrs, token, outFrame, outDisplayCutout, + outInsetsState, win.isClientLocal())) { res |= WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_SYSTEM_BARS; } - outInsetsState.set(win.getInsetsState(), win.isClientLocal()); if (mInTouchMode) { res |= WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE; @@ -8245,9 +8243,9 @@ public class WindowManagerService extends IWindowManager.Stub } @Override - public boolean getWindowInsets(WindowManager.LayoutParams attrs, - int displayId, Rect outContentInsets, Rect outStableInsets, + public boolean getWindowInsets(WindowManager.LayoutParams attrs, int displayId, DisplayCutout.ParcelableWrapper outDisplayCutout, InsetsState outInsetsState) { + final boolean fromLocal = Binder.getCallingPid() == myPid(); final long origId = Binder.clearCallingIdentity(); try { synchronized (mGlobalLock) { @@ -8257,13 +8255,8 @@ public class WindowManagerService extends IWindowManager.Stub + "could not be found!"); } final WindowToken windowToken = dc.getWindowToken(attrs.token); - final InsetsStateController insetsStateController = - dc.getInsetsStateController(); - outInsetsState.set(insetsStateController.getInsetsForWindowMetrics(attrs)); - return dc.getDisplayPolicy().getLayoutHint(attrs, windowToken, - mTmpRect /* outFrame */, outContentInsets, outStableInsets, - outDisplayCutout); + mTmpRect /* outFrame */, outDisplayCutout, outInsetsState, fromLocal); } } finally { Binder.restoreCallingIdentity(origId); diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index d4b6d00c1679..df9b4648bda0 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -977,16 +977,20 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP mSession.windowAddedLocked(mAttrs.packageName); } + boolean inSizeCompatMode() { + return inSizeCompatMode(mAttrs, mActivityRecord); + } + /** * @return {@code true} if the application runs in size compatibility mode. * @see android.content.res.CompatibilityInfo#supportsScreen - * @see ActivityRecord#inSizeCompatMode + * @see ActivityRecord#inSizeCompatMode() */ - boolean inSizeCompatMode() { - return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0 - || (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds() - // Exclude starting window because it is not displayed by the application. - && mAttrs.type != TYPE_APPLICATION_STARTING); + static boolean inSizeCompatMode(WindowManager.LayoutParams attrs, WindowToken windowToken) { + return (attrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0 + || (windowToken != null && windowToken.hasSizeCompatBounds() + // Exclude starting window because it is not displayed by the application. + && attrs.type != TYPE_APPLICATION_STARTING); } /** @@ -1224,14 +1228,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP Math.min(windowFrames.mStableFrame.bottom, windowFrames.mFrame.bottom)); } - if (mAttrs.type == TYPE_DOCK_DIVIDER) { - final WmDisplayCutout c = windowFrames.mDisplayCutout.calculateRelativeTo( - windowFrames.mDisplayFrame); - windowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets()); - } else { - windowFrames.calculateInsets(windowsAreFloating, isFullscreenAndFillsDisplay, - getDisplayFrames(dc.mDisplayFrames).mUnrestricted); - } + windowFrames.calculateInsets(windowsAreFloating, isFullscreenAndFillsDisplay, + getDisplayFrames(dc.mDisplayFrames).mUnrestricted); windowFrames.setDisplayCutout( windowFrames.mDisplayCutout.calculateRelativeTo(windowFrames.mFrame)); @@ -1545,7 +1543,12 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP * modification according to the state of transient bars. */ InsetsState getInsetsState() { - return getDisplayContent().getInsetsPolicy().getInsetsForDispatch(this); + InsetsState state = getDisplayContent().getInsetsPolicy().getInsetsForWindow(this); + if (inSizeCompatMode()) { + state = new InsetsState(state, true); + state.scale(mInvGlobalScale); + } + return state; } @Override @@ -3607,11 +3610,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP backdropFrame.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); } outFrames.displayCutout.set(mWindowFrames.mDisplayCutout.getDisplayCutout()); - - // TODO(b/149813814): Remove legacy insets. - outFrames.contentInsets.set(mWindowFrames.mLastContentInsets); - outFrames.visibleInsets.set(mWindowFrames.mLastVisibleInsets); - outFrames.stableInsets.set(mWindowFrames.mLastStableInsets); } void reportResized() { @@ -5644,7 +5642,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP * into the state of the control target. * * @param insetProvider the provider which should not be visible to the client. - * @see InsetsStateController#getInsetsForDispatch(WindowState) + * @see InsetsStateController#getInsetsForWindow(WindowState) */ void setControllableInsetProvider(InsetsSourceProvider insetProvider) { mControllableInsetProvider = insetProvider; diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index fa0b8cce5f70..5ced6a52050b 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -335,6 +335,13 @@ class WindowToken extends WindowContainer<WindowState> { } /** + * @return {@code true} if this window token has bounds for size compatibility mode. + */ + boolean hasSizeCompatBounds() { + return false; + } + + /** * Returns true if the new window is considered greater than the existing window in terms of * z-order. */ 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 ad9692f404e9..dd4d718084ab 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -1525,7 +1525,6 @@ public class ActivityRecordTests extends WindowTestsBase { any() /* window */, any() /* attrs */, anyInt() /* viewVisibility */, anyInt() /* displayId */, any() /* requestedVisibility */, any() /* outFrame */, - any() /* outContentInsets */, any() /* outStableInsets */, any() /* outDisplayCutout */, any() /* outInputChannel */, any() /* outInsetsState */, any() /* outActiveControls */); TaskSnapshotSurface.create(mAtm.mWindowManager, mActivity, snapshot); 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 5a14a249e78f..3598cd8d841d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyLayoutTests.java @@ -157,6 +157,8 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { mDisplayBounds.set(0, 0, mFrames.mDisplayWidth, mFrames.mDisplayHeight); mDisplayContent.mDisplayFrames = mFrames; mDisplayContent.setBounds(mDisplayBounds); + mDisplayContent.getInsetsStateController().getRawInsetsState().setDisplayFrame( + mDisplayBounds); } private DisplayFrames createDisplayFrames() { @@ -339,7 +341,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitInsetsIgnoringVisibility() { final InsetsState state = - mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow); + mDisplayContent.getInsetsPolicy().getInsetsForWindow(mWindow); state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false); mWindow.mAttrs.setFitInsetsIgnoringVisibility(true); @@ -359,7 +361,7 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutWindowLw_fitInsetsNotIgnoringVisibility() { final InsetsState state = - mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow); + mDisplayContent.getInsetsPolicy().getInsetsForWindow(mWindow); state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false); mWindow.mAttrs.setFitInsetsIgnoringVisibility(false); @@ -520,7 +522,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 */); - mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow) + mDisplayContent.getInsetsPolicy().getInsetsForWindow(mWindow) .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); final InsetsState requestedState = new InsetsState(); requestedState.getSource(ITYPE_STATUS_BAR).setVisible(false); @@ -544,7 +546,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 */); - mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow) + mDisplayContent.getInsetsPolicy().getInsetsForWindow(mWindow) .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); final InsetsState requestedState = new InsetsState(); requestedState.getSource(ITYPE_STATUS_BAR).setVisible(false); @@ -774,31 +776,30 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { @Test public void layoutHint_appWindow() { - mWindow.mAttrs.flags = - FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; + mWindow.mAttrs.setFitInsetsTypes(0); // Initialize DisplayFrames mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); final Rect outFrame = new Rect(); - final Rect outContentInsets = new Rect(); - final Rect outStableInsets = new Rect(); final DisplayCutout.ParcelableWrapper outDisplayCutout = new DisplayCutout.ParcelableWrapper(); + final InsetsState outState = new InsetsState(); mDisplayPolicy.getLayoutHint(mWindow.mAttrs, null /* windowToken */, outFrame, - outContentInsets, outStableInsets, outDisplayCutout); + outDisplayCutout, outState, true /* localClient */); - assertThat(outFrame, is(mFrames.mUnrestricted)); - assertThat(outContentInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT))); - assertThat(outStableInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT))); + assertThat(outFrame, is(outState.getDisplayFrame())); assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper())); + assertThat(outState.getSource(ITYPE_STATUS_BAR).getFrame(), + is(new Rect(0, 0, DISPLAY_WIDTH, STATUS_BAR_HEIGHT))); + assertThat(outState.getSource(ITYPE_NAVIGATION_BAR).getFrame(), + is(new Rect(0, DISPLAY_HEIGHT - NAV_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT))); } @Test public void layoutHint_appWindowInTask() { - mWindow.mAttrs.flags = - FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; + mWindow.mAttrs.setFitInsetsTypes(0); // Initialize DisplayFrames mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); @@ -809,24 +810,24 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { task.getWindowConfiguration().setBounds(taskBounds); final Rect outFrame = new Rect(); - final Rect outContentInsets = new Rect(); - final Rect outStableInsets = new Rect(); final DisplayCutout.ParcelableWrapper outDisplayCutout = new DisplayCutout.ParcelableWrapper(); + final InsetsState outState = new InsetsState(); - mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, - outContentInsets, outStableInsets, outDisplayCutout); + mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, outDisplayCutout, + outState, true /* localClient */); assertThat(outFrame, is(taskBounds)); - assertThat(outContentInsets, is(new Rect())); - assertThat(outStableInsets, is(new Rect())); assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper())); + assertThat(outState.getSource(ITYPE_STATUS_BAR).getFrame(), + is(new Rect(0, 0, DISPLAY_WIDTH, STATUS_BAR_HEIGHT))); + assertThat(outState.getSource(ITYPE_NAVIGATION_BAR).getFrame(), + is(new Rect(0, DISPLAY_HEIGHT - NAV_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT))); } @Test public void layoutHint_appWindowInTask_outsideContentFrame() { - mWindow.mAttrs.flags = - FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; + mWindow.mAttrs.setFitInsetsTypes(0); // Initialize DisplayFrames mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); @@ -843,18 +844,19 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { task.getWindowConfiguration().setBounds(taskBounds); final Rect outFrame = new Rect(); - final Rect outContentInsets = new Rect(); - final Rect outStableInsets = new Rect(); final DisplayCutout.ParcelableWrapper outDisplayCutout = new DisplayCutout.ParcelableWrapper(); + final InsetsState outState = new InsetsState(); - mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, outContentInsets, - outStableInsets, outDisplayCutout); + mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, outDisplayCutout, + outState, true /* localClient */); assertThat(outFrame, is(taskBounds)); - assertThat(outContentInsets, is(new Rect())); - assertThat(outStableInsets, is(new Rect())); assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper())); + assertThat(outState.getSource(ITYPE_STATUS_BAR).getFrame(), + is(new Rect(0, 0, DISPLAY_WIDTH, STATUS_BAR_HEIGHT))); + assertThat(outState.getSource(ITYPE_NAVIGATION_BAR).getFrame(), + is(new Rect(0, DISPLAY_HEIGHT - NAV_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT))); } /** 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 d67120f53917..a1606d3502ad 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java @@ -321,7 +321,7 @@ public class InsetsPolicyTest extends WindowTestsBase { assertNull(controls[i].getLeash()); } - final InsetsState state = policy.getInsetsForDispatch(mAppWindow); + final InsetsState state = policy.getInsetsForWindow(mAppWindow); state.setSourceVisible(ITYPE_STATUS_BAR, true); state.setSourceVisible(ITYPE_NAVIGATION_BAR, true); 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 c14df676f525..90caf35e2936 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsStateControllerTest.java @@ -63,7 +63,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { 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().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); + assertNotNull(getController().getInsetsForWindow(app).peekSource(ITYPE_STATUS_BAR)); } @Test @@ -72,7 +72,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR) .setWindow(statusBar, null, null); statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); - final InsetsState state = getController().getInsetsForDispatch(statusBar); + final InsetsState state = getController().getInsetsForWindow(statusBar); assertNull(state.peekSource(ITYPE_STATUS_BAR)); } @@ -88,8 +88,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { 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); - assertNull(getController().getInsetsForDispatch(navBar).peekSource(ITYPE_IME)); - assertNull(getController().getInsetsForDispatch(navBar).peekSource(ITYPE_STATUS_BAR)); + assertNull(getController().getInsetsForWindow(navBar).peekSource(ITYPE_IME)); + assertNull(getController().getInsetsForWindow(navBar).peekSource(ITYPE_STATUS_BAR)); } @Test @@ -102,8 +102,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); app.setWindowingMode(WINDOWING_MODE_PINNED); - assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); - assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); + assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_STATUS_BAR)); + assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_NAVIGATION_BAR)); } @Test @@ -116,8 +116,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); app.setWindowingMode(WINDOWING_MODE_FREEFORM); - assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); - assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); + assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_STATUS_BAR)); + assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_NAVIGATION_BAR)); } @Test @@ -131,8 +131,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); app.setAlwaysOnTop(true); - assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); - assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); + assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_STATUS_BAR)); + assertNull(getController().getInsetsForWindow(app).peekSource(ITYPE_NAVIGATION_BAR)); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -147,8 +147,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { app2.mBehindIme = false; getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertFalse(getController().getInsetsForDispatch(app2).getSource(ITYPE_IME).isVisible()); - assertTrue(getController().getInsetsForDispatch(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) @@ -160,7 +160,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.mBehindIme = true; getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); + assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -172,7 +172,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { app.mBehindIme = false; getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertFalse(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -207,7 +207,7 @@ 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().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); // Reset invocation counter. clearInvocations(app); @@ -221,7 +221,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { verify(app, atLeast(1)).notifyInsetsChanged(); // app will get visible IME insets while below IME. - assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); + assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -238,8 +238,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { mDisplayContent.applySurfaceChangesTransaction(); getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); - assertFalse(getController().getInsetsForDispatch(child).getSource(ITYPE_IME).isVisible()); + assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(child).getSource(ITYPE_IME).isVisible()); } @UseTestDisplay(addWindows = W_INPUT_METHOD) @@ -257,8 +257,8 @@ public class InsetsStateControllerTest extends WindowTestsBase { mDisplayContent.applySurfaceChangesTransaction(); getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); - assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); - assertFalse(getController().getInsetsForDispatch(child).getSource(ITYPE_IME).isVisible()); + assertTrue(getController().getInsetsForWindow(app).getSource(ITYPE_IME).isVisible()); + assertFalse(getController().getInsetsForWindow(child).getSource(ITYPE_IME).isVisible()); } @Test @@ -278,7 +278,7 @@ public class InsetsStateControllerTest extends WindowTestsBase { statusBarProvider.onPostLayout(); - final InsetsState state = getController().getInsetsForDispatch(ime); + final InsetsState state = getController().getInsetsForWindow(ime); assertEquals(new Rect(0, 1, 2, 3), state.getSource(ITYPE_STATUS_BAR).getFrame()); } |