use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerService method setPermittedInputMethods.
@Override
public boolean setPermittedInputMethods(ComponentName who, List packageList) {
if (!mHasFeature) {
return false;
}
Preconditions.checkNotNull(who, "ComponentName is null");
// this restriction.
if (!checkCallerIsCurrentUserOrProfile()) {
return false;
}
if (packageList != null) {
// InputMethodManager fetches input methods for current user.
// So this can only be set when calling user is the current user
// or parent is current user in case of managed profiles.
InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class);
List<InputMethodInfo> enabledImes = inputMethodManager.getEnabledInputMethodList();
if (enabledImes != null) {
List<String> enabledPackages = new ArrayList<String>();
for (InputMethodInfo ime : enabledImes) {
enabledPackages.add(ime.getPackageName());
}
if (!checkPackagesInPermittedListOrSystem(enabledPackages, packageList, mInjector.binderGetCallingUserHandle().getIdentifier())) {
Slog.e(LOG_TAG, "Cannot set permitted input methods, " + "because it contains already enabled input method.");
return false;
}
}
}
synchronized (this) {
ActiveAdmin admin = getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
admin.permittedInputMethods = packageList;
saveSettingsLocked(UserHandle.getCallingUserId());
}
return true;
}
use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.
the class InputMethodUtils method getMostApplicableDefaultIME.
public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) {
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;
while (i > 0) {
i--;
final InputMethodInfo imi = enabledImes.get(i);
if (imi.isAuxiliaryIme()) {
continue;
}
if (InputMethodUtils.isSystemIme(imi) && containsSubtypeOf(imi, ENGLISH_LOCALE, false, /* checkCountry */
SUBTYPE_MODE_KEYBOARD)) {
return imi;
}
if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)) {
firstFoundSystemIme = i;
}
}
return enabledImes.get(Math.max(firstFoundSystemIme, 0));
}
use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.
the class InputMethodUtilsTest method testGetImplicitlyApplicableSubtypesLocked.
@SmallTest
public void testGetImplicitlyApplicableSubtypesLocked() throws Exception {
final InputMethodSubtype nonAutoEnUS = createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoEnGB = createDummyInputMethodSubtype("en_GB", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoEnIN = createDummyInputMethodSubtype("en_IN", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoFrCA = createDummyInputMethodSubtype("fr_CA", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoFr = createDummyInputMethodSubtype("fr_CA", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoFil = createDummyInputMethodSubtype("fil", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoIn = createDummyInputMethodSubtype("in", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoId = createDummyInputMethodSubtype("id", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype autoSubtype = createDummyInputMethodSubtype("auto", SUBTYPE_MODE_KEYBOARD, !IS_AUX, IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoJa = createDummyInputMethodSubtype("ja", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoHi = createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoSrCyrl = createDummyInputMethodSubtype("sr", "sr-Cyrl", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoSrLatn = createDummyInputMethodSubtype("sr_ZZ", "sr-Latn", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoHandwritingEn = createDummyInputMethodSubtype("en", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoHandwritingFr = createDummyInputMethodSubtype("fr", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoHandwritingSrCyrl = createDummyInputMethodSubtype("sr", "sr-Cyrl", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoHandwritingSrLatn = createDummyInputMethodSubtype("sr_ZZ", "sr-Latn", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype = createDummyInputMethodSubtype("zz", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
final InputMethodSubtype nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2 = createDummyInputMethodSubtype("zz", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
// Make sure that an automatic subtype (overridesImplicitlyEnabledSubtype:true) is
// selected no matter what locale is specified.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoEnGB);
subtypes.add(nonAutoJa);
subtypes.add(nonAutoFil);
// overridesImplicitlyEnabledSubtype == true
subtypes.add(autoSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_EN_US), imi);
assertEquals(1, result.size());
verifyEquality(autoSubtype, result.get(0));
}
// Make sure that a subtype whose locale is exactly equal to the specified locale is
// selected as long as there is no no automatic subtype
// (overridesImplicitlyEnabledSubtype:true) in the given list.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
// locale == "en_US"
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoEnGB);
subtypes.add(nonAutoJa);
subtypes.add(nonAutoFil);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_EN_US), imi);
assertEquals(2, result.size());
verifyEquality(nonAutoEnUS, result.get(0));
verifyEquality(nonAutoHandwritingEn, result.get(1));
}
// Make sure that a subtype whose locale is exactly equal to the specified locale is
// selected as long as there is no automatic subtype
// (overridesImplicitlyEnabledSubtype:true) in the given list.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
// locale == "en_GB"
subtypes.add(nonAutoEnGB);
subtypes.add(nonAutoJa);
subtypes.add(nonAutoFil);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_EN_GB), imi);
assertEquals(2, result.size());
verifyEquality(nonAutoEnGB, result.get(0));
verifyEquality(nonAutoHandwritingEn, result.get(1));
}
// If there is no automatic subtype (overridesImplicitlyEnabledSubtype:true) and
// any subtype whose locale is exactly equal to the specified locale in the given list,
// try to find a subtype whose language is equal to the language part of the given locale.
// Here make sure that a subtype (locale: "fr_CA") can be found with locale: "fr".
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
// locale == "fr_CA"
subtypes.add(nonAutoFrCA);
subtypes.add(nonAutoJa);
subtypes.add(nonAutoFil);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FR), imi);
assertEquals(2, result.size());
verifyEquality(nonAutoFrCA, result.get(0));
verifyEquality(nonAutoHandwritingFr, result.get(1));
}
// Then make sure that a subtype (locale: "fr") can be found with locale: "fr_CA".
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
// locale == "fr"
subtypes.add(nonAutoFr);
subtypes.add(nonAutoJa);
subtypes.add(nonAutoFil);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FR_CA), imi);
assertEquals(2, result.size());
verifyEquality(nonAutoFrCA, result.get(0));
verifyEquality(nonAutoHandwritingFr, result.get(1));
}
// Make sure that subtypes which have "EnabledWhenDefaultIsNotAsciiCapable" in its
// extra value is selected if and only if all other selected IMEs are not AsciiCapable.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
// not ASCII capable
subtypes.add(nonAutoJa);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
assertEquals(3, result.size());
verifyEquality(nonAutoJa, result.get(0));
verifyEquality(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, result.get(1));
verifyEquality(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2, result.get(2));
}
// Make sure that if there is no subtype that matches the language requested, then we just
// use the first keyboard subtype.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoHi);
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoHi, result.get(0));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoHi);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoEnUS, result.get(0));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoHi);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoEnUS, result.get(0));
}
// Make sure that both language and script are taken into account to find the best matching
// subtype.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoSrCyrl);
subtypes.add(nonAutoSrLatn);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
subtypes.add(nonAutoHandwritingSrCyrl);
subtypes.add(nonAutoHandwritingSrLatn);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(Locale.forLanguageTag("sr-Latn-RS")), imi);
assertEquals(2, result.size());
assertThat(nonAutoSrLatn, isIn(result));
assertThat(nonAutoHandwritingSrLatn, isIn(result));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoSrCyrl);
subtypes.add(nonAutoSrLatn);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
subtypes.add(nonAutoHandwritingSrCyrl);
subtypes.add(nonAutoHandwritingSrLatn);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(Locale.forLanguageTag("sr-Cyrl-RS")), imi);
assertEquals(2, result.size());
assertThat(nonAutoSrCyrl, isIn(result));
assertThat(nonAutoHandwritingSrCyrl, isIn(result));
}
// Make sure that secondary locales are taken into account to find the best matching
// subtype.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoEnGB);
subtypes.add(nonAutoSrCyrl);
subtypes.add(nonAutoSrLatn);
subtypes.add(nonAutoFr);
subtypes.add(nonAutoFrCA);
subtypes.add(nonAutoHandwritingEn);
subtypes.add(nonAutoHandwritingFr);
subtypes.add(nonAutoHandwritingSrCyrl);
subtypes.add(nonAutoHandwritingSrLatn);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(Locale.forLanguageTag("sr-Latn-RS-x-android"), Locale.forLanguageTag("ja-JP"), Locale.forLanguageTag("fr-FR"), Locale.forLanguageTag("en-GB"), Locale.forLanguageTag("en-US")), imi);
assertEquals(6, result.size());
assertThat(nonAutoEnGB, isIn(result));
assertThat(nonAutoFr, isIn(result));
assertThat(nonAutoSrLatn, isIn(result));
assertThat(nonAutoHandwritingEn, isIn(result));
assertThat(nonAutoHandwritingFr, isIn(result));
assertThat(nonAutoHandwritingSrLatn, isIn(result));
}
// Make sure that 3-letter language code can be handled.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoFil);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FIL_PH), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoFil, result.get(0));
}
// Make sure that we never end up matching "fi" (finnish) with "fil" (filipino).
// Also make sure that the first subtype will be used as the last-resort candidate.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoJa);
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoFil);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FI), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoJa, result.get(0));
}
// Make sure that "in" and "id" conversion is taken into account.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoIn);
subtypes.add(nonAutoEnUS);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_IN), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoIn, result.get(0));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoIn);
subtypes.add(nonAutoEnUS);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_ID), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoIn, result.get(0));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoId);
subtypes.add(nonAutoEnUS);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_IN), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoId, result.get(0));
}
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoId);
subtypes.add(nonAutoEnUS);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_ID), imi);
assertEquals(1, result.size());
verifyEquality(nonAutoId, result.get(0));
}
// If there is no automatic subtype (overridesImplicitlyEnabledSubtype:true) and the system
// provides multiple locales, we try to enable multiple subtypes.
{
final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
subtypes.add(nonAutoEnUS);
subtypes.add(nonAutoFrCA);
subtypes.add(nonAutoIn);
subtypes.add(nonAutoJa);
subtypes.add(nonAutoFil);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FR, LOCALE_EN_US, LOCALE_JA_JP), imi);
assertThat(nonAutoFrCA, isIn(result));
assertThat(nonAutoEnUS, isIn(result));
assertThat(nonAutoJa, isIn(result));
assertThat(nonAutoIn, not(isIn(result)));
assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(isIn(result)));
assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(isIn(result)));
}
}
use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.
the class InputMethodUtilsTest method createDummyInputMethodInfo.
private static InputMethodInfo createDummyInputMethodInfo(String packageName, String name, CharSequence label, boolean isAuxIme, boolean isDefault, List<InputMethodSubtype> subtypes) {
final ResolveInfo ri = new ResolveInfo();
final ServiceInfo si = new ServiceInfo();
final ApplicationInfo ai = new ApplicationInfo();
ai.packageName = packageName;
ai.enabled = true;
ai.flags |= ApplicationInfo.FLAG_SYSTEM;
si.applicationInfo = ai;
si.enabled = true;
si.packageName = packageName;
si.name = name;
si.exported = true;
si.nonLocalizedLabel = label;
ri.serviceInfo = si;
return new InputMethodInfo(ri, isAuxIme, "", subtypes, 1, isDefault);
}
use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by DirtyUnicorns.
the class AppRestrictionsHelper method addSystemImes.
/**
* Find all pre-installed input methods that are marked as default
* and add them to an exclusion list so that they aren't
* presented to the user for toggling.
* Don't add non-default ones, as they may include other stuff that we
* don't need to auto-include.
* @param excludePackages the set of package names to append to
*/
private void addSystemImes(Set<String> excludePackages) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> imis = imm.getInputMethodList();
for (InputMethodInfo imi : imis) {
try {
if (imi.isDefault(mContext) && isSystemPackage(imi.getPackageName())) {
excludePackages.add(imi.getPackageName());
}
} catch (Resources.NotFoundException rnfe) {
// Not default
}
}
}
Aggregations