diff options
| author | Tiger Huang <tigerhuang@google.com> | 2022-07-01 16:58:21 +0800 |
|---|---|---|
| committer | Tiger Huang <tigerhuang@google.com> | 2022-07-27 14:10:10 +0800 |
| commit | c77eaf873d271082d8aa0c602c3e3f015b5db06a (patch) | |
| tree | 6ca3ec0787cce568f6a48dba0450f10487e17620 /core/java/android | |
| parent | bbb516199e96b0eed7a56c6ad31a17d0e4465db6 (diff) | |
Send size-compat scale to the client
The client computes the window frame on its own in ViewRootImpl#setView.
However, the bounds obtained from WindowConfiguration is not size-
compatible, which makes legacy apps produce wrong frames. The frame is
larger than expected, so when computing WindowInsets with size-
compatible InsetsState, the window cannot receive insets.
Although the client will receive the correct window frame from relayout,
but the first WindowInsets has been dispatched before that.
This CL sends the size-compat scale to the client, so the client can use
the correct WindowConfiguration to compute frames.
This is also a step to enable the client to perform local window layout.
Bug: 237749017
Bug: 161810301
Bug: 175861127
Test: atest StartingSurfaceDrawerTests WindowAddRemovePerfTest
ActivityRecordTests WindowManagerServiceTests
Change-Id: I6b23901f4b1f009444c04da7e078ea971a386ad7
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/WindowConfiguration.java | 9 | ||||
| -rw-r--r-- | core/java/android/content/res/CompatibilityInfo.java | 7 | ||||
| -rw-r--r-- | core/java/android/service/wallpaper/WallpaperService.java | 2 | ||||
| -rw-r--r-- | core/java/android/view/IWindowSession.aidl | 7 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 31 | ||||
| -rw-r--r-- | core/java/android/view/WindowlessWindowManager.java | 13 | ||||
| -rw-r--r-- | core/java/android/window/ClientWindowFrames.java | 8 |
7 files changed, 57 insertions, 20 deletions
diff --git a/core/java/android/app/WindowConfiguration.java b/core/java/android/app/WindowConfiguration.java index d0ea8d41d65c..397c8e010bad 100644 --- a/core/java/android/app/WindowConfiguration.java +++ b/core/java/android/app/WindowConfiguration.java @@ -460,6 +460,15 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu setDisplayWindowingMode(WINDOWING_MODE_UNDEFINED); } + /** @hide */ + public void scale(float scale) { + mBounds.scale(scale); + mMaxBounds.scale(scale); + if (mAppBounds != null) { + mAppBounds.scale(scale); + } + } + /** * Copies the fields from delta into this Configuration object, keeping * track of which ones have changed. Any undefined fields in {@code delta} diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java index 608e34bd07b4..e146bb9e20e2 100644 --- a/core/java/android/content/res/CompatibilityInfo.java +++ b/core/java/android/content/res/CompatibilityInfo.java @@ -551,12 +551,7 @@ public class CompatibilityInfo implements Parcelable { if (isScalingRequired()) { float invertedRatio = applicationInvertedScale; inoutConfig.densityDpi = (int)((inoutConfig.densityDpi * invertedRatio) + .5f); - inoutConfig.windowConfiguration.getMaxBounds().scale(invertedRatio); - inoutConfig.windowConfiguration.getBounds().scale(invertedRatio); - final Rect appBounds = inoutConfig.windowConfiguration.getAppBounds(); - if (appBounds != null) { - appBounds.scale(invertedRatio); - } + inoutConfig.windowConfiguration.scale(invertedRatio); } } diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 1df7dbc0cd0b..90e4e9406e53 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -1134,7 +1134,7 @@ public abstract class WallpaperService extends Service { if (mSession.addToDisplay(mWindow, mLayout, View.VISIBLE, mDisplay.getDisplayId(), mRequestedVisibilities, inputChannel, - mInsetsState, mTempControls, new Rect()) < 0) { + mInsetsState, mTempControls, new Rect(), new float[1]) < 0) { Log.w(TAG, "Failed to add window while updating wallpaper surface."); return; } diff --git a/core/java/android/view/IWindowSession.aidl b/core/java/android/view/IWindowSession.aidl index ef57b1ddd4b3..3016473fa040 100644 --- a/core/java/android/view/IWindowSession.aidl +++ b/core/java/android/view/IWindowSession.aidl @@ -50,15 +50,16 @@ interface IWindowSession { int addToDisplay(IWindow window, in WindowManager.LayoutParams attrs, in int viewVisibility, in int layerStackId, in InsetsVisibilities requestedVisibilities, out InputChannel outInputChannel, out InsetsState insetsState, - out InsetsSourceControl[] activeControls, out Rect attachedFrame); + out InsetsSourceControl[] activeControls, out Rect attachedFrame, + out float[] sizeCompatScale); int addToDisplayAsUser(IWindow window, in WindowManager.LayoutParams attrs, in int viewVisibility, in int layerStackId, in int userId, in InsetsVisibilities requestedVisibilities, out InputChannel outInputChannel, out InsetsState insetsState, out InsetsSourceControl[] activeControls, - out Rect attachedFrame); + out Rect attachedFrame, out float[] sizeCompatScale); int addToDisplayWithoutInputChannel(IWindow window, in WindowManager.LayoutParams attrs, in int viewVisibility, in int layerStackId, out InsetsState insetsState, - out Rect attachedFrame); + out Rect attachedFrame, out float[] sizeCompatScale); @UnsupportedAppUsage void remove(IWindow window); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 7be8dffdf023..45171a741313 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -695,6 +695,8 @@ public final class ViewRootImpl implements ViewParent, boolean mPendingAlwaysConsumeSystemBars; private final InsetsState mTempInsets = new InsetsState(); private final InsetsSourceControl[] mTempControls = new InsetsSourceControl[SIZE]; + private final WindowConfiguration mTempWinConfig = new WindowConfiguration(); + private float mInvSizeCompatScale = 1f; final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets = new ViewTreeObserver.InternalInsetsInfo(); @@ -1094,6 +1096,16 @@ public final class ViewRootImpl implements ViewParent, return mContext.getResources().getConfiguration(); } + private WindowConfiguration getCompatWindowConfiguration() { + final WindowConfiguration winConfig = getConfiguration().windowConfiguration; + if (mInvSizeCompatScale == 1f) { + return winConfig; + } + mTempWinConfig.setTo(winConfig); + mTempWinConfig.scale(mInvSizeCompatScale); + return mTempWinConfig; + } + /** * We have one child */ @@ -1224,10 +1236,11 @@ public final class ViewRootImpl implements ViewParent, controlInsetsForCompatibility(mWindowAttributes); Rect attachedFrame = new Rect(); + final float[] sizeCompatScale = { 1f }; res = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes, getHostVisibility(), mDisplay.getDisplayId(), userId, mInsetsController.getRequestedVisibilities(), inputChannel, mTempInsets, - mTempControls, attachedFrame); + mTempControls, attachedFrame, sizeCompatScale); if (!attachedFrame.isValid()) { attachedFrame = null; } @@ -1237,6 +1250,8 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateRectInScreenToAppWindow(attachedFrame); } mTmpFrames.attachedFrame = attachedFrame; + mTmpFrames.sizeCompatScale = sizeCompatScale[0]; + mInvSizeCompatScale = 1f / sizeCompatScale[0]; } catch (RemoteException e) { mAdded = false; mView = null; @@ -1259,7 +1274,7 @@ public final class ViewRootImpl implements ViewParent, final InsetsState state = mInsetsController.getState(); final Rect displayCutoutSafe = mTempRect; state.getDisplayCutoutSafe(displayCutoutSafe); - final WindowConfiguration winConfig = getConfiguration().windowConfiguration; + final WindowConfiguration winConfig = getCompatWindowConfiguration(); mWindowLayout.computeFrames(mWindowAttributes, state, displayCutoutSafe, winConfig.getBounds(), winConfig.getWindowingMode(), UNSPECIFIED_LENGTH, UNSPECIFIED_LENGTH, @@ -1749,19 +1764,24 @@ public final class ViewRootImpl implements ViewParent, mTranslator.translateRectInScreenToAppWindow(displayFrame); mTranslator.translateRectInScreenToAppWindow(attachedFrame); } + final float sizeCompatScale = frames.sizeCompatScale; final boolean frameChanged = !mWinFrame.equals(frame); final boolean configChanged = !mLastReportedMergedConfiguration.equals(mergedConfiguration); final boolean attachedFrameChanged = LOCAL_LAYOUT && !Objects.equals(mTmpFrames.attachedFrame, attachedFrame); final boolean displayChanged = mDisplay.getDisplayId() != displayId; final boolean resizeModeChanged = mResizeMode != resizeMode; + final boolean sizeCompatScaleChanged = mTmpFrames.sizeCompatScale != sizeCompatScale; if (msg == MSG_RESIZED && !frameChanged && !configChanged && !attachedFrameChanged - && !displayChanged && !resizeModeChanged && !forceNextWindowRelayout) { + && !displayChanged && !resizeModeChanged && !forceNextWindowRelayout + && !sizeCompatScaleChanged) { return; } mPendingDragResizing = resizeMode != RESIZE_MODE_INVALID; mResizeMode = resizeMode; + mTmpFrames.sizeCompatScale = sizeCompatScale; + mInvSizeCompatScale = 1f / sizeCompatScale; if (configChanged) { // If configuration changed - notify about that and, maybe, about move to display. @@ -8063,11 +8083,12 @@ public final class ViewRootImpl implements ViewParent, if (maybeSyncSeqId > 0) { mSyncSeqId = maybeSyncSeqId; } + mInvSizeCompatScale = 1f / mTmpFrames.sizeCompatScale; final int transformHint = SurfaceControl.rotationToBufferTransform( (mDisplayInstallOrientation + mDisplay.getRotation()) % 4); - final WindowConfiguration winConfig = getConfiguration().windowConfiguration; + final WindowConfiguration winConfig = getCompatWindowConfiguration(); WindowLayout.computeSurfaceSize(mWindowAttributes, winConfig.getMaxBounds(), requestedWidth, requestedHeight, mTmpFrames.frame, mPendingDragResizing, mSurfaceSize); @@ -8170,7 +8191,7 @@ public final class ViewRootImpl implements ViewParent, private void setFrame(Rect frame) { mWinFrame.set(frame); - final WindowConfiguration winConfig = getConfiguration().windowConfiguration; + final WindowConfiguration winConfig = getCompatWindowConfiguration(); mPendingBackDropFrame.set(mPendingDragResizing && !winConfig.useWindowFrameForBackdrop() ? winConfig.getMaxBounds() : frame); diff --git a/core/java/android/view/WindowlessWindowManager.java b/core/java/android/view/WindowlessWindowManager.java index 94da2741f71a..d55c838c3e53 100644 --- a/core/java/android/view/WindowlessWindowManager.java +++ b/core/java/android/view/WindowlessWindowManager.java @@ -149,7 +149,8 @@ public class WindowlessWindowManager implements IWindowSession { public int addToDisplay(IWindow window, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, InsetsVisibilities requestedVisibilities, InputChannel outInputChannel, InsetsState outInsetsState, - InsetsSourceControl[] outActiveControls, Rect outAttachedFrame) { + InsetsSourceControl[] outActiveControls, Rect outAttachedFrame, + float[] outSizeCompatScale) { final SurfaceControl.Builder b = new SurfaceControl.Builder(mSurfaceSession) .setFormat(attrs.format) .setBLASTLayer() @@ -182,6 +183,7 @@ public class WindowlessWindowManager implements IWindowSession { mStateForWindow.put(window.asBinder(), state); } outAttachedFrame.set(0, 0, -1, -1); + outSizeCompatScale[0] = 1f; final int res = WindowManagerGlobal.ADD_OKAY | WindowManagerGlobal.ADD_FLAG_APP_VISIBLE | WindowManagerGlobal.ADD_FLAG_USE_BLAST; @@ -197,15 +199,18 @@ public class WindowlessWindowManager implements IWindowSession { public int addToDisplayAsUser(IWindow window, WindowManager.LayoutParams attrs, int viewVisibility, int displayId, int userId, InsetsVisibilities requestedVisibilities, InputChannel outInputChannel, InsetsState outInsetsState, - InsetsSourceControl[] outActiveControls, Rect outAttachedFrame) { + InsetsSourceControl[] outActiveControls, Rect outAttachedFrame, + float[] outSizeCompatScale) { return addToDisplay(window, attrs, viewVisibility, displayId, requestedVisibilities, - outInputChannel, outInsetsState, outActiveControls, outAttachedFrame); + outInputChannel, outInsetsState, outActiveControls, outAttachedFrame, + outSizeCompatScale); } @Override public int addToDisplayWithoutInputChannel(android.view.IWindow window, android.view.WindowManager.LayoutParams attrs, int viewVisibility, int layerStackId, - android.view.InsetsState insetsState, Rect outAttachedFrame) { + android.view.InsetsState insetsState, Rect outAttachedFrame, + float[] outSizeCompatScale) { return 0; } diff --git a/core/java/android/window/ClientWindowFrames.java b/core/java/android/window/ClientWindowFrames.java index 929e81ed9044..f274d1a15ba5 100644 --- a/core/java/android/window/ClientWindowFrames.java +++ b/core/java/android/window/ClientWindowFrames.java @@ -49,6 +49,8 @@ public class ClientWindowFrames implements Parcelable { public boolean isParentFrameClippedByDisplayCutout; + public float sizeCompatScale = 1f; + public ClientWindowFrames() { } @@ -60,6 +62,7 @@ public class ClientWindowFrames implements Parcelable { attachedFrame = new Rect(other.attachedFrame); } isParentFrameClippedByDisplayCutout = other.isParentFrameClippedByDisplayCutout; + sizeCompatScale = other.sizeCompatScale; } private ClientWindowFrames(Parcel in) { @@ -73,6 +76,7 @@ public class ClientWindowFrames implements Parcelable { parentFrame.readFromParcel(in); attachedFrame = in.readTypedObject(Rect.CREATOR); isParentFrameClippedByDisplayCutout = in.readBoolean(); + sizeCompatScale = in.readFloat(); } @Override @@ -82,6 +86,7 @@ public class ClientWindowFrames implements Parcelable { parentFrame.writeToParcel(dest, flags); dest.writeTypedObject(attachedFrame, flags); dest.writeBoolean(isParentFrameClippedByDisplayCutout); + dest.writeFloat(sizeCompatScale); } @Override @@ -91,7 +96,8 @@ public class ClientWindowFrames implements Parcelable { + " display=" + displayFrame.toShortString(sb) + " parentFrame=" + parentFrame.toShortString(sb) + (attachedFrame != null ? " attachedFrame=" + attachedFrame.toShortString() : "") - + " parentClippedByDisplayCutout=" + isParentFrameClippedByDisplayCutout + "}"; + + (isParentFrameClippedByDisplayCutout ? " parentClippedByDisplayCutout" : "") + + (sizeCompatScale != 1f ? " sizeCompatScale=" + sizeCompatScale : "") + "}"; } @Override |
