diff options
2 files changed, 63 insertions, 38 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 39441281f670..0a918b25c6b8 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 @@ -45,7 +45,6 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.view.IInputMethodManager; import java.util.ArrayList; -import java.util.Objects; import java.util.concurrent.Executor; /** @@ -207,23 +206,21 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } protected void insetsChanged(InsetsState insetsState) { - mMainExecutor.execute(() -> { - if (mInsetsState.equals(insetsState)) { - return; - } + if (mInsetsState.equals(insetsState)) { + return; + } - mImeShowing = insetsState.getSourceOrDefaultVisibility(InsetsState.ITYPE_IME); + mImeShowing = insetsState.getSourceOrDefaultVisibility(InsetsState.ITYPE_IME); - final InsetsSource newSource = insetsState.getSource(InsetsState.ITYPE_IME); - final Rect newFrame = newSource.getFrame(); - final Rect oldFrame = mInsetsState.getSource(InsetsState.ITYPE_IME).getFrame(); + final InsetsSource newSource = insetsState.getSource(InsetsState.ITYPE_IME); + final Rect newFrame = newSource.getFrame(); + final Rect oldFrame = mInsetsState.getSource(InsetsState.ITYPE_IME).getFrame(); - mInsetsState.set(insetsState, true /* copySources */); - if (mImeShowing && !newFrame.equals(oldFrame) && newSource.isVisible()) { - if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation"); - startAnimation(mImeShowing, true /* forceRestart */); - } - }); + mInsetsState.set(insetsState, true /* copySources */); + if (mImeShowing && !newFrame.equals(oldFrame) && newSource.isVisible()) { + if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation"); + startAnimation(mImeShowing, true /* forceRestart */); + } } @VisibleForTesting @@ -236,27 +233,25 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged continue; } if (activeControl.getType() == InsetsState.ITYPE_IME) { - mMainExecutor.execute(() -> { - final Point lastSurfacePosition = mImeSourceControl != null - ? mImeSourceControl.getSurfacePosition() : null; - final boolean positionChanged = - !activeControl.getSurfacePosition().equals(lastSurfacePosition); - final boolean leashChanged = - !haveSameLeash(mImeSourceControl, activeControl); - mImeSourceControl = activeControl; - if (mAnimation != null) { - if (positionChanged) { - startAnimation(mImeShowing, true /* forceRestart */); - } - } else { - if (leashChanged) { - applyVisibilityToLeash(); - } - if (!mImeShowing) { - removeImeSurface(); - } + final Point lastSurfacePosition = mImeSourceControl != null + ? mImeSourceControl.getSurfacePosition() : null; + final boolean positionChanged = + !activeControl.getSurfacePosition().equals(lastSurfacePosition); + final boolean leashChanged = + !haveSameLeash(mImeSourceControl, activeControl); + mImeSourceControl = activeControl; + if (mAnimation != null) { + if (positionChanged) { + startAnimation(mImeShowing, true /* forceRestart */); + } + } else { + if (leashChanged) { + applyVisibilityToLeash(); + } + if (!mImeShowing) { + removeImeSurface(); } - }); + } } } } @@ -281,7 +276,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged return; } if (DEBUG) Slog.d(TAG, "Got showInsets for ime"); - mMainExecutor.execute(() -> startAnimation(true /* show */, false /* forceRestart */)); + startAnimation(true /* show */, false /* forceRestart */); } @@ -290,7 +285,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged return; } if (DEBUG) Slog.d(TAG, "Got hideInsets for ime"); - mMainExecutor.execute(() -> startAnimation(false /* show */, false /* forceRestart */)); + startAnimation(false /* show */, false /* forceRestart */); } public void topFocusedWindowChanged(String packageName) { 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 5e0d51809d44..a5e3f499ca0d 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 @@ -19,11 +19,13 @@ package com.android.wm.shell.common; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.InsetsState.ITYPE_IME; 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.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; @@ -40,18 +42,22 @@ import com.android.internal.view.IInputMethodManager; import org.junit.Before; import org.junit.Test; +import java.util.concurrent.Executor; + @SmallTest public class DisplayImeControllerTest { private SurfaceControl.Transaction mT; private DisplayImeController.PerDisplay mPerDisplay; private IInputMethodManager mMock; + private Executor mExecutor; @Before public void setUp() throws Exception { mT = mock(SurfaceControl.Transaction.class); mMock = mock(IInputMethodManager.class); - mPerDisplay = new DisplayImeController(null, null, Runnable::run, new TransactionPool() { + mExecutor = spy(Runnable::run); + mPerDisplay = new DisplayImeController(null, null, mExecutor, new TransactionPool() { @Override public SurfaceControl.Transaction acquire() { return mT; @@ -69,6 +75,30 @@ public class DisplayImeControllerTest { } @Test + public void insetsControlChanged_schedulesNoWorkOnExecutor() { + mPerDisplay.insetsControlChanged(insetsStateWithIme(false), insetsSourceControl()); + verifyZeroInteractions(mExecutor); + } + + @Test + public void insetsChanged_schedulesNoWorkOnExecutor() { + mPerDisplay.insetsChanged(insetsStateWithIme(false)); + verifyZeroInteractions(mExecutor); + } + + @Test + public void showInsets_schedulesNoWorkOnExecutor() { + mPerDisplay.showInsets(ime(), true); + verifyZeroInteractions(mExecutor); + } + + @Test + public void hideInsets_schedulesNoWorkOnExecutor() { + mPerDisplay.hideInsets(ime(), true); + verifyZeroInteractions(mExecutor); + } + + @Test public void reappliesVisibilityToChangedLeash() { verifyZeroInteractions(mT); mPerDisplay.mImeShowing = true; |