diff options
author | Yohei Yukawa <yukawa@google.com> | 2014-09-13 22:03:37 +0900 |
---|---|---|
committer | Yohei Yukawa <yukawa@google.com> | 2014-09-14 13:47:33 +0900 |
commit | 68c860bb29861e54fd9b868bd5af701b054a1dc0 (patch) | |
tree | e18b9d6e7688b839ea874e7f3749d5db815c1628 | |
parent | c0b8cb89105e814f2dc710c4b6f932ff726f0134 (diff) | |
download | frameworks_base-68c860bb29861e54fd9b868bd5af701b054a1dc0.zip frameworks_base-68c860bb29861e54fd9b868bd5af701b054a1dc0.tar.gz frameworks_base-68c860bb29861e54fd9b868bd5af701b054a1dc0.tar.bz2 |
Minimize the number of default enabled IMEs part 2
Previously the system tried to enable at least one auxiliary IME
even when the system is not ready. However, this doesn't make
much sense because the user should be able to set up their phone
without auxiliary IMEs. Also, IMEs enabled before the system
becomes ready are kept to be enabled after the system becomes
ready. Thus, we should minimize the number of enabled IMEs
until the system becomes ready.
BUG: 17347871
Change-Id: Ife93d909fb8a24471c425c903e2b7048826e17a3
-rw-r--r-- | core/java/com/android/internal/inputmethod/InputMethodUtils.java | 31 | ||||
-rw-r--r-- | core/tests/inputmethodtests/src/android/os/InputMethodTest.java | 27 |
2 files changed, 31 insertions, 27 deletions
diff --git a/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/core/java/com/android/internal/inputmethod/InputMethodUtils.java index d47d031..2d067d5 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodUtils.java +++ b/core/java/com/android/internal/inputmethod/InputMethodUtils.java @@ -44,6 +44,7 @@ import java.util.Locale; public class InputMethodUtils { public static final boolean DEBUG = false; public static final int NOT_A_SUBTYPE_ID = -1; + public static final String SUBTYPE_MODE_ANY = null; public static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; public static final String SUBTYPE_MODE_VOICE = "voice"; private static final String TAG = "InputMethodUtils"; @@ -127,10 +128,23 @@ public class InputMethodUtils { public static ArrayList<InputMethodInfo> getDefaultEnabledImes( Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) { - final ArrayList<InputMethodInfo> retval = new ArrayList<InputMethodInfo>(); + if (!isSystemReady) { + final ArrayList<InputMethodInfo> retval = new ArrayList<>(); + for (int i = 0; i < imis.size(); ++i) { + final InputMethodInfo imi = imis.get(i); + if (isSystemImeThatHasEnglishKeyboardSubtype(imi)) { + retval.add(imi); + } + } + return retval; + } + + final ArrayList<InputMethodInfo> retval = new ArrayList<>(); boolean auxilialyImeAdded = false; for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); + // TODO: We should check isAsciiCapable instead of relying on + // isSystemImeThatHasEnglishKeyboardSubtype(). if (isValidSystemDefaultIme(isSystemReady, imi, context) || isSystemImeThatHasEnglishKeyboardSubtype(imi)) { retval.add(imi); @@ -139,6 +153,7 @@ public class InputMethodUtils { } } } + // If one or more auxiliary input methods are available, OK to stop populating the list. if (auxilialyImeAdded) { return retval; } @@ -164,7 +179,7 @@ public class InputMethodUtils { try { if (imi.isDefault(context) && containsSubtypeOf( imi, context.getResources().getConfiguration().locale.getLanguage(), - null /* mode */)) { + SUBTYPE_MODE_ANY)) { return true; } } catch (Resources.NotFoundException ex) { @@ -179,13 +194,14 @@ public class InputMethodUtils { public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) { final int N = imi.getSubtypeCount(); for (int i = 0; i < N; ++i) { - if (!imi.getSubtypeAt(i).getLocale().startsWith(language)) { + final InputMethodSubtype subtype = imi.getSubtypeAt(i); + if (!subtype.getLocale().startsWith(language)) { continue; } - if(!TextUtils.isEmpty(mode) && !imi.getSubtypeAt(i).getMode().equalsIgnoreCase(mode)) { - continue; + if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) || + mode.equalsIgnoreCase(subtype.getMode())) { + return true; } - return true; } return false; } @@ -212,8 +228,7 @@ public class InputMethodUtils { return subtypes; } - public static InputMethodInfo getMostApplicableDefaultIME( - List<InputMethodInfo> enabledImes) { + public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) { if (enabledImes == null || enabledImes.isEmpty()) { return null; } diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java b/core/tests/inputmethodtests/src/android/os/InputMethodTest.java index cb85fc5..d56c5a9 100644 --- a/core/tests/inputmethodtests/src/android/os/InputMethodTest.java +++ b/core/tests/inputmethodtests/src/android/os/InputMethodTest.java @@ -53,10 +53,8 @@ public class InputMethodTest extends InstrumentationTestCase { public void testVoiceImes() throws Exception { // locale: en_US assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY, - "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", - "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); + "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY, - "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY, "DummyDefaultAutoVoiceIme", "DummyDefaultEnKeyboardIme"); @@ -66,10 +64,8 @@ public class InputMethodTest extends InstrumentationTestCase { // locale: en_GB assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY, - "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", - "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); + "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY, - "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); @@ -79,10 +75,8 @@ public class InputMethodTest extends InstrumentationTestCase { // locale: ja_JP assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY, - "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", - "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); + "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY, - "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", @@ -96,40 +90,35 @@ public class InputMethodTest extends InstrumentationTestCase { public void testKeyboardImes() throws Exception { // locale: en_US assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, !IS_SYSTEM_READY, - "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", - "com.android.apps.inputmethod.hindi"); + "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: en_GB assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, !IS_SYSTEM_READY, - "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", - "com.android.apps.inputmethod.hindi"); + "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: en_IN assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, !IS_SYSTEM_READY, - "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", - "com.android.apps.inputmethod.hindi"); + "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: hi assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, !IS_SYSTEM_READY, - "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", - "com.android.apps.inputmethod.hindi"); + "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: ja_JP assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, !IS_SYSTEM_READY, - "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", - "com.android.apps.inputmethod.hindi"); + "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi", "com.android.apps.inputmethod.japanese"); |