From 7b7367684c757a0e2cf4584211a781163d726c0e Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Wed, 22 Mar 2023 16:59:56 +0900 Subject: [PATCH] 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 --- .../com/android/server/wm/DisplayPolicy.java | 1 - .../server/wm/InsetsSourceProvider.java | 2 -- .../com/android/server/wm/WindowState.java | 5 ++-- .../android/server/wm/DisplayPolicyTests.java | 23 ++++++++++--------- .../server/wm/InsetsSourceProviderTest.java | 19 --------------- 5 files changed, 15 insertions(+), 35 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index d31fe23bf2be3..6ed20257f829e 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 @@ public class DisplayPolicy { 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 3b23f97171753..3e03b9983a5db 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 @@ class InsetsSourceProvider { 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 680f6052f36ab..23934e00408a5 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 @@ class WindowState extends WindowContainer implements WindowManagerP 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 2914de115efff..c8fdee06f3e41 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 @@ public class DisplayPolicyTests extends WindowTestsBase { 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 b35eceb6dd11a..5e513f1a0d010 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsSourceProviderTest.java @@ -75,25 +75,6 @@ public class InsetsSourceProviderTest extends WindowTestsBase { mProvider.getSource().calculateVisibleInsets(new Rect(0, 0, 500, 500))); } - @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");