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

Commit 64166944 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Hide inputMethodClientHasFocus() from apps"

parents 805ba6fb cf93f9a5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ interface IWindowManager

    IWindowSession openSession(in IWindowSessionCallback callback, in IInputMethodClient client,
            in IInputContext inputContext);
    boolean inputMethodClientHasFocus(IInputMethodClient client);

    void getInitialDisplaySize(int displayId, out Point size);
    void getBaseDisplaySize(int displayId, out Point size);
+21 −32
Original line number Diff line number Diff line
@@ -2523,19 +2523,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            synchronized (mMethodMap) {
                if (mCurClient == null || client == null
                        || mCurClient.client.asBinder() != client.asBinder()) {
                    try {
                    // 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 (!mIWindowManager.inputMethodClientHasFocus(client)) {
                    if (!mWindowManagerInternal.inputMethodClientHasFocus(client)) {
                        Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
                        return false;
                    }
                    } catch (RemoteException e) {
                        return false;
                    }
                }

                if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
                return showCurrentInputLocked(flags, resultReceiver);
            }
@@ -2608,16 +2603,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            synchronized (mMethodMap) {
                if (mCurClient == null || client == null
                        || mCurClient.client.asBinder() != client.asBinder()) {
                    try {
                    // 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 (!mIWindowManager.inputMethodClientHasFocus(client)) {
                            if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
                                    + uid + ": " + client);
                            return false;
                    if (!mWindowManagerInternal.inputMethodClientHasFocus(client)) {
                        if (DEBUG) {
                            Slog.w(TAG, "Ignoring hideSoftInput of uid " + uid + ": " + client);
                        }
                    } catch (RemoteException e) {
                        return false;
                    }
                }
@@ -2732,8 +2724,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            + client.asBinder());
                }

                try {
                    if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
                if (!mWindowManagerInternal.inputMethodClientHasFocus(cs.client)) {
                    // 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
@@ -2745,8 +2736,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    }
                    return InputBindResult.NOT_IME_TARGET_WINDOW;
                }
                } catch (RemoteException e) {
                }

                if (!calledFromValidUser) {
                    Slog.w(TAG, "A background user is requesting window. Hiding IME.");
+6 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ 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;

@@ -441,4 +442,9 @@ public abstract class WindowManagerInternal {
     * Returns {@code true} if a Window owned by {@code uid} has focus.
     */
    public abstract boolean isUidFocused(int uid);

    /**
     * Returns {@code true} if a process that is identified by {@code client} has IME focus.
     */
    public abstract boolean inputMethodClientHasFocus(IInputMethodClient client);
}
+24 −24
Original line number Diff line number Diff line
@@ -5039,30 +5039,6 @@ public class WindowManagerService extends IWindowManager.Stub
        return session;
    }

    @Override
    public boolean inputMethodClientHasFocus(IInputMethodClient client) {
        synchronized (mWindowMap) {
            // TODO: multi-display
            if (getDefaultDisplayContentLocked().inputMethodClientHasFocus(client)) {
                return true;
            }

            // Okay, how about this...  what is the current focus?
            // It seems in some cases we may not have moved the IM
            // target window, such as when it was in a pop-up window,
            // so let's also look at the current focus.  (An example:
            // go to Gmail, start searching so the keyboard goes up,
            // 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()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void getInitialDisplaySize(int displayId, Point size) {
        synchronized (mWindowMap) {
@@ -7432,6 +7408,30 @@ public class WindowManagerService extends IWindowManager.Stub
                return mCurrentFocus != null ? uid == mCurrentFocus.getOwningUid() : false;
            }
        }

        @Override
        public boolean inputMethodClientHasFocus(IInputMethodClient client) {
            synchronized (mWindowMap) {
                // TODO: multi-display
                if (getDefaultDisplayContentLocked().inputMethodClientHasFocus(client)) {
                    return true;
                }

                // Okay, how about this...  what is the current focus?
                // It seems in some cases we may not have moved the IM
                // target window, such as when it was in a pop-up window,
                // so let's also look at the current focus.  (An example:
                // go to Gmail, start searching so the keyboard goes up,
                // 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()) {
                    return true;
                }
            }
            return false;
        }
    }

    void registerAppFreezeListener(AppFreezeListener listener) {