summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2015-06-26 18:02:54 -0700
committerYohei Yukawa <yukawa@google.com>2015-06-26 18:02:54 -0700
commit174843afb629c57af19e14ee3ec4a91358061dd9 (patch)
treedc769b528135728d9f0aee8dac0a9d26476f2417 /services
parent1fa8290dbec37519576d346ba9ae8bbe20b64aa9 (diff)
downloadframeworks_base-174843afb629c57af19e14ee3ec4a91358061dd9.zip
frameworks_base-174843afb629c57af19e14ee3ec4a91358061dd9.tar.gz
frameworks_base-174843afb629c57af19e14ee3ec4a91358061dd9.tar.bz2
Check system locale when picking up an initial SpellChecker.
Since Ia25e7b4f308778891929e31b8cbd741f6848cce4, the TSMS has picked up the first found spell checker no matter regardless of the system locale. The primary goal of this CL is to introduce a low-risk fix for the situation where two or more spell checker services are pre-installed but they are well different from each other in terms of supported languages. Solving the problem in more ambiguous and complicated situation is beyond the goal of this CL. With this CL, we still pick up the first found spell checker but also require the spell checker supports a certain locale. We will try several locales starting with the system locale to some fallback locales until we find one appropriate spell checker. If no spell checker is picked up in this process, we simply pick up the first one as we have done. Examples about what locales will be checked are: A. System locale: en_US 1. en_US 2. en_GB 3. en B. System locale: en 1. en 2. en_US 3. en_GB C. System locale: en_IN 1. en_IN 2. en_US 3. en_GB 4. en D. System locale: ja_JP 1. ja_JP 2. ja 3. en_US 4. en_GB 5. en E. System locale: fil_PH 1. fil_PH 2. fil 3. en_US 4. en_GB 5. en F. System locale: th_TH_TH 1. th_TH_TH 2. th_TH 3. th 4. en_US 5. en_GB 6. en Bug: 22042994 Change-Id: I094f1c33430f7904a1dac6167431d6df64a07212
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/TextServicesManagerService.java42
1 files changed, 38 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java
index 5bce6eb..aace66c 100644
--- a/services/core/java/com/android/server/TextServicesManagerService.java
+++ b/services/core/java/com/android/server/TextServicesManagerService.java
@@ -18,6 +18,7 @@ package com.android.server;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.PackageMonitor;
+import com.android.internal.inputmethod.InputMethodUtils;
import com.android.internal.textservice.ISpellCheckerService;
import com.android.internal.textservice.ISpellCheckerSession;
import com.android.internal.textservice.ISpellCheckerSessionListener;
@@ -61,9 +62,11 @@ import android.view.textservice.SpellCheckerSubtype;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -141,7 +144,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap, mSettings);
SpellCheckerInfo sci = getCurrentSpellChecker(null);
if (sci == null) {
- sci = findAvailSpellCheckerLocked(null, 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
@@ -190,7 +193,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
change == PACKAGE_PERMANENT_CHANGE || change == PACKAGE_TEMPORARY_CHANGE
// Package modified
|| isPackageModified(packageName)) {
- sci = findAvailSpellCheckerLocked(null, packageName);
+ sci = findAvailSpellCheckerLocked(packageName);
if (sci != null) {
setCurrentSpellCheckerLocked(sci.getId());
}
@@ -331,8 +334,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
mSpellCheckerBindGroups.clear();
}
- // TODO: find an appropriate spell checker for specified locale
- private SpellCheckerInfo findAvailSpellCheckerLocked(String locale, String prefPackage) {
+ private SpellCheckerInfo findAvailSpellCheckerLocked(String prefPackage) {
final int spellCheckersCount = mSpellCheckerList.size();
if (spellCheckersCount == 0) {
Slog.w(TAG, "no available spell checker services found");
@@ -349,6 +351,38 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
}
}
}
+
+ // 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)) {
+ // TODO: We may have more spell checkers that fall into this category.
+ // Ideally we should pick up the most suitable one instead of simply
+ // returning the first found one.
+ return info;
+ }
+ }
+ }
+ }
+
if (spellCheckersCount > 1) {
Slog.w(TAG, "more than one spell checker service found, picking first");
}