Methods Summary |
---|
private boolean | bindCurrentSpellCheckerService(android.content.Intent service, android.content.ServiceConnection conn, int flags)
if (service == null || conn == null) {
Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
return false;
}
return mContext.bindServiceAsUser(service, conn, flags,
new UserHandle(mSettings.getCurrentUserId()));
|
private static void | buildSpellCheckerMapLocked(android.content.Context context, java.util.ArrayList list, java.util.HashMap map, com.android.server.TextServicesManagerService$TextServicesSettings settings)
list.clear();
map.clear();
final PackageManager pm = context.getPackageManager();
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());
}
|
private boolean | calledFromValidUser()
final int uid = Binder.getCallingUid();
final int userId = UserHandle.getUserId(uid);
if (DBG) {
Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
+ "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
+ " calling userId = " + userId + ", foreground user id = "
+ mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid());
try {
final String[] packageNames = AppGlobals.getPackageManager().getPackagesForUid(uid);
for (int i = 0; i < packageNames.length; ++i) {
if (DBG) {
Slog.d(TAG, "--- process name for "+ uid + " = " + packageNames[i]);
}
}
} catch (RemoteException e) {
}
}
if (uid == Process.SYSTEM_UID || userId == mSettings.getCurrentUserId()) {
return true;
}
// Permits current profile to use TSFM as long as the current text service is the system's
// one. This is a tentative solution and should be replaced with fully functional multiuser
// support.
// TODO: Implement multiuser support in TSMS.
final boolean isCurrentProfile = mSettings.isCurrentProfile(userId);
if (DBG) {
Slog.d(TAG, "--- userId = "+ userId + " isCurrentProfile = " + isCurrentProfile);
}
if (mSettings.isCurrentProfile(userId)) {
final SpellCheckerInfo spellCheckerInfo = getCurrentSpellCheckerWithoutVerification();
if (spellCheckerInfo != null) {
final ServiceInfo serviceInfo = spellCheckerInfo.getServiceInfo();
final boolean isSystemSpellChecker =
(serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
if (DBG) {
Slog.d(TAG, "--- current spell checker = "+ spellCheckerInfo.getPackageName()
+ " isSystem = " + isSystemSpellChecker);
}
if (isSystemSpellChecker) {
return true;
}
}
}
// Unlike InputMethodManagerService#calledFromValidUser, INTERACT_ACROSS_USERS_FULL isn't
// taken into account here. Anyway this method is supposed to be removed once multiuser
// support is implemented.
if (DBG) {
Slog.d(TAG, "--- IPC from userId:" + userId + " is being ignored. \n"
+ getStackTrace());
}
return false;
|
protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.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);
}
}
}
|
private android.view.textservice.SpellCheckerInfo | findAvailSpellCheckerLocked(java.lang.String locale, java.lang.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;
}
}
}
if (spellCheckersCount > 1) {
Slog.w(TAG, "more than one spell checker service found, picking first");
}
return mSpellCheckerList.get(0);
|
public void | finishSpellCheckerService(com.android.internal.textservice.ISpellCheckerSessionListener listener)
if (!calledFromValidUser()) {
return;
}
if (DBG) {
Slog.d(TAG, "FinishSpellCheckerService");
}
synchronized(mSpellCheckerMap) {
final ArrayList<SpellCheckerBindGroup> removeList =
new ArrayList<SpellCheckerBindGroup>();
for (SpellCheckerBindGroup group : mSpellCheckerBindGroups.values()) {
if (group == null) continue;
// Use removeList to avoid modifying mSpellCheckerBindGroups in this loop.
removeList.add(group);
}
final int removeSize = removeList.size();
for (int i = 0; i < removeSize; ++i) {
removeList.get(i).removeListener(listener);
}
}
|
public android.view.textservice.SpellCheckerInfo | getCurrentSpellChecker(java.lang.String locale)
// TODO: Make this work even for non-current users?
if (!calledFromValidUser()) {
return null;
}
return getCurrentSpellCheckerWithoutVerification();
|
public android.view.textservice.SpellCheckerSubtype | getCurrentSpellCheckerSubtype(java.lang.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;
}
}
// 4. Fall back to the applicable language and return it if not null
// 5. Simply just return it even if it's null which means we could find no suitable
// spell check languages
return candidate;
}
|
private android.view.textservice.SpellCheckerInfo | getCurrentSpellCheckerWithoutVerification()
synchronized (mSpellCheckerMap) {
final String curSpellCheckerId = mSettings.getSelectedSpellChecker();
if (DBG) {
Slog.w(TAG, "getCurrentSpellChecker: " + curSpellCheckerId);
}
if (TextUtils.isEmpty(curSpellCheckerId)) {
return null;
}
return mSpellCheckerMap.get(curSpellCheckerId);
}
|
public android.view.textservice.SpellCheckerInfo[] | getEnabledSpellCheckers()
// TODO: Make this work even for non-current users?
if (!calledFromValidUser()) {
return null;
}
if (DBG) {
Slog.d(TAG, "getEnabledSpellCheckers: " + mSpellCheckerList.size());
for (int i = 0; i < mSpellCheckerList.size(); ++i) {
Slog.d(TAG, "EnabledSpellCheckers: " + mSpellCheckerList.get(i).getPackageName());
}
}
return mSpellCheckerList.toArray(new SpellCheckerInfo[mSpellCheckerList.size()]);
|
public void | getSpellCheckerService(java.lang.String sciId, java.lang.String locale, com.android.internal.textservice.ITextServicesSessionListener tsListener, com.android.internal.textservice.ISpellCheckerSessionListener scListener, android.os.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;
|
private static java.lang.String | getStackTrace()
final StringBuilder sb = new StringBuilder();
try {
throw new RuntimeException();
} catch (RuntimeException e) {
final StackTraceElement[] frames = e.getStackTrace();
// Start at 1 because the first frame is here and we don't care about it
for (int j = 1; j < frames.length; ++j) {
sb.append(frames[j].toString() + "\n");
}
}
return sb.toString();
|
public boolean | isSpellCheckerEnabled()
if (!calledFromValidUser()) {
return false;
}
synchronized(mSpellCheckerMap) {
return isSpellCheckerEnabledLocked();
}
|
private boolean | isSpellCheckerEnabledLocked()
final long ident = Binder.clearCallingIdentity();
try {
final boolean retval = mSettings.isSpellCheckerEnabled();
if (DBG) {
Slog.w(TAG, "getSpellCheckerEnabled: " + retval);
}
return retval;
} finally {
Binder.restoreCallingIdentity(ident);
}
|
public void | setCurrentSpellChecker(java.lang.String locale, java.lang.String sciId)
if (!calledFromValidUser()) {
return;
}
synchronized(mSpellCheckerMap) {
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException(
"Requires permission "
+ android.Manifest.permission.WRITE_SECURE_SETTINGS);
}
setCurrentSpellCheckerLocked(sciId);
}
|
private void | setCurrentSpellCheckerLocked(java.lang.String sciId)
if (DBG) {
Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
}
if (TextUtils.isEmpty(sciId) || !mSpellCheckerMap.containsKey(sciId)) return;
final SpellCheckerInfo currentSci = getCurrentSpellChecker(null);
if (currentSci != null && currentSci.getId().equals(sciId)) {
// Do nothing if the current spell checker is same as new spell checker.
return;
}
final long ident = Binder.clearCallingIdentity();
try {
mSettings.putSelectedSpellChecker(sciId);
setCurrentSpellCheckerSubtypeLocked(0);
} finally {
Binder.restoreCallingIdentity(ident);
}
|
public void | setCurrentSpellCheckerSubtype(java.lang.String locale, int hashCode)
if (!calledFromValidUser()) {
return;
}
synchronized(mSpellCheckerMap) {
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException(
"Requires permission "
+ android.Manifest.permission.WRITE_SECURE_SETTINGS);
}
setCurrentSpellCheckerSubtypeLocked(hashCode);
}
|
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);
}
|
public void | setSpellCheckerEnabled(boolean enabled)
if (!calledFromValidUser()) {
return;
}
synchronized(mSpellCheckerMap) {
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException(
"Requires permission "
+ android.Manifest.permission.WRITE_SECURE_SETTINGS);
}
setSpellCheckerEnabledLocked(enabled);
}
|
private void | setSpellCheckerEnabledLocked(boolean enabled)
if (DBG) {
Slog.w(TAG, "setSpellCheckerEnabled: " + enabled);
}
final long ident = Binder.clearCallingIdentity();
try {
mSettings.setSpellCheckerEnabled(enabled);
} finally {
Binder.restoreCallingIdentity(ident);
}
|
private void | startSpellCheckerServiceInnerLocked(android.view.textservice.SpellCheckerInfo info, java.lang.String locale, com.android.internal.textservice.ITextServicesSessionListener tsListener, com.android.internal.textservice.ISpellCheckerSessionListener scListener, int uid, android.os.Bundle bundle)
if (DBG) {
Slog.w(TAG, "Start spell checker session inner locked.");
}
final String sciId = info.getId();
final InternalServiceConnection connection = new InternalServiceConnection(
sciId, locale, bundle);
final Intent serviceIntent = new Intent(SpellCheckerService.SERVICE_INTERFACE);
serviceIntent.setComponent(info.getComponent());
if (DBG) {
Slog.w(TAG, "bind service: " + info.getId());
}
if (!bindCurrentSpellCheckerService(serviceIntent, connection, Context.BIND_AUTO_CREATE)) {
Slog.e(TAG, "Failed to get a spell checker service.");
return;
}
final SpellCheckerBindGroup group = new SpellCheckerBindGroup(
connection, tsListener, locale, scListener, uid, bundle);
mSpellCheckerBindGroups.put(sciId, group);
|
private void | switchUserLocked(int userId)
mSettings.setCurrentUserId(userId);
updateCurrentProfileIds();
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());
}
}
|
public void | systemRunning()
if (!mSystemReady) {
mSystemReady = true;
}
|
private void | unbindServiceLocked()
for (SpellCheckerBindGroup scbg : mSpellCheckerBindGroups.values()) {
scbg.removeAll();
}
mSpellCheckerBindGroups.clear();
|
void | updateCurrentProfileIds()
List<UserInfo> profiles =
UserManager.get(mContext).getProfiles(mSettings.getCurrentUserId());
int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null
for (int i = 0; i < currentProfileIds.length; i++) {
currentProfileIds[i] = profiles.get(i).id;
}
mSettings.setCurrentProfileIds(currentProfileIds);
|