use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by ParanoidAndroid.
the class TextServicesManagerService method getCurrentSpellCheckerSubtype.
// TODO: Respect allowImplicitlySelectedSubtype
// TODO: Save SpellCheckerSubtype by supported languages by looking at "locale".
@Override
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale, boolean allowImplicitlySelectedSubtype) {
// TODO: Make this work even for non-current users?
if (!calledFromValidUser()) {
return null;
}
synchronized (mSpellCheckerMap) {
final String subtypeHashCodeStr = mSettings.getSelectedSpellCheckerSubtype();
if (DBG) {
Slog.w(TAG, "getCurrentSpellCheckerSubtype: " + subtypeHashCodeStr);
}
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
if (sci == null || sci.getSubtypeCount() == 0) {
if (DBG) {
Slog.w(TAG, "Subtype not found.");
}
return null;
}
final int hashCode;
if (!TextUtils.isEmpty(subtypeHashCodeStr)) {
hashCode = Integer.valueOf(subtypeHashCodeStr);
} else {
hashCode = 0;
}
if (hashCode == 0 && !allowImplicitlySelectedSubtype) {
return null;
}
String candidateLocale = null;
if (hashCode == 0) {
// Spell checker language settings == "auto"
final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
if (currentInputMethodSubtype != null) {
final String localeString = currentInputMethodSubtype.getLocale();
if (!TextUtils.isEmpty(localeString)) {
// 1. Use keyboard locale if available in the spell checker
candidateLocale = localeString;
}
}
}
if (candidateLocale == null) {
// 2. Use System locale if available in the spell checker
candidateLocale = mContext.getResources().getConfiguration().locale.toString();
}
}
SpellCheckerSubtype candidate = null;
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
if (hashCode == 0) {
final String scsLocale = scs.getLocale();
if (candidateLocale.equals(scsLocale)) {
return scs;
} else if (candidate == null) {
if (candidateLocale.length() >= 2 && scsLocale.length() >= 2 && candidateLocale.startsWith(scsLocale)) {
// Fall back to the applicable language
candidate = scs;
}
}
} else if (scs.hashCode() == hashCode) {
if (DBG) {
Slog.w(TAG, "Return subtype " + scs.hashCode() + ", input= " + locale + ", " + scs.getLocale());
}
// 3. Use the user specified spell check language
return scs;
}
}
// spell check languages
return candidate;
}
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by ParanoidAndroid.
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;
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by ParanoidAndroid.
the class TextServicesManagerService method switchUserLocked.
private void switchUserLocked(int userId) {
mSettings.setCurrentUserId(userId);
unbindServiceLocked();
buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap, mSettings);
SpellCheckerInfo sci = getCurrentSpellChecker(null);
if (sci == null) {
sci = findAvailSpellCheckerLocked(null, 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 ParanoidAndroid.
the class TextServicesManagerService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
pw.println("Permission Denial: can't dump TextServicesManagerService from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
return;
}
synchronized (mSpellCheckerMap) {
pw.println("Current Text Services Manager state:");
pw.println(" Spell Checker Map:");
for (Map.Entry<String, SpellCheckerInfo> ent : mSpellCheckerMap.entrySet()) {
pw.print(" ");
pw.print(ent.getKey());
pw.println(":");
SpellCheckerInfo info = ent.getValue();
pw.print(" ");
pw.print("id=");
pw.println(info.getId());
pw.print(" ");
pw.print("comp=");
pw.println(info.getComponent().toShortString());
int NS = info.getSubtypeCount();
for (int i = 0; i < NS; i++) {
SpellCheckerSubtype st = info.getSubtypeAt(i);
pw.print(" ");
pw.print("Subtype #");
pw.print(i);
pw.println(":");
pw.print(" ");
pw.print("locale=");
pw.println(st.getLocale());
pw.print(" ");
pw.print("extraValue=");
pw.println(st.getExtraValue());
}
}
pw.println("");
pw.println(" Spell Checker Bind Groups:");
for (Map.Entry<String, SpellCheckerBindGroup> ent : mSpellCheckerBindGroups.entrySet()) {
SpellCheckerBindGroup grp = ent.getValue();
pw.print(" ");
pw.print(ent.getKey());
pw.print(" ");
pw.print(grp);
pw.println(":");
pw.print(" ");
pw.print("mInternalConnection=");
pw.println(grp.mInternalConnection);
pw.print(" ");
pw.print("mSpellChecker=");
pw.println(grp.mSpellChecker);
pw.print(" ");
pw.print("mBound=");
pw.print(grp.mBound);
pw.print(" mConnected=");
pw.println(grp.mConnected);
int NL = grp.mListeners.size();
for (int i = 0; i < NL; i++) {
InternalDeathRecipient listener = grp.mListeners.get(i);
pw.print(" ");
pw.print("Listener #");
pw.print(i);
pw.println(":");
pw.print(" ");
pw.print("mTsListener=");
pw.println(listener.mTsListener);
pw.print(" ");
pw.print("mScListener=");
pw.println(listener.mScListener);
pw.print(" ");
pw.print("mGroup=");
pw.println(listener.mGroup);
pw.print(" ");
pw.print("mScLocale=");
pw.print(listener.mScLocale);
pw.print(" mUid=");
pw.println(listener.mUid);
}
}
}
}
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);
}
}
Aggregations