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

Commit 6aa03788 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove deprecated hidden public methods from InputMethodUtils.

This is a follow up CL for a recent attempt to minimize
the number of default enabled IMEs.
- part1: I831502db502f4073c9c2f50ce7705a4e45e2e1e3
- part2: Ife93d909fb8a24471c425c903e2b7048826e17a3
- part3: I6571d464a46453934f0a8f5e79018a67a9a3c845
- part4: I871ccda787eb0f1099ba3574356c1da4b33681f3

This CL removes following deprecated hidden public methods
from InputMethodUtils as planned.
- isSystemImeThatHasEnglishKeyboardSubtype(InputMethodInfo)
- isValidSystemDefaultIme(boolean, InputMethodInfo, Context)
- containsSubtypeOf(InputMethodInfo, String, String)

This is a pure code refactoring with preserving the current
logic. Hence no behavior change is intended.

Change-Id: I1ff994cbbdef83e1e907a0d88aa9ae09d45263b4
parent bb41a5f6
Loading
Loading
Loading
Loading
+7 −64
Original line number Diff line number Diff line
@@ -120,18 +120,6 @@ public class InputMethodUtils {
                & ApplicationInfo.FLAG_SYSTEM) != 0;
    }

    /**
     * @deprecated Use {@link #isSystemImeThatHasSubtypeOf(InputMethodInfo, Context, boolean,
     * Locale, boolean, String)} instead.
     */
    @Deprecated
    public static boolean isSystemImeThatHasEnglishKeyboardSubtype(InputMethodInfo imi) {
        if (!isSystemIme(imi)) {
            return false;
        }
        return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(), SUBTYPE_MODE_KEYBOARD);
    }

    public static boolean isSystemImeThatHasSubtypeOf(final InputMethodInfo imi,
            final Context context, final boolean checkDefaultAttribute,
            @Nullable final Locale requiredLocale, final boolean checkCountry,
@@ -382,35 +370,6 @@ public class InputMethodUtils {
                .build();
    }

    /**
     * @deprecated Use {@link #isSystemImeThatHasSubtypeOf(InputMethodInfo, Context, boolean,
     * Locale, boolean, String)} instead.
     */
    @Deprecated
    public static boolean isValidSystemDefaultIme(
            boolean isSystemReady, InputMethodInfo imi, Context context) {
        if (!isSystemReady) {
            return false;
        }
        if (!isSystemIme(imi)) {
            return false;
        }
        if (imi.getIsDefaultResourceId() != 0) {
            try {
                if (imi.isDefault(context) && containsSubtypeOf(
                        imi, context.getResources().getConfiguration().locale.getLanguage(),
                        SUBTYPE_MODE_ANY)) {
                    return true;
                }
            } catch (Resources.NotFoundException ex) {
            }
        }
        if (imi.getSubtypeCount() == 0) {
            Slog.w(TAG, "Found no subtypes in a system IME: " + imi.getPackageName());
        }
        return false;
    }

    public static Locale constructLocaleFromString(String localeStr) {
        if (TextUtils.isEmpty(localeStr)) {
            return null;
@@ -459,25 +418,6 @@ public class InputMethodUtils {
        return false;
    }

    /**
     * @deprecated Use {@link #containsSubtypeOf(InputMethodInfo, Locale, boolean, String)} instead.
     */
    @Deprecated
    public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) {
        final int N = imi.getSubtypeCount();
        for (int i = 0; i < N; ++i) {
            final InputMethodSubtype subtype = imi.getSubtypeAt(i);
            if (!subtype.getLocale().startsWith(language)) {
                continue;
            }
            if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) ||
                    mode.equalsIgnoreCase(subtype.getMode())) {
                return true;
            }
        }
        return false;
    }

    public static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) {
        ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
        final int subtypeCount = imi.getSubtypeCount();
@@ -510,12 +450,15 @@ public class InputMethodUtils {
        while (i > 0) {
            i--;
            final InputMethodInfo imi = enabledImes.get(i);
            if (InputMethodUtils.isSystemImeThatHasEnglishKeyboardSubtype(imi)
                    && !imi.isAuxiliaryIme()) {
            if (imi.isAuxiliaryIme()) {
                continue;
            }
            if (InputMethodUtils.isSystemIme(imi)
                    && containsSubtypeOf(imi, ENGLISH_LOCALE, false /* checkCountry */,
                            SUBTYPE_MODE_KEYBOARD)) {
                return imi;
            }
            if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)
                    && !imi.isAuxiliaryIme()) {
            if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)) {
                firstFoundSystemIme = i;
            }
        }
+5 −3
Original line number Diff line number Diff line
@@ -764,9 +764,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

        InputMethodInfo defIm = null;
        for (InputMethodInfo imi : mMethodList) {
            if (defIm == null) {
                if (InputMethodUtils.isValidSystemDefaultIme(
                        mSystemReady, imi, context)) {
            if (defIm == null && mSystemReady) {
                final Locale systemLocale = context.getResources().getConfiguration().locale;
                if (InputMethodUtils.isSystemImeThatHasSubtypeOf(imi, context,
                        true /* checkDefaultAttribute */, systemLocale, false /* checkCountry */,
                        InputMethodUtils.SUBTYPE_MODE_ANY)) {
                    defIm = imi;
                    Slog.i(TAG, "Selected default: " + imi.getId());
                }