Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56436513 authored by Felix Stern's avatar Felix Stern
Browse files

Only apply an IME target change if it's the current controlTarget

Bug: 298172246
Flag: android.view.inputmethod.refactor_insets_controller
Test: atest ImeInsetsSourceProviderTest#testUpdateControlForTarget_differentControlTarget
Change-Id: I659378c9516a7270a07c095609d840af76f5e5f8
parent c77bf043
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
        if (Flags.refactorInsetsController()) {
            // TODO(b/353463205) investigate if we should fail the statsToken, or if it's only
            //  temporary null.
            if (target != null) {
            if (target != null && target == mControlTarget) {
                // If insets target is not available (e.g. RemoteInsetsControlTarget), use current
                // IME input target to update IME request state. For example, switch from a task
                // with showing IME to a split-screen task without showing IME.
@@ -334,6 +334,11 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
                } else {
                    invokeOnImeRequestedChangedListener(target, statsToken);
                }
            } else {
                ProtoLog.w(WM_DEBUG_IME,
                        "Not invoking onImeRequestedChangedListener, target=%s, current "
                                + "controlTarget=%s",
                        target, mControlTarget);
            }
        }
    }
+21 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -276,4 +278,23 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {
        assertTrue(mImeProvider.isServerVisible());
        assertTrue(mImeProvider.isSurfaceVisible());
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)
    public void testUpdateControlForTarget_differentControlTarget() throws RemoteException {
        final WindowState oldTarget = newWindowBuilder("app", TYPE_APPLICATION).build();
        final WindowState newTarget = newWindowBuilder("newapp", TYPE_APPLICATION).build();

        oldTarget.setRequestedVisibleTypes(
                WindowInsets.Type.defaultVisible() | WindowInsets.Type.ime());
        mDisplayContent.setImeControlTarget(oldTarget);
        mDisplayContent.setImeInputTarget(newTarget);

        // Having a null windowContainer will early return in updateControlForTarget
        mImeProvider.setWindowContainer(null, null, null);

        clearInvocations(mDisplayContent);
        mImeProvider.updateControlForTarget(newTarget, false /* force */, ImeTracker.Token.empty());
        verify(mDisplayContent, never()).getImeInputTarget();
    }
}