Make sure to extend insets frame when the bar layout with cutout

The private flag to let the layout system know the bar should extend its
requested size by the cutout size is not included in the insets
calculation, and the bar size will have a mis-match if they want to do
so. To modify the calculation of the insets to make them match.

Bug: 236101339
Test: See the bug
Test: atest DisplayPolicyInsetsTests
Change-Id: If76f3325196db7e8ab90d6dc56c9f67e0cd61ca9
This commit is contained in:
Yunfan Chen
2022-06-16 19:46:20 +09:00
parent 7eb0c5ea1f
commit 2a4fc3c9ba
2 changed files with 40 additions and 20 deletions

View File

@@ -16,8 +16,6 @@
package android.view;
import static android.view.Gravity.DISPLAY_CLIP_HORIZONTAL;
import static android.view.Gravity.DISPLAY_CLIP_VERTICAL;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
import static android.view.InsetsState.ITYPE_STATUS_BAR;
@@ -275,17 +273,9 @@ public class WindowLayout {
Gravity.applyDisplay(attrs.gravity, outDisplayFrame, outFrame);
}
if (extendedByCutout && !displayCutoutSafe.contains(outFrame)) {
mTempRect.set(outFrame);
// Move the frame into displayCutoutSafe.
final int clipFlags = DISPLAY_CLIP_VERTICAL | DISPLAY_CLIP_HORIZONTAL;
Gravity.applyDisplay(attrs.gravity & ~clipFlags, displayCutoutSafe,
if (extendedByCutout) {
extendFrameByCutout(attrs.gravity, displayCutoutSafe, outDisplayFrame, outFrame,
mTempRect);
if (mTempRect.intersect(outDisplayFrame)) {
outFrame.union(mTempRect);
}
}
if (DEBUG) Log.d(TAG, "computeFrames " + attrs.getTitle()
@@ -301,6 +291,21 @@ public class WindowLayout {
+ " requestedVisibilities=" + requestedVisibilities);
}
public static void extendFrameByCutout(int gravity, Rect displayCutoutSafe,
Rect displayFrame, Rect inOutFrame, Rect tempRect) {
if (displayCutoutSafe.contains(inOutFrame)) {
return;
}
tempRect.set(inOutFrame);
// Move the frame into displayCutoutSafe.
Gravity.applyDisplay(0 /* gravity */, displayCutoutSafe, tempRect);
if (tempRect.intersect(displayFrame)) {
inOutFrame.union(tempRect);
}
}
public static void computeSurfaceSize(WindowManager.LayoutParams attrs, Rect maxBounds,
int requestedWidth, int requestedHeight, Rect winFrame, boolean dragResizing,
Point outSurfaceSize) {

View File

@@ -46,6 +46,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_BAR_BACKGROUNDS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
@@ -1165,7 +1166,8 @@ public class DisplayPolicy {
continue;
}
calculateInsetsFrame(displayFrames, win, inOutFrame,
provider.source, provider.insetsSize
provider.source, provider.insetsSize,
lp.privateFlags, lp.gravity
);
}
}
@@ -1240,21 +1242,25 @@ public class DisplayPolicy {
provider.insetsSize != null
? (displayFrames, windowContainer, inOutFrame) -> {
inOutFrame.inset(win.mGivenContentInsets);
final LayoutParams lp =
win.mAttrs.forRotation(displayFrames.mRotation);
final InsetsFrameProvider ifp =
win.mAttrs.forRotation(displayFrames.mRotation)
.providedInsets[index];
lp.providedInsets[index];
calculateInsetsFrame(displayFrames, windowContainer,
inOutFrame, ifp.source, ifp.insetsSize);
inOutFrame, ifp.source, ifp.insetsSize,
lp.privateFlags, lp.gravity);
} : null;
final TriConsumer<DisplayFrames, WindowContainer, Rect> imeFrameProvider =
provider.imeInsetsSize != null
? (displayFrames, windowContainer, inOutFrame) -> {
inOutFrame.inset(win.mGivenContentInsets);
final LayoutParams lp =
win.mAttrs.forRotation(displayFrames.mRotation);
final InsetsFrameProvider ifp =
win.mAttrs.forRotation(displayFrames.mRotation)
.providedInsets[index];
lp.providedInsets[index];
calculateInsetsFrame(displayFrames, windowContainer,
inOutFrame, ifp.source, ifp.imeInsetsSize);
inOutFrame, ifp.source, ifp.imeInsetsSize,
lp.privateFlags, lp.gravity);
} : null;
mDisplayContent.setInsetProvider(provider.type, win, frameProvider,
imeFrameProvider);
@@ -1266,11 +1272,15 @@ public class DisplayPolicy {
}
private void calculateInsetsFrame(DisplayFrames df, WindowContainer container, Rect inOutFrame,
int source, Insets insetsSize) {
int source, Insets insetsSize, @LayoutParams.PrivateFlags int privateFlags,
int windowGravity) {
boolean extendByCutout = false;
if (source == InsetsFrameProvider.SOURCE_DISPLAY) {
inOutFrame.set(df.mUnrestricted);
} else if (source == InsetsFrameProvider.SOURCE_CONTAINER_BOUNDS) {
inOutFrame.set(container.getBounds());
} else {
extendByCutout = (privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0;
}
if (insetsSize == null) {
return;
@@ -1288,6 +1298,11 @@ public class DisplayPolicy {
} else {
inOutFrame.setEmpty();
}
if (extendByCutout) {
WindowLayout.extendFrameByCutout(windowGravity, df.mDisplayCutoutSafe,
df.mUnrestricted, inOutFrame, sTmpRect);
}
}
@WindowManagerPolicy.AltBarPosition