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

Commit ca0fe022 authored by Michael Bestas's avatar Michael Bestas Committed by Michael W
Browse files

Revert "Remove dependency on IME subtype from TSMS"

Since the upgrade from Android 9 to 10 spell checking
has stopped working for any language other than English.
Reverting this commit makes the spell checker recognize
the currently active input language again.

Thanks to ClearlyClaire for figuring this out.
Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/1723
This reverts commit bb0a2247.

Change-Id: I3532f93d25d7ef30a3a070daaaf6d2209d4f2ec8
parent a5464e4c
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ import android.service.textservice.SpellCheckerService;
import android.text.TextUtils;
import android.util.Slog;
import android.util.SparseArray;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.InputMethodSystemProperty;
import android.view.textservice.SpellCheckerInfo;
import android.view.textservice.SpellCheckerSubtype;
@@ -573,19 +575,37 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {

        // subtypeHashCode == 0 means spell checker language settings is "auto"

        if (systemLocale == null) {
        Locale candidateLocale = null;
        final InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
        if (imm != null) {
            final InputMethodSubtype currentInputMethodSubtype =
                    imm.getCurrentInputMethodSubtype();
            if (currentInputMethodSubtype != null) {
                final String localeString = currentInputMethodSubtype.getLocale();
                if (!TextUtils.isEmpty(localeString)) {
                    // 1. Use keyboard locale if available in the spell checker
                    candidateLocale = SubtypeLocaleUtils.constructLocaleFromString(localeString);
                }
            }
        }
        if (candidateLocale == null) {
            // 2. Use System locale if available in the spell checker
            candidateLocale = systemLocale;
        }

        if (candidateLocale == null) {
            return null;
        }
        SpellCheckerSubtype firstLanguageMatchingSubtype = null;
        for (int i = 0; i < sci.getSubtypeCount(); ++i) {
            final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
            final Locale scsLocale = scs.getLocaleObject();
            if (Objects.equals(scsLocale, systemLocale)) {
            if (Objects.equals(scsLocale, candidateLocale)) {
                // Exact match wins.
                return scs;
            }
            if (firstLanguageMatchingSubtype == null && scsLocale != null
                    && TextUtils.equals(systemLocale.getLanguage(), scsLocale.getLanguage())) {
                    && TextUtils.equals(candidateLocale.getLanguage(), scsLocale.getLanguage())) {
                // Remember as a fall back candidate
                firstLanguageMatchingSubtype = scs;
            }