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

Commit 5e5c60a4 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Minimize the number of default enabled IMEs part 1

Basically this CL does following clean-ups as groundwork.
- Embed isDefaultEnabledIme into its only one caller
- Fix a typo in isSystemAuxilialyImeThatHashAutomaticSubtype()
- Use exit-early style in getMostApplicableDefaultIME()

No behavior change is intended by this CL.

BUG: 17347871
Change-Id: I831502db502f4073c9c2f50ce7705a4e45e2e1e3
parent 12c12ee2
Loading
Loading
Loading
Loading
+21 −26
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public class InputMethodUtils {
        return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(), SUBTYPE_MODE_KEYBOARD);
    }

    private static boolean isSystemAuxilialyImeThatHashAutomaticSubtype(InputMethodInfo imi) {
    private static boolean isSystemAuxilialyImeThatHasAutomaticSubtype(InputMethodInfo imi) {
        if (!isSystemIme(imi)) {
            return false;
        }
@@ -131,7 +131,8 @@ public class InputMethodUtils {
        boolean auxilialyImeAdded = false;
        for (int i = 0; i < imis.size(); ++i) {
            final InputMethodInfo imi = imis.get(i);
            if (isDefaultEnabledIme(isSystemReady, imi, context)) {
            if (isValidSystemDefaultIme(isSystemReady, imi, context)
                    || isSystemImeThatHasEnglishKeyboardSubtype(imi)) {
                retval.add(imi);
                if (imi.isAuxiliaryIme()) {
                    auxilialyImeAdded = true;
@@ -143,7 +144,7 @@ public class InputMethodUtils {
        }
        for (int i = 0; i < imis.size(); ++i) {
            final InputMethodInfo imi = imis.get(i);
            if (isSystemAuxilialyImeThatHashAutomaticSubtype(imi)) {
            if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi)) {
                retval.add(imi);
            }
        }
@@ -175,12 +176,6 @@ public class InputMethodUtils {
        return false;
    }

    public static boolean isDefaultEnabledIme(
            boolean isSystemReady, InputMethodInfo imi, Context context) {
        return isValidSystemDefaultIme(isSystemReady, imi, context)
                || isSystemImeThatHasEnglishKeyboardSubtype(imi);
    }

    public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) {
        final int N = imi.getSubtypeCount();
        for (int i = 0; i < N; ++i) {
@@ -219,7 +214,9 @@ public class InputMethodUtils {

    public static InputMethodInfo getMostApplicableDefaultIME(
            List<InputMethodInfo> enabledImes) {
        if (enabledImes != null && enabledImes.size() > 0) {
        if (enabledImes == null || enabledImes.isEmpty()) {
            return null;
        }
        // We'd prefer to fall back on a system IME, since that is safer.
        int i = enabledImes.size();
        int firstFoundSystemIme = -1;
@@ -237,8 +234,6 @@ public class InputMethodUtils {
        }
        return enabledImes.get(Math.max(firstFoundSystemIme, 0));
    }
        return null;
    }

    public static boolean isValidSubtypeId(InputMethodInfo imi, int subtypeHashCode) {
        return getSubtypeIdFromHashCode(imi, subtypeHashCode) != NOT_A_SUBTYPE_ID;