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

Commit 41f89c3b authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove the dependency on IInputMethodClient from IME focus check

This is a preparation to remove the dependency on IInputMethodClient
from WindowManagerService.

What inputMethodClientHasFocus(IInputMethodClient) is currently doing
is basically equivalent to comparing PID (and UID), because
InputMethodManager is a per-process instance and comparing two
IInputMethodClient Binder proxies is no more or less than comparing
PID (and UID pair).  We can just change its method signature to
achieve the same behavior by taking a PID/UID pair instead of taking
IInputMethodClient.

Note that we can later add display ID to this method to support
multi-display scenario.

This CL also renames inputMethodClientHasFocus() to
isInputMethodClientFocus() for better consistency with other methods.

There should be no observable behavior difference in this CL anyway.

Bug: 115993358
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Change-Id: I444077b1e4af4033f67ab72c181fac85b601e08a
parent 4d2f4462
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -139,8 +139,7 @@ public final class InputBindResult implements Parcelable {
         * The client should try to restart input when its {@link android.view.Window} is focused
         * again.</p>
         *
         * @see com.android.server.wm.WindowManagerInternal#inputMethodClientHasFocus(
         * IInputMethodClient)
         * @see com.android.server.wm.WindowManagerInternal#isInputMethodClientFocus(int, int)
         */
        int ERROR_NOT_IME_TARGET_WINDOW = 11;
        /**
+11 −3
Original line number Diff line number Diff line
@@ -2536,7 +2536,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    // We need to check if this is the current client with
                    // focus in the window manager, to allow this call to
                    // be made before input is started in it.
                    if (!mWindowManagerInternal.inputMethodClientHasFocus(client)) {
                    final ClientState cs = mClients.get(client.asBinder());
                    if (cs == null) {
                        throw new IllegalArgumentException("unknown client " + client.asBinder());
                    }
                    if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid)) {
                        Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
                        return false;
                    }
@@ -2616,7 +2620,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    // We need to check if this is the current client with
                    // focus in the window manager, to allow this call to
                    // be made before input is started in it.
                    if (!mWindowManagerInternal.inputMethodClientHasFocus(client)) {
                    final ClientState cs = mClients.get(client.asBinder());
                    if (cs == null) {
                        throw new IllegalArgumentException("unknown client " + client.asBinder());
                    }
                    if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid)) {
                        if (DEBUG) {
                            Slog.w(TAG, "Ignoring hideSoftInput of uid " + uid + ": " + client);
                        }
@@ -2734,7 +2742,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            + client.asBinder());
                }

                if (!mWindowManagerInternal.inputMethodClientHasFocus(cs.client)) {
                if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid)) {
                    // Check with the window manager to make sure this client actually
                    // has a window with focus.  If not, reject.  This is thread safe
                    // because if the focus changes some time before or after, the
+5 −10
Original line number Diff line number Diff line
@@ -150,7 +150,6 @@ import android.view.SurfaceSession;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ToBooleanFunction;
import com.android.internal.view.IInputMethodClient;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.wm.utils.RotationCache;
import com.android.server.wm.utils.WmDisplayCutout;
@@ -2946,7 +2945,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }
    }

    boolean inputMethodClientHasFocus(IInputMethodClient client) {
    boolean isInputMethodClientFocus(int uid, int pid) {
        final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
        if (imFocus == null) {
            return false;
@@ -2958,17 +2957,13 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
        }

        final IInputMethodClient imeClient = imFocus.mSession.mClient;

        if (DEBUG_INPUT_METHOD) {
            Slog.i(TAG_WM, "IM target client: " + imeClient);
            if (imeClient != null) {
                Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
                Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
            }
            Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
                    + "/" + imFocus.mSession.mPid);
            Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
        }

        return imeClient != null && imeClient.asBinder() == client.asBinder();
        return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
    }

    boolean hasSecureWindowOnScreen() {
+7 −3
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.view.InputChannel;
import android.view.MagnificationSpec;
import android.view.WindowInfo;

import com.android.internal.view.IInputMethodClient;
import com.android.server.input.InputManagerService;
import com.android.server.policy.WindowManagerPolicy;

@@ -444,9 +443,14 @@ public abstract class WindowManagerInternal {
    public abstract boolean isUidFocused(int uid);

    /**
     * Returns {@code true} if a process that is identified by {@code client} has IME focus.
     * Checks whether the specified process has IME focus or not.
     *
     * @param uid UID of the process to be queried
     * @param pid PID of the process to be queried
     * @return {@code true} if a process that is identified by {@code uid} and {@code pid} has IME
     *         focus
     */
    public abstract boolean inputMethodClientHasFocus(IInputMethodClient client);
    public abstract boolean isInputMethodClientFocus(int uid, int pid);

    /**
     * Return the display Id for given window.
+4 −4
Original line number Diff line number Diff line
@@ -7412,12 +7412,12 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        @Override
        public boolean inputMethodClientHasFocus(IInputMethodClient client) {
        public boolean isInputMethodClientFocus(int uid, int pid) {
            synchronized (mWindowMap) {
                // Check all displays if any input method window has focus.
                for (int i = mRoot.mChildren.size() - 1; i >= 0; --i) {
                    final DisplayContent displayContent = mRoot.mChildren.get(i);
                    if (displayContent.inputMethodClientHasFocus(client)) {
                    if (displayContent.isInputMethodClientFocus(uid, pid)) {
                        return true;
                    }
                }
@@ -7430,8 +7430,8 @@ public class WindowManagerService extends IWindowManager.Stub
                // press home.  Sometimes the IME won't go down.)
                // Would be nice to fix this more correctly, but it's
                // way at the end of a release, and this should be good enough.
                if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null
                        && mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
                if (mCurrentFocus != null && mCurrentFocus.mSession.mUid == uid
                        && mCurrentFocus.mSession.mPid == pid) {
                    return true;
                }
            }