Merge "Remove double-posting in DisplayImeController" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3faaf538e9
@@ -47,7 +47,6 @@ import com.android.internal.inputmethod.ResultCallbacks;
|
||||
import com.android.internal.view.IInputMethodManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
@@ -209,23 +208,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
|
||||
@@ -238,27 +235,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +278,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 */);
|
||||
}
|
||||
|
||||
|
||||
@@ -292,7 +287,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) {
|
||||
|
||||
@@ -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;
|
||||
@@ -70,6 +76,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);
|
||||
|
||||
Reference in New Issue
Block a user