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

Commit 72fa1823 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Introduce IME subtype switching auto mode

Create a new RotationList inside InputMethodSubtypeSwitchingController,
enabling switching in either static or recency order and either forwards
or backwards direction. Also introduce a new auto mode for IME subtype
switching, which resolves to recency order for the first switch after a
user action (reset after each switch), and to static order otherwise.
This also handles switching using the hardware keyboard shortcut
to maintain consistency.

Flag: android.view.inputmethod.ime_switcher_revamp
Test: atest InputMethodSubtypeSwitchingControllerTest
Bug: 311791923
Change-Id: I71e3a0f4234f829ca6791cd575fda977bc3df13f
parent 3368b44b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.inputmethod.Flags;
import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodSession;
import android.window.WindowProviderService;
@@ -186,6 +187,10 @@ public abstract class AbstractInputMethodService extends WindowProviderService
            if (callback != null) {
                callback.finishedEvent(seq, handled);
            }
            if (Flags.imeSwitcherRevamp() && !handled && event.getAction() == KeyEvent.ACTION_DOWN
                    && event.getUnicodeChar() > 0 && mInputMethodServiceInternal != null) {
                mInputMethodServiceInternal.notifyUserActionIfNecessary();
            }
        }

        /**
+31 −6
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import static com.android.server.inputmethod.ImeVisibilityStateComputer.ImeTarge
import static com.android.server.inputmethod.ImeVisibilityStateComputer.ImeVisibilityResult;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME;
import static com.android.server.inputmethod.InputMethodBindingController.TIME_TO_RECONNECT;
import static com.android.server.inputmethod.InputMethodSubtypeSwitchingController.MODE_AUTO;
import static com.android.server.inputmethod.InputMethodUtils.isSoftInputModeStateVisibleAllowed;

import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -4138,7 +4139,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        final var currentImi = bindingController.getSelectedMethod();
        final ImeSubtypeListItem nextSubtype = getUserData(userId).mSwitchingController
                .getNextInputMethodLocked(onlyCurrentIme, currentImi,
                        bindingController.getCurrentSubtype());
                        bindingController.getCurrentSubtype(),
                        MODE_AUTO, true /* forward */);
        if (nextSubtype == null) {
            return false;
        }
@@ -4158,7 +4160,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final var currentImi = bindingController.getSelectedMethod();
            final ImeSubtypeListItem nextSubtype = getUserData(userId).mSwitchingController
                    .getNextInputMethodLocked(false /* onlyCurrentIme */, currentImi,
                            bindingController.getCurrentSubtype());
                            bindingController.getCurrentSubtype(),
                            MODE_AUTO, true /* forward */);
            return nextSubtype != null;
        }
    }
@@ -5459,6 +5462,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            // Set InputMethod here
            settings.putSelectedInputMethod(imi != null ? imi.getId() : "");
        }

        if (Flags.imeSwitcherRevamp()) {
            getUserData(userId).mSwitchingController.onInputMethodSubtypeChanged();
        }
    }

    @GuardedBy("ImfLock.class")
@@ -5579,11 +5586,29 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        if (currentImi == null) {
            return;
        }
        final var currentSubtype = bindingController.getCurrentSubtype();
        final InputMethodSubtypeHandle nextSubtypeHandle;
        if (Flags.imeSwitcherRevamp()) {
            final var nextItem = getUserData(userId).mSwitchingController
                    .getNextInputMethodForHardware(
                            false /* onlyCurrentIme */, currentImi, currentSubtype, MODE_AUTO,
                            direction > 0 /* forward */);
            if (nextItem == null) {
                Slog.i(TAG, "Hardware keyboard switching shortcut,"
                        + " next input method and subtype not found");
                return;
            }

            final var nextSubtype = nextItem.mSubtypeId > NOT_A_SUBTYPE_ID
                    ? nextItem.mImi.getSubtypeAt(nextItem.mSubtypeId) : null;
            nextSubtypeHandle = InputMethodSubtypeHandle.of(nextItem.mImi, nextSubtype);
        } else {
            final InputMethodSubtypeHandle currentSubtypeHandle =
                InputMethodSubtypeHandle.of(currentImi, bindingController.getCurrentSubtype());
        final InputMethodSubtypeHandle nextSubtypeHandle =
                    InputMethodSubtypeHandle.of(currentImi, currentSubtype);
            nextSubtypeHandle =
                    getUserData(userId).mHardwareKeyboardShortcutController.onSubtypeSwitch(
                        currentSubtypeHandle, direction > 0);
        }
        if (nextSubtypeHandle == null) {
            return;
        }
+380 −11

File changed.

Preview size limit exceeded, changes collapsed.

+662 −7

File changed.

Preview size limit exceeded, changes collapsed.