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

Commit 5d580797 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Consolidate clearing mImeInsetsFrozenUntilStartInput

As CL[1] that IMMS only invoke updateInputMethodTargetWindow when the
IME input target window changed, that caused somehow we can't clear
mImeInsetsFrozenUntilStartInput in ActivityRecord to make the activity
can receive IME insets correctly like when turning the screen off/on
and then unlocking the non-secure keyguard to back to the same app,
since the IME input target didn't changed.

Making sure IMMS side always invoke updateInputMethodTargetWindow to WM
to clear IME insets frozen state.

[1]: Id8a56c68a06a774ef12ba444fd9a368148ea4539

Fix: 205783849
Test: atest ActivityRecordTests#\
        testImeInsetsFrozenFlag_resetWhenReportedToBeImeInputTarget

Merged-In: I796754992911b917a49fcd18f22019c1eecad908
Change-Id: I796754992911b917a49fcd18f22019c1eecad908
parent 8e58b1cc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2837,7 +2837,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                return;
            }
            final IBinder targetWindow = mImeTargetWindowMap.get(startInputToken);
            if (targetWindow != null && mLastImeTargetWindow != targetWindow) {
            if (targetWindow != null) {
                mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow);
            }
            mLastImeTargetWindow = targetWindow;
+2 −0
Original line number Diff line number Diff line
@@ -1037,6 +1037,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                pw.print(" forceNewConfig="); pw.println(forceNewConfig);
        pw.print(prefix); pw.print("mActivityType=");
                pw.println(activityTypeToString(getActivityType()));
        pw.print(prefix); pw.print("mImeInsetsFrozenUntilStartInput=");
                pw.println(mImeInsetsFrozenUntilStartInput);
        if (requestedVrComponent != null) {
            pw.print(prefix);
            pw.print("requestedVrComponent=");
+3 −3
Original line number Diff line number Diff line
@@ -3969,11 +3969,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     * which controls the visibility and animation of the input method window.
     */
    void updateImeInputAndControlTarget(WindowState target) {
        if (mImeInputTarget != target) {
            ProtoLog.i(WM_DEBUG_IME, "setInputMethodInputTarget %s", target);
        if (target != null && target.mActivityRecord != null) {
            target.mActivityRecord.mImeInsetsFrozenUntilStartInput = false;
        }
        if (mImeInputTarget != target) {
            ProtoLog.i(WM_DEBUG_IME, "setInputMethodInputTarget %s", target);
            setImeInputTarget(target);
            updateImeControlTarget();
        }
+38 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.os.Process.NOBODY_UID;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
@@ -127,6 +128,8 @@ import android.view.IRemoteAnimationFinishedCallback;
import android.view.IRemoteAnimationRunner.Stub;
import android.view.IWindowManager;
import android.view.IWindowSession;
import android.view.InsetsSource;
import android.view.InsetsState;
import android.view.RemoteAnimationAdapter;
import android.view.RemoteAnimationTarget;
import android.view.Surface;
@@ -2884,6 +2887,41 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);
    }

    @UseTestDisplay(addWindows = W_INPUT_METHOD)
    @Test
    public void testImeInsetsFrozenFlag_resetWhenReportedToBeImeInputTarget() {
        final WindowState app = createWindow(null, TYPE_APPLICATION, "app");

        InsetsSource imeSource = new InsetsSource(ITYPE_IME);
        app.getInsetsState().addSource(imeSource);
        mDisplayContent.setImeLayeringTarget(app);
        mDisplayContent.updateImeInputAndControlTarget(app);

        InsetsState state = mDisplayContent.getInsetsPolicy().getInsetsForWindow(app);
        assertFalse(state.getSource(ITYPE_IME).isVisible());
        assertTrue(state.getSource(ITYPE_IME).getFrame().isEmpty());

        // Simulate app is closing and expect IME insets is frozen.
        mDisplayContent.mOpeningApps.clear();
        app.mActivityRecord.commitVisibility(false, false);
        app.mActivityRecord.onWindowsGone();
        assertTrue(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);

        // Simulate app re-start input or turning screen off/on then unlocked by un-secure
        // keyguard to back to the app, expect IME insets is not frozen
        imeSource.setFrame(new Rect(100, 400, 500, 500));
        app.getInsetsState().addSource(imeSource);
        app.getInsetsState().setSourceVisible(ITYPE_IME, true);
        mDisplayContent.updateImeInputAndControlTarget(app);
        assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);

        // Verify when IME is visible and the app can receive the right IME insets from policy.
        makeWindowVisibleAndDrawn(app, mImeWindow);
        state = mDisplayContent.getInsetsPolicy().getInsetsForWindow(app);
        assertTrue(state.getSource(ITYPE_IME).isVisible());
        assertEquals(state.getSource(ITYPE_IME).getFrame(), imeSource.getFrame());
    }

    private void assertHasStartingWindow(ActivityRecord atoken) {
        assertNotNull(atoken.mStartingSurface);
        assertNotNull(atoken.mStartingData);