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

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

Move getLastInputMethodSubtype() logic to InputMethodSettings

This is a mechanical refactoring CL that moves the main logic of

 InputMethodManagerService#getLastInputMethodSubtype()

to

 InputMethodUtils.InputMethodSettings#getLastInputMethodSubtypeLocked()

without changing any developer observable behavior.

This is also a preparation to support

 InputMethodManager#getLastInputMethodSubtype()

for background users.

Bug: 234882948
Test: atest CtsInputMethodTestCases:InputMethodSubtypeTest
Change-Id: I39077b2ef170287af851e3d0e0bd51c6e668ca17
parent 0ac31bf6
Loading
Loading
Loading
Loading
+1 −17
Original line number Diff line number Diff line
@@ -4167,23 +4167,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            if (!calledFromValidUserLocked()) {
                return null;
            }
            final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
            // TODO: Handle the case of the last IME with no subtypes
            if (lastIme == null || TextUtils.isEmpty(lastIme.first)
                    || TextUtils.isEmpty(lastIme.second)) return null;
            final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
            if (lastImi == null) return null;
            try {
                final int lastSubtypeHash = Integer.parseInt(lastIme.second);
                final int lastSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(lastImi,
                        lastSubtypeHash);
                if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
                    return null;
                }
                return lastImi.getSubtypeAt(lastSubtypeId);
            } catch (NumberFormatException e) {
                return null;
            }
            return mSettings.getLastInputMethodSubtypeLocked();
        }
    }

+21 −0
Original line number Diff line number Diff line
@@ -592,6 +592,27 @@ final class InputMethodUtils {
            return getLastSubtypeForInputMethodLockedInternal(null);
        }

        @Nullable
        InputMethodSubtype getLastInputMethodSubtypeLocked() {
            final Pair<String, String> lastIme = getLastInputMethodAndSubtypeLocked();
            // TODO: Handle the case of the last IME with no subtypes
            if (lastIme == null || TextUtils.isEmpty(lastIme.first)
                    || TextUtils.isEmpty(lastIme.second)) return null;
            final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
            if (lastImi == null) return null;
            try {
                final int lastSubtypeHash = Integer.parseInt(lastIme.second);
                final int lastSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(lastImi,
                        lastSubtypeHash);
                if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
                    return null;
                }
                return lastImi.getSubtypeAt(lastSubtypeId);
            } catch (NumberFormatException e) {
                return null;
            }
        }

        String getLastSubtypeForInputMethodLocked(String imeId) {
            Pair<String, String> ime = getLastSubtypeForInputMethodLockedInternal(imeId);
            if (ime != null) {