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

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

Rewrite a fake language code "tl" in SpellChecker.

With following CLs, we already have a special rewrite rule of "tl" to
"fil" for IMEs that are targeting older versions of Android earlier than
Lollipop that did not support three letter language codes and used
"tl" (Tagalog) as the language string for "fil" (Filipino).
  - 92280cd3 [1]
  - ed65bc0c [2]

  [1]: I94f203bddceb9c87710cb187cc3cc0ee6d9092a5
  [2]: Ica9cd2baac002c406f92331aadd7725d7424046a

With this CL, we have the same rewrite rule for spell checker services.

Bug: 20696126
Change-Id: I0af0f520a15337e33973391c9965364e3ae1ee4c
parent 658c29e8
Loading
Loading
Loading
Loading
+4 −19
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view.textservice;

import com.android.internal.inputmethod.InputMethodUtils;

import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -156,24 +158,7 @@ public final class SpellCheckerSubtype implements Parcelable {
     */
    @Nullable
    public Locale getLocaleObject() {
        // TODO: Use InputMethodUtils.constructLocaleFromString() instead.
        return constructLocaleFromString(mSubtypeLocale);
    }

    private static Locale constructLocaleFromString(String localeStr) {
        if (TextUtils.isEmpty(localeStr))
            return null;
        String[] localeParams = localeStr.split("_", 3);
        // The length of localeStr is guaranteed to always return a 1 <= value <= 3
        // because localeStr is not empty.
        if (localeParams.length == 1) {
            return new Locale(localeParams[0]);
        } else if (localeParams.length == 2) {
            return new Locale(localeParams[0], localeParams[1]);
        } else if (localeParams.length == 3) {
            return new Locale(localeParams[0], localeParams[1], localeParams[2]);
        }
        return null;
        return InputMethodUtils.constructLocaleFromString(mSubtypeLocale);
    }

    /**
@@ -188,7 +173,7 @@ public final class SpellCheckerSubtype implements Parcelable {
     */
    public CharSequence getDisplayName(
            Context context, String packageName, ApplicationInfo appInfo) {
        final Locale locale = constructLocaleFromString(mSubtypeLocale);
        final Locale locale = getLocaleObject();
        final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale;
        if (mSubtypeNameResId == 0) {
            return localeStr;
+6 −5
Original line number Diff line number Diff line
@@ -89,13 +89,14 @@ public class SpellCheckerSubtypeTest extends InstrumentationTestCase {
        assertEquals(new Locale("en", "US", "POSIX"), new SpellCheckerSubtype(
                SUBTYPE_NAME_RES_ID_A, "en_US_POSIX", SUBTYPE_EXTRA_VALUE_A).getLocaleObject());

        // Special rewrite rule for "tl" was not yet supported in spell checker.
        // TODO: Match the behavior to InputMethodSubtype.
        assertEquals(new Locale("tl"), new SpellCheckerSubtype(
        // Special rewrite rule for "tl" for versions of Android earlier than Lollipop that did not
        // support three letter language codes, and used "tl" (Tagalog) as the language string for
        // "fil" (Filipino).
        assertEquals(new Locale("fil"), new SpellCheckerSubtype(
                SUBTYPE_NAME_RES_ID_A, "tl", SUBTYPE_EXTRA_VALUE_A).getLocaleObject());
        assertEquals(new Locale("tl", "PH"), new SpellCheckerSubtype(
        assertEquals(new Locale("fil", "PH"), new SpellCheckerSubtype(
                SUBTYPE_NAME_RES_ID_A, "tl_PH", SUBTYPE_EXTRA_VALUE_A).getLocaleObject());
        assertEquals(new Locale("tl", "PH", "POSIX"), new SpellCheckerSubtype(
        assertEquals(new Locale("fil", "PH", "POSIX"), new SpellCheckerSubtype(
                SUBTYPE_NAME_RES_ID_A, "tl_PH_POSIX", SUBTYPE_EXTRA_VALUE_A).getLocaleObject());

        // So far rejecting invalid/unexpected locale strings is out of the scope.