diff options
2 files changed, 23 insertions, 11 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java index 266cf294a950..7f7af935ff2b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java @@ -274,29 +274,30 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } if (hasImeSourceControl) { - final Point lastSurfacePosition = mImeSourceControl != null - ? mImeSourceControl.getSurfacePosition() : null; - final boolean positionChanged = - !imeSourceControl.getSurfacePosition().equals(lastSurfacePosition); - final boolean leashChanged = - !haveSameLeash(mImeSourceControl, imeSourceControl); if (mAnimation != null) { + final Point lastSurfacePosition = hadImeSourceControl + ? mImeSourceControl.getSurfacePosition() : null; + final boolean positionChanged = + !imeSourceControl.getSurfacePosition().equals(lastSurfacePosition); if (positionChanged) { startAnimation(mImeShowing, true /* forceRestart */); } } else { - if (leashChanged) { + if (!haveSameLeash(mImeSourceControl, imeSourceControl)) { applyVisibilityToLeash(imeSourceControl); } if (!mImeShowing) { removeImeSurface(); } - if (mImeSourceControl != null) { - mImeSourceControl.release(SurfaceControl::release); - } } - mImeSourceControl = imeSourceControl; + } else if (mAnimation != null) { + mAnimation.cancel(); + } + + if (hadImeSourceControl && mImeSourceControl != imeSourceControl) { + mImeSourceControl.release(SurfaceControl::release); } + mImeSourceControl = imeSourceControl; } private void applyVisibilityToLeash(InsetsSourceControl imeSourceControl) { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java index 9967e5f47752..262ee72d86fc 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java @@ -22,6 +22,8 @@ import static android.view.Surface.ROTATION_0; import static android.view.WindowInsets.Type.ime; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -131,6 +133,15 @@ public class DisplayImeControllerTest extends ShellTestCase { verify(mT).show(any()); } + @Test + public void insetsControlChanged_updateImeSourceControl() { + mPerDisplay.insetsControlChanged(insetsStateWithIme(false), insetsSourceControl()); + assertNotNull(mPerDisplay.mImeSourceControl); + + mPerDisplay.insetsControlChanged(new InsetsState(), new InsetsSourceControl[]{}); + assertNull(mPerDisplay.mImeSourceControl); + } + private InsetsSourceControl[] insetsSourceControl() { return new InsetsSourceControl[]{ new InsetsSourceControl( |