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

Commit a6beec8e authored by Adrian Roos's avatar Adrian Roos
Browse files

Fix stuck IME when IME dialog is focused

Only the currently focused window will invoke startInput, and thus control the IME.

However, if the IME puts up a focusable dialog, and the requesting activity restarts,
its new window won't regain focus - because the IME dialog still has it. Thus, IMMS
never receives a startInput, and never tells WMS about a new mInputMethodInputTarget.

To address this, we clear mInputMethodInputTarget if it refers to a no longer existing
window, then the empty IME control target will take over, and hide the IME, which will
hide its dialog and let the newly launched WindowState obtain focus and ultimately
control of the IME.

Fixes: 160672060
Test: atest 'DisplayContentTests#testInputMethodInputTarget_isClearedWhenWindowStateIsRemoved'
Change-Id: I138ac7198013635e7fb620921305ed1eb224d4de
parent 7368ed7d
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -2170,6 +2170,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (isInputMethodTarget()) {
        if (isInputMethodTarget()) {
            dc.computeImeTarget(true /* updateImeTarget */);
            dc.computeImeTarget(true /* updateImeTarget */);
        }
        }
        if (dc.mInputMethodInputTarget == this) {
            dc.setInputMethodInputTarget(null);
        }
        if (dc.mInputMethodControlTarget == this) {
        if (dc.mInputMethodControlTarget == this) {
            dc.updateImeControlTarget();
            dc.updateImeControlTarget();
        }
        }
+15 −0
Original line number Original line Diff line number Diff line
@@ -889,6 +889,21 @@ public class DisplayContentTests extends WindowTestsBase {
        assertEquals(dc.getImeContainer().getParentSurfaceControl(), dc.computeImeParent());
        assertEquals(dc.getImeContainer().getParentSurfaceControl(), dc.computeImeParent());
    }
    }


    @Test
    public void testInputMethodInputTarget_isClearedWhenWindowStateIsRemoved() throws Exception {
        final DisplayContent dc = createNewDisplay();

        WindowState app = createWindow(null, TYPE_BASE_APPLICATION, dc, "app");

        dc.mInputMethodInputTarget = app;
        assertEquals(app, dc.computeImeControlTarget());

        app.removeImmediately();

        assertNull(dc.mInputMethodInputTarget);
        assertNull(dc.computeImeControlTarget());
    }

    @Test
    @Test
    public void testComputeImeControlTarget() throws Exception {
    public void testComputeImeControlTarget() throws Exception {
        final DisplayContent dc = createNewDisplay();
        final DisplayContent dc = createNewDisplay();