Remove a redundant param in getDefaultEnabledImes

With the previous CL [1], systemReady parameter in
InputMethodUtils.getDefaultEnabledImes() is guaranteed to be true.
Hence this CL removes that parameter. There should be no behavior change
in this CL.

 [1]: I5b37c450db4b25b3e635b6d634293a34eec8b9d4
      7924782c00

Test: adb shell am instrument -w -e class com.android.internal.inputmethod.InputMethodUtilsTest com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Bug: 32343335
Change-Id: Ia14d12a4e21d0e2e22bfe0bd8d496f48058c5525
This commit is contained in:
Yohei Yukawa
2017-01-23 16:17:11 -08:00
parent 7924782c00
commit af5cee8d26
3 changed files with 21 additions and 100 deletions

View File

@@ -266,43 +266,6 @@ public class InputMethodUtils {
}
}
private static InputMethodListBuilder getMinimumKeyboardSetWithoutSystemLocale(
final ArrayList<InputMethodInfo> imis, final Context context,
@Nullable final Locale fallbackLocale) {
// Before the system becomes ready, we pick up at least one keyboard in the following order.
// The first user (device owner) falls into this category.
// 1. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: true
// 2. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: true
// 3. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: false
// 4. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: false
// TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
final InputMethodListBuilder builder = new InputMethodListBuilder();
builder.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
if (!builder.isEmpty()) {
return builder;
}
builder.fillImes(imis, context, false /* checkDefaultAttribute */, fallbackLocale,
true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
if (!builder.isEmpty()) {
return builder;
}
builder.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
if (!builder.isEmpty()) {
return builder;
}
builder.fillImes(imis, context, false /* checkDefaultAttribute */, fallbackLocale,
false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
if (!builder.isEmpty()) {
return builder;
}
Slog.w(TAG, "No software keyboard is found. imis=" + Arrays.toString(imis.toArray())
+ " fallbackLocale=" + fallbackLocale);
return builder;
}
private static InputMethodListBuilder getMinimumKeyboardSetWithSystemLocale(
final ArrayList<InputMethodInfo> imis, final Context context,
@Nullable final Locale systemLocale, @Nullable final Locale fallbackLocale) {
@@ -353,21 +316,10 @@ public class InputMethodUtils {
}
public static ArrayList<InputMethodInfo> getDefaultEnabledImes(final Context context,
final boolean isSystemReady, final ArrayList<InputMethodInfo> imis) {
final ArrayList<InputMethodInfo> imis) {
final Locale fallbackLocale = getFallbackLocaleForDefaultIme(imis, context);
if (!isSystemReady) {
// When the system is not ready, the system locale is not stable and reliable. Hence
// we will pick up IMEs that support software keyboard based on the fallback locale.
// Also pick up suitable IMEs regardless of the software keyboard support.
// (e.g. Voice IMEs)
return getMinimumKeyboardSetWithoutSystemLocale(imis, context, fallbackLocale)
.fillImes(imis, context, true /* checkDefaultAttribute */, fallbackLocale,
true /* checkCountry */, SUBTYPE_MODE_ANY)
.build();
}
// When the system is ready, we will primarily rely on the system locale, but also keep
// relying on the fallback locale as a last resort.
// We will primarily rely on the system locale, but also keep relying on the fallback locale
// as a last resort.
// Also pick up suitable IMEs regardless of the software keyboard support (e.g. Voice IMEs),
// then pick up suitable auxiliary IMEs when necessary (e.g. Voice IMEs with "automatic"
// subtype)

View File

@@ -81,35 +81,23 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
public void testVoiceImes() throws Exception {
// locale: en_US
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
"DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US,
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US,
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
"DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
"DummyNonDefaultAutoVoiceIme1");
// locale: en_GB
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB,
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
"DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB,
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB,
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB,
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
"DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
"DummyNonDefaultAutoVoiceIme1");
// locale: ja_JP
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP,
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
"DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP,
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP,
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP,
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
"DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
"DummyNonDefaultAutoVoiceIme1");
}
@@ -117,54 +105,35 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
public void testKeyboardImes() throws Exception {
// locale: en_US
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
"com.android.apps.inputmethod.voice");
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
// locale: en_GB
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rGB"), LOCALE_EN_GB,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rGB"), LOCALE_EN_GB,
IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
"com.android.apps.inputmethod.voice");
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
// locale: en_IN
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rIN"), LOCALE_EN_IN,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rIN"), LOCALE_EN_IN,
IS_SYSTEM_READY, "com.android.apps.inputmethod.hindi",
"com.android.apps.inputmethod.hindi",
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
// locale: hi
assertDefaultEnabledImes(getSamplePreinstalledImes("hi"), LOCALE_HI,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("hi"), LOCALE_HI,
IS_SYSTEM_READY, "com.android.apps.inputmethod.hindi",
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
"com.android.apps.inputmethod.hindi", "com.android.apps.inputmethod.latin",
"com.android.apps.inputmethod.voice");
// locale: ja_JP
assertDefaultEnabledImes(getSamplePreinstalledImes("ja-rJP"), LOCALE_JA_JP,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("ja-rJP"), LOCALE_JA_JP,
IS_SYSTEM_READY, "com.android.apps.inputmethod.japanese",
"com.android.apps.inputmethod.voice");
"com.android.apps.inputmethod.japanese", "com.android.apps.inputmethod.voice");
// locale: zh_CN
assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rCN"), LOCALE_ZH_CN,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rCN"), LOCALE_ZH_CN,
IS_SYSTEM_READY, "com.android.apps.inputmethod.pinyin",
"com.android.apps.inputmethod.voice");
"com.android.apps.inputmethod.pinyin", "com.android.apps.inputmethod.voice");
// locale: zh_TW
// Note: In this case, no IME is suitable for the system locale. Hence we will pick up a
// fallback IME regardless of the "default" attribute.
assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rTW"), LOCALE_ZH_TW,
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
assertDefaultEnabledImes(getSamplePreinstalledImes("zh-rTW"), LOCALE_ZH_TW,
IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
"com.android.apps.inputmethod.voice");
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
}
@SmallTest
@@ -792,10 +761,10 @@ public class InputMethodUtilsTest extends InstrumentationTestCase {
}
private void assertDefaultEnabledImes(final ArrayList<InputMethodInfo> preinstalledImes,
final Locale systemLocale, final boolean isSystemReady, String... expectedImeNames) {
final Locale systemLocale, String... expectedImeNames) {
final Context context = createTargetContextWithLocales(new LocaleList(systemLocale));
final String[] actualImeNames = getPackageNames(
InputMethodUtils.getDefaultEnabledImes(context, isSystemReady, preinstalledImes));
InputMethodUtils.getDefaultEnabledImes(context, preinstalledImes));
assertEquals(expectedImeNames.length, actualImeNames.length);
for (int i = 0; i < expectedImeNames.length; ++i) {
assertEquals(expectedImeNames[i], actualImeNames[i]);

View File

@@ -926,7 +926,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
return;
}
final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes(
context, mSystemReady, mSettings.getEnabledInputMethodListLocked());
context, mSettings.getEnabledInputMethodListLocked());
if (suitableImes.isEmpty()) {
Slog.i(TAG, "No default found");
return;
@@ -3089,7 +3089,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
if (resetDefaultEnabledIme) {
final ArrayList<InputMethodInfo> defaultEnabledIme =
InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, mMethodList);
InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList);
final int N = defaultEnabledIme.size();
for (int i = 0; i < N; ++i) {
final InputMethodInfo imi = defaultEnabledIme.get(i);