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

Commit dc394bdd authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Fix an edge case in IMS#switchInputMethod()

This CL fixes a long-standing edge case when

  InputMethodService#switchInputMethod(String, InputMethodSubtype)

stops working when it should work.

In short, IMMS#mCurrentSubtype can be null even when the IME has
enabled and existing subtype. IMMS#setInputMethodLocked() should just
go ahead to handle the request rather than bailing out.

Fix: 231444489
Fix: 291762796
Test: atest CtsInputMethodTestCases:InputMethodSubtypeEndToEndTest
Change-Id: I5402f1b01da940a87a645721686270aca609b933
(cherry picked from commit da56eb5c)
parent c7bce336
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -3377,15 +3377,18 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            } else {
                // If subtype is null, try to find the most applicable one from
                // getCurrentInputMethodSubtype.
                subtypeId = NOT_A_SUBTYPE_ID;
                newSubtype = getCurrentInputMethodSubtypeLocked();
                if (newSubtype != null) {
                    for (int i = 0; i < subtypeCount; ++i) {
                        if (Objects.equals(newSubtype, info.getSubtypeAt(i))) {
                            subtypeId = i;
                            break;
                        }
                    }
                }
            if (newSubtype == null || oldSubtype == null) {
                Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype
                        + ", new subtype = " + newSubtype);
                notifyInputMethodSubtypeChangedLocked(userId, info, null);
                return;
            }
            if (!newSubtype.equals(oldSubtype)) {
            if (!Objects.equals(newSubtype, oldSubtype)) {
                setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
                IInputMethodInvoker curMethod = getCurMethodLocked();
                if (curMethod != null) {