Merge "Minimize the number of default enabled IMEs part 4" into lmp-mr1-dev
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.internal.inputmethod;
|
package com.android.internal.inputmethod;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -34,7 +36,9 @@ import android.view.textservice.SpellCheckerInfo;
|
|||||||
import android.view.textservice.TextServicesManager;
|
import android.view.textservice.TextServicesManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -115,8 +119,8 @@ public class InputMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link Locale} returned from
|
* @deprecated Use {@link #isSystemImeThatHasSubtypeOf(InputMethodInfo, Context, boolean,
|
||||||
* {@link #getFallbackLocaleForDefaultIme(ArrayList)} instead.
|
* Locale, boolean, String)} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean isSystemImeThatHasEnglishKeyboardSubtype(InputMethodInfo imi) {
|
public static boolean isSystemImeThatHasEnglishKeyboardSubtype(InputMethodInfo imi) {
|
||||||
@@ -126,25 +130,60 @@ public class InputMethodUtils {
|
|||||||
return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(), SUBTYPE_MODE_KEYBOARD);
|
return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(), SUBTYPE_MODE_KEYBOARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isSystemImeThatHasSubtypeOf(final InputMethodInfo imi,
|
||||||
|
final Context context, final boolean checkDefaultAttribute,
|
||||||
|
@Nullable final Locale requiredLocale, final boolean checkCountry,
|
||||||
|
final String requiredSubtypeMode) {
|
||||||
|
if (!isSystemIme(imi)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (checkDefaultAttribute && !imi.isDefault(context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!containsSubtypeOf(imi, requiredLocale, checkCountry, requiredSubtypeMode)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static Locale getFallbackLocaleForDefaultIme(final ArrayList<InputMethodInfo> imis,
|
public static Locale getFallbackLocaleForDefaultIme(final ArrayList<InputMethodInfo> imis,
|
||||||
final Context context) {
|
final Context context) {
|
||||||
|
// At first, find the fallback locale from the IMEs that are declared as "default" in the
|
||||||
|
// current locale. Note that IME developers can declare an IME as "default" only for
|
||||||
|
// some particular locales but "not default" for other locales.
|
||||||
for (final Locale fallbackLocale : SEARCH_ORDER_OF_FALLBACK_LOCALES) {
|
for (final Locale fallbackLocale : SEARCH_ORDER_OF_FALLBACK_LOCALES) {
|
||||||
for (int i = 0; i < imis.size(); ++i) {
|
for (int i = 0; i < imis.size(); ++i) {
|
||||||
final InputMethodInfo imi = imis.get(i);
|
if (isSystemImeThatHasSubtypeOf(imis.get(i), context,
|
||||||
if (isSystemIme(imi) && imi.isDefault(context) &&
|
true /* checkDefaultAttribute */, fallbackLocale,
|
||||||
containsSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
|
true /* checkCountry */, SUBTYPE_MODE_KEYBOARD)) {
|
||||||
SUBTYPE_MODE_KEYBOARD)) {
|
|
||||||
return fallbackLocale;
|
return fallbackLocale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If no fallback locale is found in the above condition, find fallback locales regardless
|
||||||
|
// of the "default" attribute as a last resort.
|
||||||
|
for (final Locale fallbackLocale : SEARCH_ORDER_OF_FALLBACK_LOCALES) {
|
||||||
|
for (int i = 0; i < imis.size(); ++i) {
|
||||||
|
if (isSystemImeThatHasSubtypeOf(imis.get(i), context,
|
||||||
|
false /* checkDefaultAttribute */, fallbackLocale,
|
||||||
|
true /* checkCountry */, SUBTYPE_MODE_KEYBOARD)) {
|
||||||
|
return fallbackLocale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Slog.w(TAG, "Found no fallback locale. imis=" + Arrays.toString(imis.toArray()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSystemAuxilialyImeThatHasAutomaticSubtype(InputMethodInfo imi) {
|
private static boolean isSystemAuxilialyImeThatHasAutomaticSubtype(final InputMethodInfo imi,
|
||||||
|
final Context context, final boolean checkDefaultAttribute) {
|
||||||
if (!isSystemIme(imi)) {
|
if (!isSystemIme(imi)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (checkDefaultAttribute && !imi.isDefault(context)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!imi.isAuxiliaryIme()) {
|
if (!imi.isAuxiliaryIme()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -166,98 +205,184 @@ public class InputMethodUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<InputMethodInfo> getDefaultEnabledImes(
|
private static final class InputMethodListBuilder {
|
||||||
Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) {
|
// Note: We use LinkedHashSet instead of android.util.ArraySet because the enumeration
|
||||||
// OK to store null in fallbackLocale because isImeThatHasSubtypeOf() is null-tolerant.
|
// order can have non-trivial effect in the call sites.
|
||||||
final Locale fallbackLocale = getFallbackLocaleForDefaultIme(imis, context);
|
@NonNull
|
||||||
|
private final LinkedHashSet<InputMethodInfo> mInputMethodSet = new LinkedHashSet<>();
|
||||||
|
|
||||||
if (!isSystemReady) {
|
public InputMethodListBuilder fillImes(final ArrayList<InputMethodInfo> imis,
|
||||||
final ArrayList<InputMethodInfo> retval = new ArrayList<>();
|
final Context context, final boolean checkDefaultAttribute,
|
||||||
|
@Nullable final Locale locale, final boolean checkCountry,
|
||||||
|
final String requiredSubtypeMode) {
|
||||||
for (int i = 0; i < imis.size(); ++i) {
|
for (int i = 0; i < imis.size(); ++i) {
|
||||||
final InputMethodInfo imi = imis.get(i);
|
final InputMethodInfo imi = imis.get(i);
|
||||||
// TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
|
if (isSystemImeThatHasSubtypeOf(imi, context, checkDefaultAttribute, locale,
|
||||||
if (isSystemIme(imi) && imi.isDefault(context) &&
|
checkCountry, requiredSubtypeMode)) {
|
||||||
isImeThatHasSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
|
mInputMethodSet.add(imi);
|
||||||
SUBTYPE_MODE_KEYBOARD)) {
|
|
||||||
retval.add(imi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
// OK to store null in fallbackLocale because isImeThatHasSubtypeOf() is null-tolerant.
|
|
||||||
final Locale systemLocale = getSystemLocaleFromContext(context);
|
|
||||||
// TODO: Use LinkedHashSet to simplify the code.
|
|
||||||
final ArrayList<InputMethodInfo> retval = new ArrayList<>();
|
|
||||||
boolean systemLocaleKeyboardImeFound = false;
|
|
||||||
|
|
||||||
// First, try to find IMEs with taking the system locale country into consideration.
|
|
||||||
for (int i = 0; i < imis.size(); ++i) {
|
|
||||||
final InputMethodInfo imi = imis.get(i);
|
|
||||||
if (!isSystemIme(imi) || !imi.isDefault(context)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final boolean isSystemLocaleKeyboardIme = isImeThatHasSubtypeOf(imi, systemLocale,
|
|
||||||
false /* ignoreCountry */, SUBTYPE_MODE_KEYBOARD);
|
|
||||||
// TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
|
|
||||||
// TODO: Use LinkedHashSet to simplify the code.
|
|
||||||
if (isSystemLocaleKeyboardIme ||
|
|
||||||
isImeThatHasSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
|
|
||||||
SUBTYPE_MODE_ANY)) {
|
|
||||||
retval.add(imi);
|
|
||||||
}
|
|
||||||
systemLocaleKeyboardImeFound |= isSystemLocaleKeyboardIme;
|
|
||||||
}
|
|
||||||
|
|
||||||
// System locale country doesn't match any IMEs, try to find IMEs in a country-agnostic
|
|
||||||
// way.
|
|
||||||
if (!systemLocaleKeyboardImeFound) {
|
|
||||||
for (int i = 0; i < imis.size(); ++i) {
|
|
||||||
final InputMethodInfo imi = imis.get(i);
|
|
||||||
if (!isSystemIme(imi) || !imi.isDefault(context)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isImeThatHasSubtypeOf(imi, fallbackLocale, false /* ignoreCountry */,
|
|
||||||
SUBTYPE_MODE_KEYBOARD)) {
|
|
||||||
// IMEs that have fallback locale are already added in the previous loop. We
|
|
||||||
// don't need to add them again here.
|
|
||||||
// TODO: Use LinkedHashSet to simplify the code.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isImeThatHasSubtypeOf(imi, systemLocale, true /* ignoreCountry */,
|
|
||||||
SUBTYPE_MODE_ANY)) {
|
|
||||||
retval.add(imi);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: The behavior of InputMethodSubtype#overridesImplicitlyEnabledSubtype() should be
|
||||||
|
// documented more clearly.
|
||||||
|
public InputMethodListBuilder fillAuxiliaryImes(final ArrayList<InputMethodInfo> imis,
|
||||||
|
final Context context) {
|
||||||
// If one or more auxiliary input methods are available, OK to stop populating the list.
|
// If one or more auxiliary input methods are available, OK to stop populating the list.
|
||||||
for (int i = 0; i < retval.size(); ++i) {
|
for (final InputMethodInfo imi : mInputMethodSet) {
|
||||||
if (retval.get(i).isAuxiliaryIme()) {
|
if (imi.isAuxiliaryIme()) {
|
||||||
return retval;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
boolean added = false;
|
||||||
|
for (int i = 0; i < imis.size(); ++i) {
|
||||||
|
final InputMethodInfo imi = imis.get(i);
|
||||||
|
if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi, context,
|
||||||
|
true /* checkDefaultAttribute */)) {
|
||||||
|
mInputMethodSet.add(imi);
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (added) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
for (int i = 0; i < imis.size(); ++i) {
|
for (int i = 0; i < imis.size(); ++i) {
|
||||||
final InputMethodInfo imi = imis.get(i);
|
final InputMethodInfo imi = imis.get(i);
|
||||||
if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi)) {
|
if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi, context,
|
||||||
retval.add(imi);
|
false /* checkDefaultAttribute */)) {
|
||||||
|
mInputMethodSet.add(imi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isImeThatHasSubtypeOf(final InputMethodInfo imi,
|
public boolean isEmpty() {
|
||||||
final Locale locale, final boolean ignoreCountry, final String mode) {
|
return mInputMethodSet.isEmpty();
|
||||||
if (locale == null) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return containsSubtypeOf(imi, locale, ignoreCountry, mode);
|
|
||||||
|
@NonNull
|
||||||
|
public ArrayList<InputMethodInfo> build() {
|
||||||
|
return new ArrayList<>(mInputMethodSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
// Once the system becomes ready, we pick up at least one keyboard in the following order.
|
||||||
|
// Secondary users fall into this category in general.
|
||||||
|
// 1. checkDefaultAttribute: true, locale: systemLocale, checkCountry: true
|
||||||
|
// 2. checkDefaultAttribute: true, locale: systemLocale, checkCountry: false
|
||||||
|
// 3. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: true
|
||||||
|
// 4. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: false
|
||||||
|
// 5. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: true
|
||||||
|
// 6. 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 */, systemLocale,
|
||||||
|
true /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
|
||||||
|
if (!builder.isEmpty()) {
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
builder.fillImes(imis, context, true /* checkDefaultAttribute */, systemLocale,
|
||||||
|
false /* checkCountry */, SUBTYPE_MODE_KEYBOARD);
|
||||||
|
if (!builder.isEmpty()) {
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
builder.fillImes(imis, context, true /* 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,
|
||||||
|
true /* 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())
|
||||||
|
+ " systemLocale=" + systemLocale + " fallbackLocale=" + fallbackLocale);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<InputMethodInfo> getDefaultEnabledImes(final Context context,
|
||||||
|
final boolean isSystemReady, 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.
|
||||||
|
// 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)
|
||||||
|
final Locale systemLocale = getSystemLocaleFromContext(context);
|
||||||
|
return getMinimumKeyboardSetWithSystemLocale(imis, context, systemLocale, fallbackLocale)
|
||||||
|
.fillImes(imis, context, true /* checkDefaultAttribute */, systemLocale,
|
||||||
|
true /* checkCountry */, SUBTYPE_MODE_ANY)
|
||||||
|
.fillAuxiliaryImes(imis, context)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link #isSystemIme(InputMethodInfo)} and
|
* @deprecated Use {@link #isSystemImeThatHasSubtypeOf(InputMethodInfo, Context, boolean,
|
||||||
* {@link InputMethodInfo#isDefault(Context)} and
|
* Locale, boolean, String)} instead.
|
||||||
* {@link #isImeThatHasSubtypeOf(InputMethodInfo, Locale, boolean, String))} instead.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static boolean isValidSystemDefaultIme(
|
public static boolean isValidSystemDefaultIme(
|
||||||
@@ -285,22 +410,25 @@ public class InputMethodUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsSubtypeOf(final InputMethodInfo imi,
|
public static boolean containsSubtypeOf(final InputMethodInfo imi,
|
||||||
final Locale locale, final boolean ignoreCountry, final String mode) {
|
@Nullable final Locale locale, final boolean checkCountry, final String mode) {
|
||||||
|
if (locale == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final int N = imi.getSubtypeCount();
|
final int N = imi.getSubtypeCount();
|
||||||
for (int i = 0; i < N; ++i) {
|
for (int i = 0; i < N; ++i) {
|
||||||
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
|
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
|
||||||
if (ignoreCountry) {
|
if (checkCountry) {
|
||||||
final Locale subtypeLocale = new Locale(getLanguageFromLocaleString(
|
|
||||||
subtype.getLocale()));
|
|
||||||
if (!subtypeLocale.getLanguage().equals(locale.getLanguage())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: Use {@link Locale#toLanguageTag()} and
|
// TODO: Use {@link Locale#toLanguageTag()} and
|
||||||
// {@link Locale#forLanguageTag(languageTag)} instead.
|
// {@link Locale#forLanguageTag(languageTag)} instead.
|
||||||
if (!TextUtils.equals(subtype.getLocale(), locale.toString())) {
|
if (!TextUtils.equals(subtype.getLocale(), locale.toString())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
final Locale subtypeLocale = new Locale(getLanguageFromLocaleString(
|
||||||
|
subtype.getLocale()));
|
||||||
|
if (!subtypeLocale.getLanguage().equals(locale.getLanguage())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) ||
|
if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) ||
|
||||||
mode.equalsIgnoreCase(subtype.getMode())) {
|
mode.equalsIgnoreCase(subtype.getMode())) {
|
||||||
@@ -465,19 +593,9 @@ public class InputMethodUtils {
|
|||||||
return applicableSubtypes;
|
return applicableSubtypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<InputMethodSubtype> getEnabledInputMethodSubtypeList(
|
|
||||||
Context context, InputMethodInfo imi, List<InputMethodSubtype> enabledSubtypes,
|
|
||||||
boolean allowsImplicitlySelectedSubtypes) {
|
|
||||||
if (allowsImplicitlySelectedSubtypes && enabledSubtypes.isEmpty()) {
|
|
||||||
enabledSubtypes = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(
|
|
||||||
context.getResources(), imi);
|
|
||||||
}
|
|
||||||
return InputMethodSubtype.sort(context, 0, imi, enabledSubtypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the language component of a given locale string.
|
* Returns the language component of a given locale string.
|
||||||
* TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(languageTag)}
|
* TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(String)}
|
||||||
*/
|
*/
|
||||||
public static String getLanguageFromLocaleString(String locale) {
|
public static String getLanguageFromLocaleString(String locale) {
|
||||||
final int idx = locale.indexOf('_');
|
final int idx = locale.indexOf('_');
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class InputMethodTest extends InstrumentationTestCase {
|
public class InputMethodTest extends InstrumentationTestCase {
|
||||||
private static final boolean IS_AUX = true;
|
private static final boolean IS_AUX = true;
|
||||||
@@ -46,84 +47,104 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
private static final Locale LOCALE_EN_IN = new Locale("en", "IN");
|
private static final Locale LOCALE_EN_IN = new Locale("en", "IN");
|
||||||
private static final Locale LOCALE_HI = new Locale("hi");
|
private static final Locale LOCALE_HI = new Locale("hi");
|
||||||
private static final Locale LOCALE_JA_JP = new Locale("ja", "JP");
|
private static final Locale LOCALE_JA_JP = new Locale("ja", "JP");
|
||||||
|
private static final Locale LOCALE_ZH_CN = new Locale("zh", "CN");
|
||||||
|
private static final Locale LOCALE_ZH_TW = new Locale("zh", "TW");
|
||||||
private static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
|
private static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
|
||||||
private static final String SUBTYPE_MODE_VOICE = "voice";
|
private static final String SUBTYPE_MODE_VOICE = "voice";
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testVoiceImes() throws Exception {
|
public void testVoiceImes() throws Exception {
|
||||||
// locale: en_US
|
// locale: en_US
|
||||||
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
|
||||||
"DummyDefaultEnKeyboardIme");
|
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
||||||
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US,
|
||||||
"DummyDefaultEnKeyboardIme");
|
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
|
||||||
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US,
|
||||||
"DummyDefaultAutoVoiceIme", "DummyDefaultEnKeyboardIme");
|
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
||||||
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US,
|
||||||
"DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
|
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
|
||||||
"DummyDefaultEnKeyboardIme");
|
"DummyNonDefaultAutoVoiceIme1");
|
||||||
|
|
||||||
// locale: en_GB
|
// locale: en_GB
|
||||||
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB,
|
||||||
"DummyDefaultEnKeyboardIme");
|
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
||||||
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB,
|
||||||
"DummyDefaultEnKeyboardIme");
|
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
|
||||||
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB,
|
||||||
"DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
||||||
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB,
|
||||||
"DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
|
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
|
||||||
"DummyDefaultEnKeyboardIme");
|
"DummyNonDefaultAutoVoiceIme1");
|
||||||
|
|
||||||
// locale: ja_JP
|
// locale: ja_JP
|
||||||
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP,
|
||||||
"DummyDefaultEnKeyboardIme");
|
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
||||||
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP,
|
||||||
"DummyDefaultEnKeyboardIme");
|
!IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme");
|
||||||
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP,
|
||||||
"DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme");
|
||||||
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP,
|
||||||
"DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1",
|
IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyNonDefaultAutoVoiceIme0",
|
||||||
"DummyDefaultEnKeyboardIme");
|
"DummyNonDefaultAutoVoiceIme1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testKeyboardImes() throws Exception {
|
public void testKeyboardImes() throws Exception {
|
||||||
// locale: en_US
|
// locale: en_US
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
|
||||||
"com.android.apps.inputmethod.latin");
|
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rUS"), LOCALE_EN_US,
|
||||||
"com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin");
|
IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
|
||||||
|
"com.android.apps.inputmethod.voice");
|
||||||
|
|
||||||
// locale: en_GB
|
// locale: en_GB
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rGB"), LOCALE_EN_GB,
|
||||||
"com.android.apps.inputmethod.latin");
|
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rGB"), LOCALE_EN_GB,
|
||||||
"com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin");
|
IS_SYSTEM_READY, "com.android.apps.inputmethod.latin",
|
||||||
|
"com.android.apps.inputmethod.voice");
|
||||||
|
|
||||||
// locale: en_IN
|
// locale: en_IN
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rIN"), LOCALE_EN_IN,
|
||||||
"com.android.apps.inputmethod.latin");
|
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("en-rIN"), LOCALE_EN_IN,
|
||||||
"com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
|
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
|
// locale: hi
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("hi"), LOCALE_HI,
|
||||||
"com.android.apps.inputmethod.latin");
|
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("hi"), LOCALE_HI,
|
||||||
"com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
|
IS_SYSTEM_READY, "com.android.apps.inputmethod.hindi",
|
||||||
"com.android.apps.inputmethod.hindi");
|
"com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.voice");
|
||||||
|
|
||||||
// locale: ja_JP
|
// locale: ja_JP
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, !IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("ja-rJP"), LOCALE_JA_JP,
|
||||||
"com.android.apps.inputmethod.latin");
|
!IS_SYSTEM_READY, "com.android.apps.inputmethod.latin");
|
||||||
assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, IS_SYSTEM_READY,
|
assertDefaultEnabledImes(getSamplePreinstalledImes("ja-rJP"), LOCALE_JA_JP,
|
||||||
"com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin",
|
IS_SYSTEM_READY, "com.android.apps.inputmethod.japanese",
|
||||||
"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");
|
||||||
|
|
||||||
|
// 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public void testParcelable() throws Exception {
|
public void testParcelable() throws Exception {
|
||||||
final ArrayList<InputMethodInfo> originalList = getSamplePreinstalledImes();
|
final ArrayList<InputMethodInfo> originalList = getSamplePreinstalledImes("en-rUS");
|
||||||
final List<InputMethodInfo> clonedList = cloneViaParcel(originalList);
|
final List<InputMethodInfo> clonedList = cloneViaParcel(originalList);
|
||||||
assertNotNull(clonedList);
|
assertNotNull(clonedList);
|
||||||
final List<InputMethodInfo> clonedClonedList = cloneViaParcel(clonedList);
|
final List<InputMethodInfo> clonedClonedList = cloneViaParcel(clonedList);
|
||||||
@@ -139,11 +160,14 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertDefaultEnabledImes(final ArrayList<InputMethodInfo> preinstalledImes,
|
private void assertDefaultEnabledImes(final ArrayList<InputMethodInfo> preinstalledImes,
|
||||||
final Locale systemLocale, final boolean isSystemReady, String... imeNames) {
|
final Locale systemLocale, final boolean isSystemReady, String... expectedImeNames) {
|
||||||
final Context context = getInstrumentation().getTargetContext();
|
final Context context = getInstrumentation().getTargetContext();
|
||||||
assertEquals(new HashSet<String>(Arrays.asList(imeNames)),
|
final String[] actualImeNames = getPackageNames(callGetDefaultEnabledImesUnderWithLocale(
|
||||||
getPackageNames(callGetDefaultEnabledImesUnderWithLocale(context,
|
context, isSystemReady, preinstalledImes, systemLocale));
|
||||||
isSystemReady, preinstalledImes, systemLocale)));
|
assertEquals(expectedImeNames.length, actualImeNames.length);
|
||||||
|
for (int i = 0; i < expectedImeNames.length; ++i) {
|
||||||
|
assertEquals(expectedImeNames[i], actualImeNames[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<InputMethodInfo> cloneViaParcel(final List<InputMethodInfo> list) {
|
private static List<InputMethodInfo> cloneViaParcel(final List<InputMethodInfo> list) {
|
||||||
@@ -172,11 +196,10 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashSet<String> getPackageNames(final ArrayList<InputMethodInfo> imis) {
|
private String[] getPackageNames(final ArrayList<InputMethodInfo> imis) {
|
||||||
final HashSet<String> packageNames = new HashSet<>();
|
final String[] packageNames = new String[imis.size()];
|
||||||
for (final InputMethodInfo imi : imis) {
|
for (int i = 0; i < imis.size(); ++i) {
|
||||||
final String actualPackageName = imi.getPackageName();
|
packageNames[i] = imis.get(i).getPackageName();
|
||||||
packageNames.add(actualPackageName);
|
|
||||||
}
|
}
|
||||||
return packageNames;
|
return packageNames;
|
||||||
}
|
}
|
||||||
@@ -278,21 +301,34 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
return preinstalledImes;
|
return preinstalledImes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<InputMethodInfo> getSamplePreinstalledImes() {
|
private static boolean contains(final String[] textList, final String textToBeChecked) {
|
||||||
|
if (textList == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (final String text : textList) {
|
||||||
|
if (Objects.equals(textToBeChecked, text)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<InputMethodInfo> getSamplePreinstalledImes(final String localeString) {
|
||||||
ArrayList<InputMethodInfo> preinstalledImes = new ArrayList<>();
|
ArrayList<InputMethodInfo> preinstalledImes = new ArrayList<>();
|
||||||
|
|
||||||
// a dummy Voice IME
|
// a dummy Voice IME
|
||||||
{
|
{
|
||||||
|
final boolean isDefaultIme = false;
|
||||||
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
||||||
subtypes.add(createDummyInputMethodSubtype("", SUBTYPE_MODE_VOICE, IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("", SUBTYPE_MODE_VOICE, IS_AUX,
|
||||||
IS_AUTO, !IS_ASCII_CAPABLE));
|
IS_AUTO, !IS_ASCII_CAPABLE));
|
||||||
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.voice",
|
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.voice",
|
||||||
"com.android.inputmethod.voice", "DummyVoiceIme", IS_AUX, IS_DEFAULT,
|
"com.android.inputmethod.voice", "DummyVoiceIme", IS_AUX, isDefaultIme,
|
||||||
subtypes));
|
subtypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// a dummy Hindi IME
|
// a dummy Hindi IME
|
||||||
{
|
{
|
||||||
|
final boolean isDefaultIme = contains(new String[]{ "hi", "en-rIN" }, localeString);
|
||||||
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
||||||
// TODO: This subtype should be marked as IS_ASCII_CAPABLE
|
// TODO: This subtype should be marked as IS_ASCII_CAPABLE
|
||||||
subtypes.add(createDummyInputMethodSubtype("en_IN", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("en_IN", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
@@ -300,32 +336,36 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
subtypes.add(createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
!IS_AUTO, !IS_ASCII_CAPABLE));
|
!IS_AUTO, !IS_ASCII_CAPABLE));
|
||||||
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.hindi",
|
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.hindi",
|
||||||
"com.android.inputmethod.hindi", "DummyHindiIme", !IS_AUX, IS_DEFAULT,
|
"com.android.inputmethod.hindi", "DummyHindiIme", !IS_AUX, isDefaultIme,
|
||||||
subtypes));
|
subtypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// a dummy Pinyin IME
|
// a dummy Pinyin IME
|
||||||
{
|
{
|
||||||
|
final boolean isDefaultIme = contains(new String[]{ "zh-rCN" }, localeString);
|
||||||
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
||||||
subtypes.add(createDummyInputMethodSubtype("zh_CN", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("zh_CN", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
!IS_AUTO, !IS_ASCII_CAPABLE));
|
!IS_AUTO, !IS_ASCII_CAPABLE));
|
||||||
preinstalledImes.add(createDummyInputMethodInfo("ccom.android.apps.inputmethod.pinyin",
|
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.pinyin",
|
||||||
"com.android.apps.inputmethod.pinyin", "DummyPinyinIme", !IS_AUX, IS_DEFAULT,
|
"com.android.apps.inputmethod.pinyin", "DummyPinyinIme", !IS_AUX, isDefaultIme,
|
||||||
subtypes));
|
subtypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// a dummy Korian IME
|
// a dummy Korean IME
|
||||||
{
|
{
|
||||||
|
final boolean isDefaultIme = contains(new String[]{ "ko" }, localeString);
|
||||||
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
||||||
subtypes.add(createDummyInputMethodSubtype("ko", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("ko", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
!IS_AUTO, !IS_ASCII_CAPABLE));
|
!IS_AUTO, !IS_ASCII_CAPABLE));
|
||||||
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.korean",
|
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.korean",
|
||||||
"com.android.apps.inputmethod.korean", "DummyKorianIme", !IS_AUX, IS_DEFAULT,
|
"com.android.apps.inputmethod.korean", "DummyKoreanIme", !IS_AUX, isDefaultIme,
|
||||||
subtypes));
|
subtypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// a dummy Latin IME
|
// a dummy Latin IME
|
||||||
{
|
{
|
||||||
|
final boolean isDefaultIme = contains(
|
||||||
|
new String[]{ "en-rUS", "en-rGB", "en-rIN", "en", "hi" }, localeString);
|
||||||
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
||||||
subtypes.add(createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
!IS_AUTO, IS_ASCII_CAPABLE));
|
!IS_AUTO, IS_ASCII_CAPABLE));
|
||||||
@@ -336,12 +376,13 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
subtypes.add(createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
!IS_AUTO, IS_ASCII_CAPABLE));
|
!IS_AUTO, IS_ASCII_CAPABLE));
|
||||||
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.latin",
|
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.latin",
|
||||||
"com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT,
|
"com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, isDefaultIme,
|
||||||
subtypes));
|
subtypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// a dummy Japanese IME
|
// a dummy Japanese IME
|
||||||
{
|
{
|
||||||
|
final boolean isDefaultIme = contains(new String[]{ "ja", "ja-rJP" }, localeString);
|
||||||
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
|
||||||
subtypes.add(createDummyInputMethodSubtype("ja", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
subtypes.add(createDummyInputMethodSubtype("ja", SUBTYPE_MODE_KEYBOARD, !IS_AUX,
|
||||||
!IS_AUTO, !IS_ASCII_CAPABLE));
|
!IS_AUTO, !IS_ASCII_CAPABLE));
|
||||||
@@ -349,7 +390,7 @@ public class InputMethodTest extends InstrumentationTestCase {
|
|||||||
!IS_AUTO, !IS_ASCII_CAPABLE));
|
!IS_AUTO, !IS_ASCII_CAPABLE));
|
||||||
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.japanese",
|
preinstalledImes.add(createDummyInputMethodInfo("com.android.apps.inputmethod.japanese",
|
||||||
"com.android.apps.inputmethod.japanese", "DummyJapaneseIme", !IS_AUX,
|
"com.android.apps.inputmethod.japanese", "DummyJapaneseIme", !IS_AUX,
|
||||||
IS_DEFAULT, subtypes));
|
isDefaultIme, subtypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
return preinstalledImes;
|
return preinstalledImes;
|
||||||
|
|||||||
Reference in New Issue
Block a user