Remove double-posting in DisplayImeController

Now that the PerDisplay methods already run on the mMainExecutor,
we no longer need to post to that executor from PerDisplay's methods.

Fixes: 175954493
Test: atest DisplayImeController
Change-Id: Ib528b899b7f47f5c4afe3e31925bfb8d8abb8aef
This commit is contained in:
Adrian Roos
2021-01-27 14:08:12 +01:00
parent c8d8b7cd9c
commit a30d9a0d74
2 changed files with 63 additions and 38 deletions

View File

@@ -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) {

View File

@@ -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;
@@ -68,6 +74,30 @@ public class DisplayImeControllerTest {
}.new PerDisplay(DEFAULT_DISPLAY, ROTATION_0);
}
@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);