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

Commit f1e0887e authored by Taran Singh's avatar Taran Singh
Browse files

Ime target window should control when to hide IME (1/2)

Input method frameworks uses focused window and some tricks
to best guestimate IME target. Though it doesn't always know the
actual IME target. e.g. when window has both NOT_FOCUSABLE,
ALT_FOCUSABLE_IM; IMF thinks focued window is IME target but it isn't
the case.

The right thing to do is to call both show(IME), hide(IME) on IME
target.

Bug: 142461756
Bug: 111084606
Test: Manually tested using steps below:
  1. Make sure new insets flag is enabled
  2. Launch any activity which has child window with NOT_FOCUSABLE,
     ALT_FOCUSABLE_IM (e.g. Instagram login screen)
  3. Verify IME can be shown and hidden by this window.

Change-Id: I13f3e04f6f9e1574db9cbb56bdb7817152499d03
parent fd0e5865
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -81,6 +81,14 @@ oneway interface IWindow {
     */
    void showInsets(int types, boolean fromIme);

    /**
     * Called when a set of insets source window should be hidden by policy.
     *
     * @param types internal inset types (WindowInsets.Type.InsetType) to hide
     * @param fromIme true if this request originated from IME (InputMethodService).
     */
    void hideInsets(int types, boolean fromIme);

    void moved(int newX, int newY);
    void dispatchAppVisibility(boolean visible);
    void dispatchGetNewSurface();
+19 −0
Original line number Diff line number Diff line
@@ -4530,6 +4530,7 @@ public final class ViewRootImpl implements ViewParent,
    private static final int MSG_SYSTEM_GESTURE_EXCLUSION_CHANGED = 32;
    private static final int MSG_LOCATION_IN_PARENT_DISPLAY_CHANGED = 33;
    private static final int MSG_SHOW_INSETS = 34;
    private static final int MSG_HIDE_INSETS = 35;


    final class ViewRootHandler extends Handler {
@@ -4596,6 +4597,8 @@ public final class ViewRootImpl implements ViewParent,
                    return "MSG_LOCATION_IN_PARENT_DISPLAY_CHANGED";
                case MSG_SHOW_INSETS:
                    return "MSG_SHOW_INSETS";
                case MSG_HIDE_INSETS:
                    return "MSG_HIDE_INSETS";
            }
            return super.getMessageName(message);
        }
@@ -4714,6 +4717,10 @@ public final class ViewRootImpl implements ViewParent,
                    mInsetsController.show(msg.arg1, msg.arg2 == 1);
                    break;
                }
                case MSG_HIDE_INSETS: {
                    mInsetsController.hide(msg.arg1, msg.arg2 == 1);
                    break;
                }
                case MSG_WINDOW_MOVED:
                    if (mAdded) {
                        final int w = mWinFrame.width();
@@ -7513,6 +7520,10 @@ public final class ViewRootImpl implements ViewParent,
        mHandler.obtainMessage(MSG_SHOW_INSETS, types, fromIme ? 1 : 0).sendToTarget();
    }

    private void hideInsets(@InsetType int types, boolean fromIme) {
        mHandler.obtainMessage(MSG_HIDE_INSETS, types, fromIme ? 1 : 0).sendToTarget();
    }

    public void dispatchMoved(int newX, int newY) {
        if (DEBUG_LAYOUT) Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY);
        if (mTranslator != null) {
@@ -8635,6 +8646,14 @@ public final class ViewRootImpl implements ViewParent,
            }
        }

        @Override
        public void hideInsets(@InsetType int types, boolean fromIme) {
            final ViewRootImpl viewAncestor = mViewAncestor.get();
            if (viewAncestor != null) {
                viewAncestor.hideInsets(types, fromIme);
            }
        }

        @Override
        public void moved(int newX, int newY) {
            final ViewRootImpl viewAncestor = mViewAncestor.get();
+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ public class BaseIWindow extends IWindow.Stub {
    public void showInsets(@InsetType int types, boolean fromIme)  throws RemoteException {
    }

    @Override
    public void hideInsets(@InsetType int types, boolean fromIme)  throws RemoteException {
    }

    @Override
    public void moved(int newX, int newY) {
    }
+9 −0
Original line number Diff line number Diff line
@@ -33,4 +33,13 @@ interface InsetsControlTarget {
     */
    default void showInsets(@InsetType int types, boolean fromIme) {
    }

    /**
     * Instructs the control target to hide inset sources.
     *
     * @param types to specify which types of insets source window should be hidden.
     * @param fromIme {@code true} if IME hide request originated from {@link InputMethodService}.
     */
    default void hideInsets(@InsetType int types, boolean fromIme) {
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -3375,6 +3375,15 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }
    }

    @Override
    public void hideInsets(@InsetType int types, boolean fromIme) {
        try {
            mClient.hideInsets(types, fromIme);
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed to deliver showInsets", e);
        }
    }

    Rect getBackdropFrame(Rect frame) {
        // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
        // start even if we haven't received the relayout window, so that the client requests
Loading