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

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

Hide IME when the input target was covered by IME layering overlay

Bug: 258048231
Bug: 224195164
Bug: 252192121

Test: manual with issue steps
Test: atest ImeVisibilityStateComputerTest#\
         testOnApplyImeVisibilityFromComputer
Change-Id: Ia71b975898efb19439c3a1b1a9a2bdcf21b78650
parent 0938e22a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -259,6 +259,8 @@ public final class InputMethodDebug {
                return "SHOW_IME_SCREENSHOT_FROM_IMMS";
            case SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS:
                return "REMOVE_IME_SCREENSHOT_FROM_IMMS";
            case SoftInputShowHideReason.HIDE_WHEN_INPUT_TARGET_INVISIBLE:
                return "HIDE_WHEN_INPUT_TARGET_INVISIBLE";
            default:
                return "Unknown=" + reason;
        }
+7 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import java.lang.annotation.Retention;
        SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR,
        SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS,
        SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS,
        SoftInputShowHideReason.HIDE_WHEN_INPUT_TARGET_INVISIBLE,
})
public @interface SoftInputShowHideReason {
    /** Show soft input by {@link android.view.inputmethod.InputMethodManager#showSoftInput}. */
@@ -271,4 +272,10 @@ public @interface SoftInputShowHideReason {
     * Removes ime screenshot by {@link com.android.server.inputmethod.InputMethodManagerService}.
     */
    int REMOVE_IME_SCREENSHOT_FROM_IMMS = ImeProtoEnums.REASON_REMOVE_IME_SCREENSHOT_FROM_IMMS;

    /**
     * Hide soft input when the input target being removed or being obscured by an non-IME
     * focusable overlay window.
     */
    int HIDE_WHEN_INPUT_TARGET_INVISIBLE = ImeProtoEnums.REASON_HIDE_WHEN_INPUT_TARGET_INVISIBLE;
}
+13 −2
Original line number Diff line number Diff line
@@ -108,6 +108,12 @@ public final class ImeVisibilityStateComputer {
     */
    private boolean mRequestedImeScreenshot;

    /** The window token of the current visible IME layering target overlay. */
    private IBinder mCurVisibleImeLayeringOverlay;

    /** The window token of the current visible IME input target. */
    private IBinder mCurVisibleImeInputTarget;

    /** Represent the invalid IME visibility state */
    public static final int STATE_INVALID = -1;

@@ -190,13 +196,18 @@ public final class ImeVisibilityStateComputer {
            @Override
            public void onImeTargetOverlayVisibilityChanged(IBinder overlayWindowToken,
                    boolean visible, boolean removed) {
                // TODO(b/258048231): implement logic to fix IME layering overlay visibility issue.
                mCurVisibleImeLayeringOverlay = (visible && !removed) ? overlayWindowToken : null;
            }

            @Override
            public void onImeInputTargetVisibilityChanged(IBinder imeInputTarget,
                    boolean visibleRequested, boolean removed) {
                // TODO(b/258048231): implement logic to fix IME input target visibility issue.
                mCurVisibleImeInputTarget = (visibleRequested && !removed) ? imeInputTarget : null;
                if (mCurVisibleImeInputTarget == null && mCurVisibleImeLayeringOverlay != null) {
                    mService.onApplyImeVisibilityFromComputer(imeInputTarget,
                            new ImeVisibilityResult(STATE_HIDE_IME_EXPLICIT,
                                    SoftInputShowHideReason.HIDE_WHEN_INPUT_TARGET_INVISIBLE));
                }
            }
        });
    }
+8 −0
Original line number Diff line number Diff line
@@ -4813,6 +4813,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    void onApplyImeVisibilityFromComputer(IBinder windowToken,
            @NonNull ImeVisibilityResult result) {
        synchronized (ImfLock.class) {
            mVisibilityApplier.applyImeVisibility(windowToken, null, result.getState(),
                    result.getReason());
        }
    }

    @GuardedBy("ImfLock.class")
    void setEnabledSessionLocked(SessionState session) {
        if (mEnabledSession != session) {
+8 −0
Original line number Diff line number Diff line
@@ -3349,6 +3349,10 @@ public class WindowManagerService extends IWindowManager.Stub
    void dispatchImeTargetOverlayVisibilityChanged(@NonNull IBinder token, boolean visible,
            boolean removed) {
        if (mImeTargetChangeListener != null) {
            if (DEBUG_INPUT_METHOD) {
                Slog.d(TAG, "onImeTargetOverlayVisibilityChanged, win=" + mWindowMap.get(token)
                        + "visible=" + visible + ", removed=" + removed);
            }
            mH.post(() -> mImeTargetChangeListener.onImeTargetOverlayVisibilityChanged(token,
                    visible, removed));
        }
@@ -3357,6 +3361,10 @@ public class WindowManagerService extends IWindowManager.Stub
    void dispatchImeInputTargetVisibilityChanged(@NonNull IBinder token, boolean visible,
            boolean removed) {
        if (mImeTargetChangeListener != null) {
            if (DEBUG_INPUT_METHOD) {
                Slog.d(TAG, "onImeInputTargetVisibilityChanged, win=" + mWindowMap.get(token)
                        + "visible=" + visible + ", removed=" + removed);
            }
            mH.post(() -> mImeTargetChangeListener.onImeInputTargetVisibilityChanged(token,
                    visible, removed));
        }
Loading