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

Commit 6648dded authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Fix broken locale related assumptions in TextServicesManager.

startsWith is a bogus check unless languages match. Also, don't
assume 2 letter languages.

bug: 10090157
Change-Id: I8adda61bddc465aac261c0ce2023fa9606affe1b
parent d811af22
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -89,6 +89,18 @@ public final class TextServicesManager {
        return sInstance;
    }

    /**
     * Returns the language component of a given locale string.
     */
    private static String parseLanguageFromLocaleString(String locale) {
        final int idx = locale.indexOf('_');
        if (idx < 0) {
            return locale;
        } else {
            return locale.substring(0, idx);
        }
    }

    /**
     * Get a spell checker session for the specified spell checker
     * @param locale the locale for the spell checker. If {@code locale} is null and
@@ -134,9 +146,8 @@ public final class TextServicesManager {
            }
            if (locale != null) {
                final String subtypeLocale = subtypeInUse.getLocale();
                final String inputLocale = locale.toString();
                if (subtypeLocale.length() < 2 || inputLocale.length() < 2
                        || !subtypeLocale.substring(0, 2).equals(inputLocale.substring(0, 2))) {
                final String subtypeLanguage = parseLanguageFromLocaleString(subtypeLocale);
                if (subtypeLanguage.length() < 2 || !locale.getLanguage().equals(subtypeLanguage)) {
                    return null;
                }
            }
@@ -145,11 +156,12 @@ public final class TextServicesManager {
            for (int i = 0; i < sci.getSubtypeCount(); ++i) {
                final SpellCheckerSubtype subtype = sci.getSubtypeAt(i);
                final String tempSubtypeLocale = subtype.getLocale();
                final String tempSubtypeLanguage = parseLanguageFromLocaleString(tempSubtypeLocale);
                if (tempSubtypeLocale.equals(localeStr)) {
                    subtypeInUse = subtype;
                    break;
                } else if (localeStr.length() >= 2 && tempSubtypeLocale.length() >= 2
                        && localeStr.startsWith(tempSubtypeLocale)) {
                } else if (tempSubtypeLanguage.length() >= 2 &&
                        locale.getLanguage().equals(tempSubtypeLanguage)) {
                    subtypeInUse = subtype;
                }
            }