Use IFP only for non-IME window insets providers
With the flexible insets change, it is now not possible the window is
providng insets but without a InsetsFrameProvider. The calculation of
the givenContentInsets is already included in the InsetsFrameProvider
and it is not longer necessary to calculate it in updateSourceFrame
any more.
For IME cases, the IME is provider its own frame provider to calculate
insets size with considering of the givenContentInsets. No extra
calculation needed in the general InsetsSourceProvider as well.
Tests are modified. The tests were using navigation bar to test the
mGivenContentInsets related logic. Since it will not really happen in
the production environment, modified the test to use IME window to
verify the logic, and cover the ImeSourceProvider related code.
Because the given content insets only in effect with the process of
DisplayPolicy, and is covered by the modified test is
DisplayPolicyTests, removing the other out-dated tests.
Test: DisplayPolicyTests
Test: DisplayPolicyInsetsTests
Bug: 274723551
Change-Id: I2a6828255a336fdf0d5b6c1281daff1cec02a7eb
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index d31fe23..6ed2025 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -1122,7 +1122,6 @@
inOutFrame.set(windowContainer.getBounds());
break;
case SOURCE_FRAME:
- inOutFrame.inset(win.mGivenContentInsets);
extendByCutout =
(lp.privateFlags & PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT) != 0;
break;
diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java
index 3b23f97..3e03b99 100644
--- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java
+++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java
@@ -218,8 +218,6 @@
if (mFrameProvider != null) {
mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
mWindowContainer, mSourceFrame);
- } else {
- mSourceFrame.inset(win.mGivenContentInsets);
}
updateSourceFrameForServerVisibility();
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 680f605..23934e0 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -428,8 +428,9 @@
boolean mGivenInsetsPending;
/**
- * These are the content insets that were given during layout for
- * this window, to be applied to windows behind it.
+ * These are the content insets that were given during layout for this window, to be applied to
+ * windows behind it.
+ * This is only applied to IME windows when corresponding process in DisplayPolicy executed.
*/
final Rect mGivenContentInsets = new Rect();
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java
index 2914de1..c8fdee0 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayPolicyTests.java
@@ -352,27 +352,28 @@
assertTrue(imeSource.getFrame().contains(navBarSource.getFrame()));
}
- @SetupWindows(addWindows = W_NAVIGATION_BAR)
+ @SetupWindows(addWindows = W_INPUT_METHOD)
@Test
- public void testInsetsGivenContentFrame() {
+ public void testImeInsetsGivenContentFrame() {
final DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy();
final DisplayInfo displayInfo = new DisplayInfo();
displayInfo.logicalWidth = 1000;
displayInfo.logicalHeight = 2000;
displayInfo.rotation = ROTATION_0;
- WindowManager.LayoutParams attrs = mNavBarWindow.mAttrs;
- displayPolicy.addWindowLw(mNavBarWindow, attrs);
- mNavBarWindow.setRequestedSize(attrs.width, attrs.height);
- mNavBarWindow.getControllableInsetProvider().setServerVisible(true);
+ mDisplayContent.setInputMethodWindowLocked(mImeWindow);
+ mImeWindow.getControllableInsetProvider().setServerVisible(true);
- mNavBarWindow.mGivenContentInsets.set(0, 10, 0, 0);
+ mImeWindow.mGivenContentInsets.set(0, 10, 0, 0);
- displayPolicy.layoutWindowLw(mNavBarWindow, null, mDisplayContent.mDisplayFrames);
+ displayPolicy.layoutWindowLw(mImeWindow, null, mDisplayContent.mDisplayFrames);
final InsetsState state = mDisplayContent.getInsetsStateController().getRawInsetsState();
- final InsetsSource navBarSource = state.peekSource(
- mNavBarWindow.getControllableInsetProvider().getSource().getId());
- assertEquals(attrs.height - 10, navBarSource.getFrame().height());
+ final InsetsSource imeSource = state.peekSource(ID_IME);
+
+ assertNotNull(imeSource);
+ assertFalse(imeSource.getFrame().isEmpty());
+ assertEquals(mImeWindow.getWindowFrames().mFrame.height() - 10,
+ imeSource.getFrame().height());
}
@SetupWindows(addWindows = { W_ACTIVITY, W_NAVIGATION_BAR })
diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java
index b35eceb..5e513f1 100644
--- a/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java
@@ -76,25 +76,6 @@
}
@Test
- public void testPostLayout_givenInsets() {
- final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime");
- ime.getFrame().set(0, 0, 500, 100);
- ime.mGivenContentInsets.set(0, 0, 0, 60);
- ime.mGivenVisibleInsets.set(0, 0, 0, 75);
- ime.mHasSurface = true;
- mProvider.setWindowContainer(ime, null, null);
- mProvider.updateSourceFrame(ime.getFrame());
- mProvider.onPostLayout();
- assertEquals(new Rect(0, 0, 500, 40), mProvider.getSource().getFrame());
- assertEquals(new Rect(0, 0, 500, 25), mProvider.getSource().getVisibleFrame());
- assertEquals(Insets.of(0, 40, 0, 0),
- mProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500),
- false /* ignoreVisibility */));
- assertEquals(Insets.of(0, 25, 0, 0),
- mProvider.getSource().calculateVisibleInsets(new Rect(0, 0, 500, 500)));
- }
-
- @Test
public void testPostLayout_invisible() {
final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
statusBar.getFrame().set(0, 0, 500, 100);