Search in sources :

Example 6 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by ParanoidAndroid.

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);
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 7 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project platform_frameworks_base by android.

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);
    }
}
Also used : SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 8 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project platform_frameworks_base by android.

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());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 9 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project platform_frameworks_base by android.

the class TextServicesManagerService method getSpellCheckerService.

@Override
public void getSpellCheckerService(String sciId, String locale, ITextServicesSessionListener tsListener, ISpellCheckerSessionListener scListener, Bundle bundle) {
    if (!calledFromValidUser()) {
        return;
    }
    if (!mSystemReady) {
        return;
    }
    if (TextUtils.isEmpty(sciId) || tsListener == null || scListener == null) {
        Slog.e(TAG, "getSpellCheckerService: Invalid input.");
        return;
    }
    synchronized (mSpellCheckerMap) {
        if (!mSpellCheckerMap.containsKey(sciId)) {
            return;
        }
        final SpellCheckerInfo sci = mSpellCheckerMap.get(sciId);
        final int uid = Binder.getCallingUid();
        if (mSpellCheckerBindGroups.containsKey(sciId)) {
            final SpellCheckerBindGroup bindGroup = mSpellCheckerBindGroups.get(sciId);
            if (bindGroup != null) {
                final InternalDeathRecipient recipient = mSpellCheckerBindGroups.get(sciId).addListener(tsListener, locale, scListener, uid, bundle);
                if (recipient == null) {
                    if (DBG) {
                        Slog.w(TAG, "Didn't create a death recipient.");
                    }
                    return;
                }
                if (bindGroup.mSpellChecker == null & bindGroup.mConnected) {
                    Slog.e(TAG, "The state of the spell checker bind group is illegal.");
                    bindGroup.removeAll();
                } else if (bindGroup.mSpellChecker != null) {
                    if (DBG) {
                        Slog.w(TAG, "Existing bind found. Return a spell checker session now. " + "Listeners count = " + bindGroup.mListeners.size());
                    }
                    try {
                        final ISpellCheckerSession session = bindGroup.mSpellChecker.getISpellCheckerSession(recipient.mScLocale, recipient.mScListener, bundle);
                        if (session != null) {
                            tsListener.onServiceConnected(session);
                            return;
                        } else {
                            if (DBG) {
                                Slog.w(TAG, "Existing bind already expired. ");
                            }
                            bindGroup.removeAll();
                        }
                    } catch (RemoteException e) {
                        Slog.e(TAG, "Exception in getting spell checker session: " + e);
                        bindGroup.removeAll();
                    }
                }
            }
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            startSpellCheckerServiceInnerLocked(sci, locale, tsListener, scListener, uid, bundle);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
    return;
}
Also used : ISpellCheckerSession(com.android.internal.textservice.ISpellCheckerSession) RemoteException(android.os.RemoteException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 10 with SpellCheckerInfo

use of android.view.textservice.SpellCheckerInfo in project platform_frameworks_base by android.

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);
}
Also used : Locale(java.util.Locale) SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Aggregations

SpellCheckerInfo (android.view.textservice.SpellCheckerInfo)62 RemoteException (android.os.RemoteException)16 SpellCheckerSubtype (android.view.textservice.SpellCheckerSubtype)13 ServiceInfo (android.content.pm.ServiceInfo)11 Locale (java.util.Locale)10 Intent (android.content.Intent)7 ComponentName (android.content.ComponentName)6 ApplicationInfo (android.content.pm.ApplicationInfo)6 PackageManager (android.content.pm.PackageManager)6 ResolveInfo (android.content.pm.ResolveInfo)6 InputMethodInfo (android.view.inputmethod.InputMethodInfo)6 InputMethodManager (android.view.inputmethod.InputMethodManager)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 ISpellCheckerSession (com.android.internal.textservice.ISpellCheckerSession)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1