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

Commit 194faf5e authored by Yabin Huang's avatar Yabin Huang Committed by Android (Google) Code Review
Browse files

Merge "Update IMMI#switchKeyboardLayout() to take display ID and targetWindowToken" into main

parents e00163a2 ce8fbc06
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
@@ -808,7 +808,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);
@@ -929,6 +932,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

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

    final IPersistentVrStateCallbacks mPersistentVrModeListener =
            new IPersistentVrStateCallbacks.Stub() {
        @Override
@@ -3641,7 +3648,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;
                }
@@ -3910,7 +3917,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    + ", policyFlags=" + policyFlags);
        }

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

@@ -3968,7 +3975,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;
@@ -3981,7 +3988,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;
                    }
                }
@@ -4037,16 +4044,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);
        }
    }

@@ -4056,7 +4069,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
@@ -8552,6 +8552,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