diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 2d26c64248cfa..b4e1172f49aeb 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -642,7 +642,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation updateState(state); applyLocalVisibilityOverride(); - if (!mState.equals(lastState, true /* excludingCaptionInsets */, + if (!mState.equals(lastState, false /* excludingCaptionInsets */, true /* excludeInvisibleIme */)) { if (DEBUG) Log.d(TAG, "onStateChanged, notifyInsetsChanged"); mHost.notifyInsetsChanged(); @@ -672,16 +672,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation getSourceConsumer(type).updateSource(source, animationType); } for (@InternalInsetsType int type = 0; type < InsetsState.SIZE; type++) { + // Only update the server side insets here. + if (type == ITYPE_CAPTION_BAR) continue; InsetsSource source = mState.peekSource(type); if (source == null) continue; if (newState.peekSource(type) == null) { mState.removeSource(type); } } - if (mCaptionInsetsHeight != 0) { - mState.getSource(ITYPE_CAPTION_BAR).setFrame(new Rect(mFrame.left, mFrame.top, - mFrame.right, mFrame.top + mCaptionInsetsHeight)); - } updateDisabledUserAnimationTypes(disabledUserAnimationTypes); @@ -1488,7 +1486,16 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation @Override public void setCaptionInsetsHeight(int height) { - mCaptionInsetsHeight = height; + if (mCaptionInsetsHeight != height) { + mCaptionInsetsHeight = height; + if (mCaptionInsetsHeight != 0) { + mState.getSource(ITYPE_CAPTION_BAR).setFrame(new Rect(mFrame.left, mFrame.top, + mFrame.right, mFrame.top + mCaptionInsetsHeight)); + } else { + mState.removeSource(ITYPE_CAPTION_BAR); + } + mHost.notifyInsetsChanged(); + } } @Override diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java index 4512fbac38c1d..adebde016bb3f 100644 --- a/core/java/com/android/internal/policy/DecorView.java +++ b/core/java/com/android/internal/policy/DecorView.java @@ -2019,6 +2019,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind if (getForeground() != null) { drawableChanged(); } + notifyCaptionHeightChanged(); } } diff --git a/core/tests/coretests/src/android/view/InsetsControllerTest.java b/core/tests/coretests/src/android/view/InsetsControllerTest.java index af13cc07ced1c..2770ed820562c 100644 --- a/core/tests/coretests/src/android/view/InsetsControllerTest.java +++ b/core/tests/coretests/src/android/view/InsetsControllerTest.java @@ -45,6 +45,7 @@ import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -680,6 +681,19 @@ public class InsetsControllerTest { }); } + @Test + public void testNotifyCaptionInsetsOnlyChange() { + InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { + final InsetsState state = new InsetsState(mController.getState(), true); + reset(mTestHost); + mController.setCaptionInsetsHeight(100); + verify(mTestHost).notifyInsetsChanged(); + reset(mTestHost); + mController.setCaptionInsetsHeight(0); + verify(mTestHost).notifyInsetsChanged(); + }); + } + @Test public void testRequestedState() { InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {