use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by ResurrectionRemix.
the class TextServicesManagerService method calledFromValidUser.
// ---------------------------------------------------------------------------------------
// Check whether or not this is a valid IPC. Assumes an IPC is valid when either
// 1) it comes from the system process
// 2) the calling process' user id is identical to the current user id TSMS thinks.
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;
}
}
}
// support is implemented.
if (DBG) {
Slog.d(TAG, "--- IPC from userId:" + userId + " is being ignored. \n" + getStackTrace());
}
return false;
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by ResurrectionRemix.
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_packages_apps_Settings by LineageOS.
the class SpellCheckerPreference method setValue.
@Override
public void setValue(String value) {
super.setValue(value);
int index = value != null ? Integer.parseInt(value) : -1;
if (index == -1) {
mIntent = null;
return;
}
SpellCheckerInfo sci = mScis[index];
final String settingsActivity = sci.getSettingsActivity();
if (TextUtils.isEmpty(settingsActivity)) {
mIntent = null;
} else {
mIntent = new Intent(Intent.ACTION_MAIN);
mIntent.setClassName(sci.getPackageName(), settingsActivity);
}
}
use of android.view.textservice.SpellCheckerInfo in project android_packages_apps_Settings by LineageOS.
the class SpellCheckerPreferenceControllerTest method updateState_hasSpellerChecker_shouldSetSummaryToAppName.
@Test
public void updateState_hasSpellerChecker_shouldSetSummaryToAppName() {
final String spellCheckerAppLabel = "test";
final SpellCheckerInfo sci = mock(SpellCheckerInfo.class);
when(mTextServicesManager.isSpellCheckerEnabled()).thenReturn(true);
when(mTextServicesManager.getCurrentSpellChecker()).thenReturn(sci);
when(sci.loadLabel(mContext.getPackageManager())).thenReturn(spellCheckerAppLabel);
mController.updateState(mPreference);
assertThat(mPreference.getSummary()).isEqualTo(spellCheckerAppLabel);
}
use of android.view.textservice.SpellCheckerInfo in project android_frameworks_base by crdroidandroid.
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);
}
Aggregations