use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by DirtyUnicorns.
the class InputMethodUtils method setNonSelectedSystemImesDisabledUntilUsed.
public static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager, List<InputMethodInfo> enabledImis, int userId, String callingPackage) {
if (DEBUG) {
Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
}
final String[] systemImesDisabledUntilUsed = Resources.getSystem().getStringArray(com.android.internal.R.array.config_disabledUntilUsedPreinstalledImes);
if (systemImesDisabledUntilUsed == null || systemImesDisabledUntilUsed.length == 0) {
return;
}
// Only the current spell checker should be treated as an enabled one.
final SpellCheckerInfo currentSpellChecker = TextServicesManager.getInstance().getCurrentSpellChecker();
for (final String packageName : systemImesDisabledUntilUsed) {
if (DEBUG) {
Slog.d(TAG, "check " + packageName);
}
boolean enabledIme = false;
for (int j = 0; j < enabledImis.size(); ++j) {
final InputMethodInfo imi = enabledImis.get(j);
if (packageName.equals(imi.getPackageName())) {
enabledIme = true;
break;
}
}
if (enabledIme) {
// enabled ime. skip
continue;
}
if (currentSpellChecker != null && packageName.equals(currentSpellChecker.getPackageName())) {
// enabled spell checker. skip
if (DEBUG) {
Slog.d(TAG, packageName + " is the current spell checker. skip");
}
continue;
}
ApplicationInfo ai = null;
try {
ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
} catch (RemoteException e) {
Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName + " userId=" + userId, e);
continue;
}
if (ai == null) {
// No app found for packageName
continue;
}
final boolean isSystemPackage = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
if (!isSystemPackage) {
continue;
}
setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
}
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.
the class TextServicesManagerService method findAvailSpellCheckerLocked.
private SpellCheckerInfo findAvailSpellCheckerLocked(String prefPackage) {
final int spellCheckersCount = mSpellCheckerList.size();
if (spellCheckersCount == 0) {
Slog.w(TAG, "no available spell checker services found");
return null;
}
if (prefPackage != null) {
for (int i = 0; i < spellCheckersCount; ++i) {
final SpellCheckerInfo sci = mSpellCheckerList.get(i);
if (prefPackage.equals(sci.getPackageName())) {
if (DBG) {
Slog.d(TAG, "findAvailSpellCheckerLocked: " + sci.getPackageName());
}
return sci;
}
}
}
// Look up a spell checker based on the system locale.
// TODO: Still there is a room to improve in the following logic: e.g., check if the package
// is pre-installed or not.
final Locale systemLocal = mContext.getResources().getConfiguration().locale;
final ArrayList<Locale> suitableLocales = InputMethodUtils.getSuitableLocalesForSpellChecker(systemLocal);
if (DBG) {
Slog.w(TAG, "findAvailSpellCheckerLocked suitableLocales=" + Arrays.toString(suitableLocales.toArray(new Locale[suitableLocales.size()])));
}
final int localeCount = suitableLocales.size();
for (int localeIndex = 0; localeIndex < localeCount; ++localeIndex) {
final Locale locale = suitableLocales.get(localeIndex);
for (int spellCheckersIndex = 0; spellCheckersIndex < spellCheckersCount; ++spellCheckersIndex) {
final SpellCheckerInfo info = mSpellCheckerList.get(spellCheckersIndex);
final int subtypeCount = info.getSubtypeCount();
for (int subtypeIndex = 0; subtypeIndex < subtypeCount; ++subtypeIndex) {
final SpellCheckerSubtype subtype = info.getSubtypeAt(subtypeIndex);
final Locale subtypeLocale = InputMethodUtils.constructLocaleFromString(subtype.getLocale());
if (locale.equals(subtypeLocale)) {
// returning the first found one.
return info;
}
}
}
}
if (spellCheckersCount > 1) {
Slog.w(TAG, "more than one spell checker service found, picking first");
}
return mSpellCheckerList.get(0);
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.
the class TextServicesManagerService method buildSpellCheckerMapLocked.
private static void buildSpellCheckerMapLocked(Context context, ArrayList<SpellCheckerInfo> list, HashMap<String, SpellCheckerInfo> map, TextServicesSettings settings) {
list.clear();
map.clear();
final PackageManager pm = context.getPackageManager();
// Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default
// behavior of PackageManager is exactly what we want. It by default picks up appropriate
// services depending on the unlock state for the specified user.
final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(SpellCheckerService.SERVICE_INTERFACE), PackageManager.GET_META_DATA, settings.getCurrentUserId());
final int N = services.size();
for (int i = 0; i < N; ++i) {
final ResolveInfo ri = services.get(i);
final ServiceInfo si = ri.serviceInfo;
final ComponentName compName = new ComponentName(si.packageName, si.name);
if (!android.Manifest.permission.BIND_TEXT_SERVICE.equals(si.permission)) {
Slog.w(TAG, "Skipping text service " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_TEXT_SERVICE);
continue;
}
if (DBG)
Slog.d(TAG, "Add: " + compName);
try {
final SpellCheckerInfo sci = new SpellCheckerInfo(context, ri);
if (sci.getSubtypeCount() <= 0) {
Slog.w(TAG, "Skipping text service " + compName + ": it does not contain subtypes.");
continue;
}
list.add(sci);
map.put(sci.getId(), sci);
} catch (XmlPullParserException e) {
Slog.w(TAG, "Unable to load the spell checker " + compName, e);
} catch (IOException e) {
Slog.w(TAG, "Unable to load the spell checker " + compName, e);
}
}
if (DBG) {
Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
}
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.
the class TextServicesManagerService method resetInternalState.
private void resetInternalState(@UserIdInt int userId) {
final boolean useCopyOnWriteSettings = !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(userId);
mSettings.switchCurrentUser(userId, useCopyOnWriteSettings);
updateCurrentProfileIds();
unbindServiceLocked();
buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap, mSettings);
SpellCheckerInfo sci = getCurrentSpellChecker(null);
if (sci == null) {
sci = findAvailSpellCheckerLocked(null);
if (sci != null) {
// Set the current spell checker if there is one or more spell checkers
// available. In this case, "sci" is the first one in the available spell
// checkers.
setCurrentSpellCheckerLocked(sci.getId());
}
}
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by AOSPA.
the class TextServicesManagerService method setCurrentSpellCheckerSubtypeLocked.
private void setCurrentSpellCheckerSubtypeLocked(int hashCode) {
if (DBG) {
Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
}
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
int tempHashCode = 0;
for (int i = 0; sci != null && i < sci.getSubtypeCount(); ++i) {
if (sci.getSubtypeAt(i).hashCode() == hashCode) {
tempHashCode = hashCode;
break;
}
}
final long ident = Binder.clearCallingIdentity();
try {
mSettings.putSelectedSpellCheckerSubtype(tempHashCode);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
Aggregations