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

Commit ce8fbc06 authored by Yabin Huang's avatar Yabin Huang
Browse files

Update IMMI#switchKeyboardLayout() to take display ID and targetWindowToken

To support multi-session IME, IMMI needs to know the window to which
the keyboard layout switch is dispatched, and the target window token.

This CL just passes unused parameters to IMMS. It doesn't change
the behavior of the code, thus no flag is required. The passed
parameters will be used by another CL to implement the multi-session
IME, and that CL will be protected by the concurrent_input_methods
feature flag.

Bug: 305829876
Test: atest WmTests && atest FrameworksServicesTests
Change-Id: Ie15b29247304e027dfef58ef683e5139f2ee4d35
parent 029cac40
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -217,8 +217,18 @@ public abstract class InputMethodManagerInternal {
     *
     * @param direction         {@code 1} to switch to the next subtype, {@code -1} to switch to the
     *                          previous subtype
     * @param displayId         the display to which the keyboard layout switch shortcut is
     *                          dispatched. Note that there is no guarantee that an IME is
     *                          associated with this display. This is more or less than a hint for
     *                          cases when no IME is running for the given targetWindowToken. There
     *                          is a longstanding discussion whether we should allow users to
     *                          rotate keyboard layout even when there is no edit field, and this
     *                          displayID would be helpful for such a situation.
     * @param targetWindowToken the window token to which other keys are being sent while handling
     *                          this shortcut.
     */
    public abstract void switchKeyboardLayout(int direction);
    public abstract void onSwitchKeyboardLayoutShortcut(int direction, int displayId,
            IBinder targetWindowToken);

    /**
     * Returns true if any InputConnection is currently active.
@@ -314,7 +324,8 @@ public abstract class InputMethodManagerInternal {
                }

                @Override
                public void switchKeyboardLayout(int direction) {
                public void onSwitchKeyboardLayoutShortcut(int direction, int displayId,
                        IBinder targetWindowToken) {
                }

                @Override
+2 −1
Original line number Diff line number Diff line
@@ -5763,7 +5763,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        }

        @Override
        public void switchKeyboardLayout(int direction) {
        public void onSwitchKeyboardLayoutShortcut(int direction, int displayId,
                IBinder targetWindowToken) {
            synchronized (ImfLock.class) {
                switchKeyboardLayoutLocked(direction);
            }
+25 −12
Original line number Diff line number Diff line
@@ -813,7 +813,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    handleScreenShot(msg.arg1);
                    break;
                case MSG_SWITCH_KEYBOARD_LAYOUT:
                    handleSwitchKeyboardLayout(msg.arg1, msg.arg2);
                    SwitchKeyboardLayoutMessageObject object =
                            (SwitchKeyboardLayoutMessageObject) msg.obj;
                    handleSwitchKeyboardLayout(object.keyEvent, object.direction,
                            object.focusedToken);
                    break;
                case MSG_LOG_KEYBOARD_SYSTEM_EVENT:
                    handleKeyboardSystemEvent(KeyboardLogEvent.from(msg.arg1), (KeyEvent) msg.obj);
@@ -934,6 +937,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private record SwitchKeyboardLayoutMessageObject(KeyEvent keyEvent, IBinder focusedToken,
                                                     int direction) {
    }

    final IPersistentVrStateCallbacks mPersistentVrModeListener =
            new IPersistentVrStateCallbacks.Stub() {
        @Override
@@ -3709,7 +3716,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_LANGUAGE_SWITCH:
                if (firstDown) {
                    int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
                    sendSwitchKeyboardLayout(event, direction);
                    sendSwitchKeyboardLayout(event, focusedToken, direction);
                    logKeyboardSystemsEvent(event, KeyboardLogEvent.LANGUAGE_SWITCH);
                    return true;
                }
@@ -3978,7 +3985,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    + ", policyFlags=" + policyFlags);
        }

        if (interceptUnhandledKey(event)) {
        if (interceptUnhandledKey(event, focusedToken)) {
            return null;
        }

@@ -4036,7 +4043,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return fallbackEvent;
    }

    private boolean interceptUnhandledKey(KeyEvent event) {
    private boolean interceptUnhandledKey(KeyEvent event, IBinder focusedToken) {
        final int keyCode = event.getKeyCode();
        final int repeatCount = event.getRepeatCount();
        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
@@ -4049,7 +4056,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    if (KeyEvent.metaStateHasModifiers(metaState & ~KeyEvent.META_SHIFT_MASK,
                            KeyEvent.META_CTRL_ON)) {
                        int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
                        sendSwitchKeyboardLayout(event, direction);
                        sendSwitchKeyboardLayout(event, focusedToken, direction);
                        return true;
                    }
                }
@@ -4105,16 +4112,22 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private void sendSwitchKeyboardLayout(@NonNull KeyEvent event, int direction) {
        mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, event.getDeviceId(),
                direction).sendToTarget();
    private void sendSwitchKeyboardLayout(@NonNull KeyEvent event,
            @Nullable IBinder focusedToken, int direction) {
        SwitchKeyboardLayoutMessageObject object =
                new SwitchKeyboardLayoutMessageObject(event, focusedToken, direction);
        mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, object).sendToTarget();
    }

    private void handleSwitchKeyboardLayout(int deviceId, int direction) {
    private void handleSwitchKeyboardLayout(@NonNull KeyEvent event, int direction,
            IBinder focusedToken) {
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI)) {
            InputMethodManagerInternal.get().switchKeyboardLayout(direction);
            IBinder targetWindowToken =
                    mWindowManagerInternal.getTargetWindowTokenFromInputToken(focusedToken);
            InputMethodManagerInternal.get().onSwitchKeyboardLayoutShortcut(direction,
                    event.getDisplayId(), targetWindowToken);
        } else {
            mWindowManagerFuncs.switchKeyboardLayout(deviceId, direction);
            mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
        }
    }

@@ -4124,7 +4137,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if ((actions & ACTION_PASS_TO_USER) != 0) {
            long delayMillis = interceptKeyBeforeDispatching(
                    focusedToken, fallbackEvent, policyFlags);
            if (delayMillis == 0 && !interceptUnhandledKey(fallbackEvent)) {
            if (delayMillis == 0 && !interceptUnhandledKey(fallbackEvent, focusedToken)) {
                return true;
            }
        }
+5 −0
Original line number Diff line number Diff line
@@ -866,6 +866,11 @@ public abstract class WindowManagerInternal {
    public abstract ImeTargetInfo onToggleImeRequested(boolean show,
            @NonNull IBinder focusedToken, @NonNull IBinder requestToken, int displayId);

    /**
     * Returns the token to identify the target window that the IME is associated with.
     */
    public abstract @Nullable IBinder getTargetWindowTokenFromInputToken(IBinder inputToken);

    /** The information of input method target when IME is requested to show or hide. */
    public static class ImeTargetInfo {
        public final String focusedWindowName;
+6 −0
Original line number Diff line number Diff line
@@ -8532,6 +8532,12 @@ public class WindowManagerService extends IWindowManager.Stub
                        fromOrientations, toOrientations);
            }
        }

        @Override
        public @Nullable IBinder getTargetWindowTokenFromInputToken(IBinder inputToken) {
            InputTarget inputTarget = WindowManagerService.this.getInputTargetFromToken(inputToken);
            return inputTarget == null ? null : inputTarget.getWindowToken();
        }
    }

    private final class ImeTargetVisibilityPolicyImpl extends ImeTargetVisibilityPolicy {
Loading