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
diff --git a/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/core/java/com/android/internal/inputmethod/InputMethodUtils.java
index 6eb0099..d47d031 100644
--- a/core/java/com/android/internal/inputmethod/InputMethodUtils.java
+++ b/core/java/com/android/internal/inputmethod/InputMethodUtils.java
@@ -108,7 +108,7 @@
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 @@
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 @@
}
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 @@
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,25 +214,25 @@
public static InputMethodInfo getMostApplicableDefaultIME(
List<InputMethodInfo> enabledImes) {
- if (enabledImes != null && enabledImes.size() > 0) {
- // We'd prefer to fall back on a system IME, since that is safer.
- int i = enabledImes.size();
- int firstFoundSystemIme = -1;
- while (i > 0) {
- i--;
- final InputMethodInfo imi = enabledImes.get(i);
- if (InputMethodUtils.isSystemImeThatHasEnglishKeyboardSubtype(imi)
- && !imi.isAuxiliaryIme()) {
- return imi;
- }
- if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)
- && !imi.isAuxiliaryIme()) {
- firstFoundSystemIme = i;
- }
- }
- return enabledImes.get(Math.max(firstFoundSystemIme, 0));
+ if (enabledImes == null || enabledImes.isEmpty()) {
+ return null;
}
- return null;
+ // We'd prefer to fall back on a system IME, since that is safer.
+ int i = enabledImes.size();
+ int firstFoundSystemIme = -1;
+ while (i > 0) {
+ i--;
+ final InputMethodInfo imi = enabledImes.get(i);
+ if (InputMethodUtils.isSystemImeThatHasEnglishKeyboardSubtype(imi)
+ && !imi.isAuxiliaryIme()) {
+ return imi;
+ }
+ if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)
+ && !imi.isAuxiliaryIme()) {
+ firstFoundSystemIme = i;
+ }
+ }
+ return enabledImes.get(Math.max(firstFoundSystemIme, 0));
}
public static boolean isValidSubtypeId(InputMethodInfo imi, int subtypeHashCode) {