Merge "Move tests from DisplayPolicyLayoutTests to WindowLayoutTests"
This commit is contained in:
@@ -1141,7 +1141,7 @@ public final class ViewRootImpl implements ViewParent,
|
||||
final Rect displayCutoutSafe = mTempRect;
|
||||
state.getDisplayCutoutSafe(displayCutoutSafe);
|
||||
final WindowConfiguration winConfig = getConfiguration().windowConfiguration;
|
||||
mWindowLayout.computeWindowFrames(mWindowAttributes, state,
|
||||
mWindowLayout.computeFrames(mWindowAttributes, state,
|
||||
displayCutoutSafe, winConfig.getBounds(), winConfig.getWindowingMode(),
|
||||
UNSPECIFIED_LENGTH, UNSPECIFIED_LENGTH,
|
||||
mInsetsController.getRequestedVisibilities(),
|
||||
|
||||
@@ -52,7 +52,7 @@ public class WindowLayout {
|
||||
private final Rect mTempDisplayCutoutSafeExceptMaybeBarsRect = new Rect();
|
||||
private final Rect mTempRect = new Rect();
|
||||
|
||||
public boolean computeWindowFrames(WindowManager.LayoutParams attrs, InsetsState state,
|
||||
public boolean computeFrames(WindowManager.LayoutParams attrs, InsetsState state,
|
||||
Rect displayCutoutSafe, Rect windowBounds, @WindowingMode int windowingMode,
|
||||
int requestedWidth, int requestedHeight, InsetsVisibilities requestedVisibilities,
|
||||
Rect attachedWindowFrame, float compatScale, Rect outDisplayFrame, Rect outParentFrame,
|
||||
|
||||
@@ -1447,7 +1447,7 @@ public class DisplayPolicy {
|
||||
final InsetsStateController controller = mDisplayContent.getInsetsStateController();
|
||||
for (int i = mInsetsSourceWindowsExceptIme.size() - 1; i >= 0; i--) {
|
||||
final WindowState win = mInsetsSourceWindowsExceptIme.valueAt(i);
|
||||
mWindowLayout.computeWindowFrames(win.getLayoutingAttrs(displayFrames.mRotation),
|
||||
mWindowLayout.computeFrames(win.getLayoutingAttrs(displayFrames.mRotation),
|
||||
displayFrames.mInsetsState, displayFrames.mDisplayCutoutSafe,
|
||||
displayFrames.mUnrestricted, win.getWindowingMode(), UNSPECIFIED_LENGTH,
|
||||
UNSPECIFIED_LENGTH, win.getRequestedVisibilities(),
|
||||
@@ -1496,7 +1496,7 @@ public class DisplayPolicy {
|
||||
|
||||
sTmpLastParentFrame.set(pf);
|
||||
|
||||
final boolean clippedByDisplayCutout = mWindowLayout.computeWindowFrames(attrs,
|
||||
final boolean clippedByDisplayCutout = mWindowLayout.computeFrames(attrs,
|
||||
win.getInsetsState(), displayFrames.mDisplayCutoutSafe,
|
||||
win.getBounds(), win.getWindowingMode(), requestedWidth, requestedHeight,
|
||||
win.getRequestedVisibilities(), attachedWindowFrame, win.mGlobalScale,
|
||||
|
||||
@@ -22,18 +22,9 @@ import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
|
||||
import static android.view.InsetsState.ITYPE_STATUS_BAR;
|
||||
import static android.view.InsetsState.ITYPE_TOP_GESTURES;
|
||||
import static android.view.Surface.ROTATION_0;
|
||||
import static android.view.Surface.ROTATION_270;
|
||||
import static android.view.Surface.ROTATION_90;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
|
||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
|
||||
|
||||
@@ -56,11 +47,8 @@ import android.util.Pair;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.DisplayInfo;
|
||||
import android.view.InsetsState;
|
||||
import android.view.InsetsVisibilities;
|
||||
import android.view.PrivacyIndicatorBounds;
|
||||
import android.view.RoundedCorners;
|
||||
import android.view.WindowInsets.Side;
|
||||
import android.view.WindowInsets.Type;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
@@ -108,15 +96,6 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
|
||||
updateDisplayFrames();
|
||||
}
|
||||
|
||||
void addWindowWithRawInsetsState(WindowState win) {
|
||||
addWindow(win);
|
||||
// Without mPerformLayout in display content, the window cannot see any insets. Override the
|
||||
// insets state with the global one.
|
||||
final InsetsState insetsState =
|
||||
win.getDisplayContent().getInsetsStateController().getRawInsetsState();
|
||||
win.mAboveInsetsState.set(insetsState);
|
||||
}
|
||||
|
||||
public void setRotation(int rotation, boolean includingWindows) {
|
||||
mRotation = rotation;
|
||||
updateDisplayFrames();
|
||||
@@ -231,388 +210,6 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
|
||||
expectThrows(IllegalArgumentException.class, () -> addWindow(win2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitStatusBars() {
|
||||
mWindow.mAttrs.setFitInsetsTypes(Type.statusBars());
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitNavigationBars() {
|
||||
mWindow.mAttrs.setFitInsetsTypes(Type.navigationBars());
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), 0, NAV_BAR_HEIGHT);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitAllSides() {
|
||||
mWindow.mAttrs.setFitInsetsSides(Side.all());
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitTopOnly() {
|
||||
mWindow.mAttrs.setFitInsetsSides(Side.TOP);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitInsetsIgnoringVisibility() {
|
||||
final InsetsState state =
|
||||
mDisplayContent.getInsetsStateController().getRawInsetsState();
|
||||
state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
|
||||
state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false);
|
||||
mWindow.mAttrs.setFitInsetsIgnoringVisibility(true);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitInsetsNotIgnoringVisibility() {
|
||||
final InsetsState state =
|
||||
mDisplayContent.getInsetsStateController().getRawInsetsState();
|
||||
state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
|
||||
state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false);
|
||||
mWindow.mAttrs.setFitInsetsIgnoringVisibility(false);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), 0, 0);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_insetParentFrameByIme() {
|
||||
final InsetsState state =
|
||||
mDisplayContent.getInsetsStateController().getRawInsetsState();
|
||||
state.getSource(InsetsState.ITYPE_IME).setVisible(true);
|
||||
state.getSource(InsetsState.ITYPE_IME).setFrame(
|
||||
0, DISPLAY_HEIGHT - IME_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
mWindow.mAttrs.privateFlags |= PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, IME_HEIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_fitDisplayCutout() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.setFitInsetsTypes(Type.displayCutout());
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), DISPLAY_CUTOUT_HEIGHT, 0);
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_never() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_shortEdges() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_always() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_layoutFullscreen() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_fullscreen() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mDisplayContent.getInsetsStateController().getRawInsetsState()
|
||||
.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
|
||||
final InsetsVisibilities requestedVisibilities = new InsetsVisibilities();
|
||||
requestedVisibilities.setVisibility(ITYPE_STATUS_BAR, false);
|
||||
mWindow.setRequestedVisibilities(requestedVisibilities);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_fullscreenInCutout() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mDisplayContent.getInsetsStateController().getRawInsetsState()
|
||||
.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
|
||||
final InsetsVisibilities requestedVisibilities = new InsetsVisibilities();
|
||||
requestedVisibilities.setVisibility(ITYPE_STATUS_BAR, false);
|
||||
mWindow.setRequestedVisibilities(requestedVisibilities);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_landscape() {
|
||||
addDisplayCutout();
|
||||
setRotation(ROTATION_90, true /* includingWindows */);
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_seascape() {
|
||||
addDisplayCutout();
|
||||
setRotation(ROTATION_270, true /* includingWindows */);
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_fullscreen_landscape() {
|
||||
addDisplayCutout();
|
||||
setRotation(ROTATION_90, true /* includingWindows */);
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_floatingInScreen() {
|
||||
addDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN;
|
||||
mWindow.mAttrs.setFitInsetsTypes(Type.systemBars() & ~Type.statusBars());
|
||||
mWindow.mAttrs.type = TYPE_APPLICATION_OVERLAY;
|
||||
mWindow.mAttrs.width = DISPLAY_WIDTH;
|
||||
mWindow.mAttrs.height = DISPLAY_HEIGHT;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
|
||||
assertInsetByTopBottom(mWindow.getDisplayFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withDisplayCutout_fullscreenInCutout_landscape() {
|
||||
addDisplayCutout();
|
||||
setRotation(ROTATION_90, true /* includingWindows */);
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withLongEdgeDisplayCutout() {
|
||||
addLongEdgeDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withLongEdgeDisplayCutout_never() {
|
||||
addLongEdgeDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withLongEdgeDisplayCutout_shortEdges() {
|
||||
addLongEdgeDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withLongEdgeDisplayCutout_always() {
|
||||
addLongEdgeDisplayCutout();
|
||||
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutWindowLw_withForwardInset_SoftInputAdjustNothing() {
|
||||
mWindow.mAttrs.flags =
|
||||
FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
||||
mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
|
||||
mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING;
|
||||
addWindowWithRawInsetsState(mWindow);
|
||||
|
||||
final int forwardedInsetBottom = 50;
|
||||
mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
|
||||
mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
|
||||
|
||||
assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
|
||||
assertInsetBy(mWindow.getDisplayFrame(), 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutHint_appWindow() {
|
||||
mWindow.mAttrs.setFitInsetsTypes(0);
|
||||
@@ -691,22 +288,4 @@ public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
|
||||
assertEquals(DISPLAY_WIDTH, frame.width());
|
||||
assertEquals(DISPLAY_HEIGHT, rotatedFrame.width());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that {@code actual} is inset by the given amounts from the full display rect.
|
||||
*
|
||||
* Convenience wrapper for when only the top and bottom inset are non-zero.
|
||||
*/
|
||||
private void assertInsetByTopBottom(Rect actual, int expectedInsetTop,
|
||||
int expectedInsetBottom) {
|
||||
assertInsetBy(actual, 0, expectedInsetTop, 0, expectedInsetBottom);
|
||||
}
|
||||
|
||||
/** Asserts that {@code actual} is inset by the given amounts from the full display rect. */
|
||||
private void assertInsetBy(Rect actual, int expectedInsetLeft, int expectedInsetTop,
|
||||
int expectedInsetRight, int expectedInsetBottom) {
|
||||
assertEquals(new Rect(expectedInsetLeft, expectedInsetTop,
|
||||
mFrames.mDisplayWidth - expectedInsetRight,
|
||||
mFrames.mDisplayHeight - expectedInsetBottom), actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,32 @@
|
||||
|
||||
package com.android.server.wm;
|
||||
|
||||
import static android.view.InsetsState.ITYPE_BOTTOM_DISPLAY_CUTOUT;
|
||||
import static android.view.InsetsState.ITYPE_LEFT_DISPLAY_CUTOUT;
|
||||
import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
|
||||
import static android.view.InsetsState.ITYPE_RIGHT_DISPLAY_CUTOUT;
|
||||
import static android.view.InsetsState.ITYPE_STATUS_BAR;
|
||||
import static android.view.InsetsState.ITYPE_TOP_DISPLAY_CUTOUT;
|
||||
import static android.view.WindowLayout.UNSPECIFIED_LENGTH;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
|
||||
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.app.WindowConfiguration;
|
||||
import android.graphics.Insets;
|
||||
import android.graphics.Rect;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.Gravity;
|
||||
import android.view.InsetsState;
|
||||
import android.view.InsetsVisibilities;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowLayout;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@@ -35,7 +51,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the {@link WindowLayout#computeWindowFrames}.
|
||||
* Tests for the {@link WindowLayout#computeFrames}.
|
||||
*
|
||||
* Build/Install/Run:
|
||||
* atest WmTests:WindowLayoutTests
|
||||
@@ -47,6 +63,11 @@ public class WindowLayoutTests {
|
||||
private static final int DISPLAY_HEIGHT = 1000;
|
||||
private static final int STATUS_BAR_HEIGHT = 10;
|
||||
private static final int NAVIGATION_BAR_HEIGHT = 15;
|
||||
private static final int IME_HEIGHT = 400;
|
||||
private static final int DISPLAY_CUTOUT_HEIGHT = 8;
|
||||
private static final Rect DISPLAY_CUTOUT_BOUNDS_TOP =
|
||||
new Rect(DISPLAY_WIDTH / 4, 0, DISPLAY_WIDTH * 3 / 4, DISPLAY_CUTOUT_HEIGHT);
|
||||
private static final Insets WATERFALL_INSETS = Insets.of(6, 0, 12, 0);
|
||||
|
||||
private final WindowLayout mWindowLayout = new WindowLayout();
|
||||
private final Rect mDisplayFrame = new Rect();
|
||||
@@ -69,9 +90,9 @@ public class WindowLayoutTests {
|
||||
mAttrs = new WindowManager.LayoutParams();
|
||||
mState = new InsetsState();
|
||||
mState.setDisplayFrame(new Rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT));
|
||||
mState.getSource(InsetsState.ITYPE_STATUS_BAR).setFrame(
|
||||
mState.getSource(ITYPE_STATUS_BAR).setFrame(
|
||||
0, 0, DISPLAY_WIDTH, STATUS_BAR_HEIGHT);
|
||||
mState.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setFrame(
|
||||
mState.getSource(ITYPE_NAVIGATION_BAR).setFrame(
|
||||
0, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
mState.getDisplayCutoutSafe(mDisplayCutoutSafe);
|
||||
mWindowBounds = new Rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
@@ -83,34 +104,65 @@ public class WindowLayoutTests {
|
||||
mCompatScale = 1f;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultLayoutParams() {
|
||||
computeWindowFrames();
|
||||
private void computeFrames() {
|
||||
mWindowLayout.computeFrames(mAttrs, mState, mDisplayCutoutSafe, mWindowBounds,
|
||||
mWindowingMode, mRequestedWidth, mRequestedHeight, mRequestedVisibilities,
|
||||
mAttachedWindowFrame, mCompatScale, mDisplayFrame, mParentFrame, mFrame);
|
||||
}
|
||||
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mDisplayFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mParentFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mFrame);
|
||||
private void addDisplayCutout() {
|
||||
mState.setDisplayCutout(new DisplayCutout(
|
||||
Insets.of(WATERFALL_INSETS.left, DISPLAY_CUTOUT_HEIGHT, WATERFALL_INSETS.right, 0),
|
||||
new Rect(),
|
||||
DISPLAY_CUTOUT_BOUNDS_TOP,
|
||||
new Rect(),
|
||||
new Rect(),
|
||||
WATERFALL_INSETS));
|
||||
mState.getDisplayCutoutSafe(mDisplayCutoutSafe);
|
||||
mState.getSource(ITYPE_LEFT_DISPLAY_CUTOUT).setFrame(
|
||||
0, 0, mDisplayCutoutSafe.left, DISPLAY_HEIGHT);
|
||||
mState.getSource(ITYPE_TOP_DISPLAY_CUTOUT).setFrame(
|
||||
0, 0, DISPLAY_WIDTH, mDisplayCutoutSafe.top);
|
||||
mState.getSource(ITYPE_RIGHT_DISPLAY_CUTOUT).setFrame(
|
||||
mDisplayCutoutSafe.right, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
mState.getSource(ITYPE_BOTTOM_DISPLAY_CUTOUT).setFrame(
|
||||
0, mDisplayCutoutSafe.bottom, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
}
|
||||
|
||||
private static void assertInsetByTopBottom(int top, int bottom, Rect actual) {
|
||||
assertInsetBy(0, top, 0, bottom, actual);
|
||||
}
|
||||
|
||||
private static void assertInsetBy(int left, int top, int right, int bottom, Rect actual) {
|
||||
assertRect(left, top, DISPLAY_WIDTH - right, DISPLAY_HEIGHT - bottom, actual);
|
||||
}
|
||||
|
||||
private static void assertRect(int left, int top, int right, int bottom, Rect actual) {
|
||||
assertEquals(new Rect(left, top, right, bottom), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmeasured() {
|
||||
public void defaultParams() {
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmeasured() {
|
||||
mRequestedWidth = UNSPECIFIED_LENGTH;
|
||||
mRequestedHeight = UNSPECIFIED_LENGTH;
|
||||
computeWindowFrames();
|
||||
computeFrames();
|
||||
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mDisplayFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mParentFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmeasuredWithSizeSpecifiedInLayoutParams() {
|
||||
public void unmeasuredWithSizeSpecifiedInLayoutParams() {
|
||||
final int width = DISPLAY_WIDTH / 2;
|
||||
final int height = DISPLAY_HEIGHT / 2;
|
||||
mRequestedWidth = UNSPECIFIED_LENGTH;
|
||||
@@ -118,41 +170,218 @@ public class WindowLayoutTests {
|
||||
mAttrs.width = width;
|
||||
mAttrs.height = height;
|
||||
mAttrs.gravity = Gravity.LEFT | Gravity.TOP;
|
||||
computeWindowFrames();
|
||||
computeFrames();
|
||||
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mDisplayFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
mParentFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, width, STATUS_BAR_HEIGHT + height,
|
||||
mFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertRect(0, STATUS_BAR_HEIGHT, width, STATUS_BAR_HEIGHT + height, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonFullscreenWindowBounds() {
|
||||
public void nonFullscreenWindowBounds() {
|
||||
final int top = Math.max(DISPLAY_HEIGHT / 2, STATUS_BAR_HEIGHT);
|
||||
mWindowBounds.set(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
mRequestedWidth = UNSPECIFIED_LENGTH;
|
||||
mRequestedHeight = UNSPECIFIED_LENGTH;
|
||||
computeWindowFrames();
|
||||
computeFrames();
|
||||
|
||||
assertRect(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
assertRect(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertRect(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertRect(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitStatusBars() {
|
||||
mAttrs.setFitInsetsTypes(WindowInsets.Type.statusBars());
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, 0, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, 0, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitNavigationBars() {
|
||||
mAttrs.setFitInsetsTypes(WindowInsets.Type.navigationBars());
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(0, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(0, NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertInsetByTopBottom(0, NAVIGATION_BAR_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitZeroTypes() {
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(0, 0, mDisplayFrame);
|
||||
assertInsetByTopBottom(0, 0, mParentFrame);
|
||||
assertInsetByTopBottom(0, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitAllSides() {
|
||||
mAttrs.setFitInsetsSides(WindowInsets.Side.all());
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitTopOnly() {
|
||||
mAttrs.setFitInsetsSides(WindowInsets.Side.TOP);
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, 0, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, 0, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitZeroSides() {
|
||||
mAttrs.setFitInsetsSides(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(0, 0, mDisplayFrame);
|
||||
assertInsetByTopBottom(0, 0, mParentFrame);
|
||||
assertInsetByTopBottom(0, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitInvisibleInsets() {
|
||||
mState.getSource(ITYPE_STATUS_BAR).setVisible(false);
|
||||
mState.getSource(ITYPE_NAVIGATION_BAR).setVisible(false);
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(0, 0, mDisplayFrame);
|
||||
assertInsetByTopBottom(0, 0, mParentFrame);
|
||||
assertInsetByTopBottom(0, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitInvisibleInsetsIgnoringVisibility() {
|
||||
mState.getSource(ITYPE_STATUS_BAR).setVisible(false);
|
||||
mState.getSource(ITYPE_NAVIGATION_BAR).setVisible(false);
|
||||
mAttrs.setFitInsetsIgnoringVisibility(true);
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insetParentFrameByIme() {
|
||||
mState.getSource(InsetsState.ITYPE_IME).setVisible(true);
|
||||
mState.getSource(InsetsState.ITYPE_IME).setFrame(
|
||||
0, DISPLAY_HEIGHT - IME_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
mAttrs.privateFlags |= PRIVATE_FLAG_INSET_PARENT_FRAME_BY_IME;
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, NAVIGATION_BAR_HEIGHT, mDisplayFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, IME_HEIGHT, mParentFrame);
|
||||
assertInsetByTopBottom(STATUS_BAR_HEIGHT, IME_HEIGHT, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fitDisplayCutout() {
|
||||
addDisplayCutout();
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
mAttrs.setFitInsetsTypes(WindowInsets.Type.displayCutout());
|
||||
computeFrames();
|
||||
|
||||
assertInsetBy(WATERFALL_INSETS.left, DISPLAY_CUTOUT_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mDisplayFrame);
|
||||
assertRect(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
assertInsetBy(WATERFALL_INSETS.left, DISPLAY_CUTOUT_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mParentFrame);
|
||||
assertRect(0, top, DISPLAY_WIDTH, DISPLAY_HEIGHT - NAVIGATION_BAR_HEIGHT,
|
||||
assertInsetBy(WATERFALL_INSETS.left, DISPLAY_CUTOUT_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mFrame);
|
||||
}
|
||||
|
||||
// TODO(b/161810301): Move tests here from DisplayPolicyLayoutTests and add more tests.
|
||||
@Test
|
||||
public void layoutInDisplayCutoutModeDefault() {
|
||||
addDisplayCutout();
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
private void computeWindowFrames() {
|
||||
mWindowLayout.computeWindowFrames(mAttrs, mState, mDisplayCutoutSafe, mWindowBounds,
|
||||
mWindowingMode, mRequestedWidth, mRequestedHeight, mRequestedVisibilities,
|
||||
mAttachedWindowFrame, mCompatScale, mDisplayFrame, mParentFrame, mFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mDisplayFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mParentFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mFrame);
|
||||
}
|
||||
|
||||
private void assertRect(int left, int top, int right, int bottom, Rect actual) {
|
||||
assertEquals(new Rect(left, top, right, bottom), actual);
|
||||
@Test
|
||||
public void layoutInDisplayCutoutModeDefaultWithLayoutInScreenAndLayoutInsetDecor() {
|
||||
addDisplayCutout();
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
|
||||
mAttrs.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetBy(WATERFALL_INSETS.left, 0, WATERFALL_INSETS.right, 0, mDisplayFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, 0, WATERFALL_INSETS.right, 0, mParentFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, 0, WATERFALL_INSETS.right, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutInDisplayCutoutModeDefaultWithInvisibleSystemBars() {
|
||||
addDisplayCutout();
|
||||
mState.getSource(ITYPE_STATUS_BAR).setVisible(false);
|
||||
mState.getSource(ITYPE_NAVIGATION_BAR).setVisible(false);
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mDisplayFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mParentFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutInDisplayCutoutModeShortEdges() {
|
||||
addDisplayCutout();
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetBy(WATERFALL_INSETS.left, 0, WATERFALL_INSETS.right, 0, mDisplayFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, 0, WATERFALL_INSETS.right, 0, mParentFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, 0, WATERFALL_INSETS.right, 0, mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutInDisplayCutoutModeNever() {
|
||||
addDisplayCutout();
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mDisplayFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mParentFrame);
|
||||
assertInsetBy(WATERFALL_INSETS.left, STATUS_BAR_HEIGHT, WATERFALL_INSETS.right, 0,
|
||||
mFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layoutInDisplayCutoutModeAlways() {
|
||||
addDisplayCutout();
|
||||
mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
mAttrs.setFitInsetsTypes(0);
|
||||
computeFrames();
|
||||
|
||||
assertInsetByTopBottom(0, 0, mDisplayFrame);
|
||||
assertInsetByTopBottom(0, 0, mParentFrame);
|
||||
assertInsetByTopBottom(0, 0, mFrame);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user