Merge "Fix IME insets animation stucked by wrong InsetsHint" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-12 18:37:24 +00:00
committed by Android (Google) Code Review
2 changed files with 34 additions and 2 deletions

View File

@@ -82,6 +82,7 @@ abstract class InsetsSourceProvider {
private boolean mIsLeashReadyForDispatching;
private final Rect mSourceFrame = new Rect();
private final Rect mLastSourceFrame = new Rect();
private @NonNull Insets mInsetsHint = Insets.NONE;
private final Consumer<Transaction> mSetLeashPositionConsumer = t -> {
if (mControl != null) {
@@ -298,6 +299,7 @@ abstract class InsetsSourceProvider {
if (!insetsHint.equals(mControl.getInsetsHint())) {
changed = true;
mControl.setInsetsHint(insetsHint);
mInsetsHint = insetsHint;
}
mLastSourceFrame.set(mSource.getFrame());
}
@@ -433,8 +435,8 @@ abstract class InsetsSourceProvider {
final SurfaceControl leash = mAdapter.mCapturedLeash;
mControlTarget = target;
updateVisibility();
mControl = new InsetsSourceControl(mSource.getType(), leash, surfacePosition,
mSource.calculateInsets(mWindowContainer.getBounds(), true /* ignoreVisibility */));
mControl = new InsetsSourceControl(mSource.getType(), leash, surfacePosition, mInsetsHint);
ProtoLog.d(WM_DEBUG_WINDOW_INSETS,
"InsetsSource Control %s for target %s", mControl, mControlTarget);
}

View File

@@ -449,6 +449,36 @@ public class InsetsStateControllerTest extends WindowTestsBase {
assertNotNull(app.getInsetsState().peekSource(ITYPE_NAVIGATION_BAR));
}
@UseTestDisplay(addWindows = W_INPUT_METHOD)
@Test
public void testGetInsetsHintForNewControl() {
final WindowState app1 = createTestWindow("app1");
final WindowState app2 = createTestWindow("app2");
makeWindowVisible(mImeWindow);
final InsetsSourceProvider imeInsetsProvider = getController().getSourceProvider(ITYPE_IME);
imeInsetsProvider.setWindowContainer(mImeWindow, null, null);
imeInsetsProvider.updateSourceFrame(mImeWindow.getFrame());
imeInsetsProvider.updateControlForTarget(app1, false);
imeInsetsProvider.onPostLayout();
final InsetsSourceControl control1 = imeInsetsProvider.getControl(app1);
assertNotNull(control1);
assertEquals(imeInsetsProvider.getSource().getFrame().height(),
control1.getInsetsHint().bottom);
// Simulate the IME control target updated from app1 to app2 when IME insets was invisible.
imeInsetsProvider.setServerVisible(false);
imeInsetsProvider.updateControlForTarget(app2, false);
// Verify insetsHint of the new control is same as last IME source frame after the layout.
imeInsetsProvider.onPostLayout();
final InsetsSourceControl control2 = imeInsetsProvider.getControl(app2);
assertNotNull(control2);
assertEquals(imeInsetsProvider.getSource().getFrame().height(),
control2.getInsetsHint().bottom);
}
private WindowState createTestWindow(String name) {
final WindowState win = createWindow(null, TYPE_APPLICATION, name);
win.setHasSurface(true);