am d6a8adcb: Cleanup in preparation of distracter change.

* commit 'd6a8adcb044dd8b73a1c96776a835b411a978b46':
  Cleanup in preparation of distracter change.
main
Dan Zivkovic 2015-02-06 22:29:27 +00:00 committed by Android Git Automerger
commit 3237983b37
8 changed files with 34 additions and 61 deletions

View File

@ -113,24 +113,22 @@ public interface DictionaryFacilitator {
boolean isConfidentAboutCurrentLanguageBeing(final Locale mLocale); boolean isConfidentAboutCurrentLanguageBeing(final Locale mLocale);
void resetDictionaries(final Context context, final Locale[] newLocales, void resetDictionaries(
final boolean useContactsDict, final boolean usePersonalizedDicts, final Context context,
final boolean forceReloadMainDictionary,
@Nullable final String account,
final DictionaryInitializationListener listener);
void resetDictionariesWithDictNamePrefix(final Context context,
final Locale[] newLocales, final Locale[] newLocales,
final boolean useContactsDict, final boolean useContactsDict,
final boolean usePersonalizedDicts, final boolean usePersonalizedDicts,
final boolean forceReloadMainDictionary, final boolean forceReloadMainDictionary,
@Nullable final DictionaryInitializationListener listener, @Nullable final String account,
final String dictNamePrefix, final String dictNamePrefix,
@Nullable final String account); @Nullable final DictionaryInitializationListener listener);
@UsedForTesting @UsedForTesting
void resetDictionariesForTesting(final Context context, final Locale[] locales, void resetDictionariesForTesting(
final ArrayList<String> dictionaryTypes, final HashMap<String, File> dictionaryFiles, final Context context,
final Locale[] locales,
final ArrayList<String> dictionaryTypes,
final HashMap<String, File> dictionaryFiles,
final Map<String, Map<String, String>> additionalDictAttributes, final Map<String, Map<String, String>> additionalDictAttributes,
@Nullable final String account); @Nullable final String account);

View File

@ -342,16 +342,6 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
} }
public void resetDictionaries(final Context context, final Locale[] newLocales,
final boolean useContactsDict, final boolean usePersonalizedDicts,
final boolean forceReloadMainDictionary,
@Nullable final String account,
final DictionaryInitializationListener listener) {
resetDictionariesWithDictNamePrefix(context, newLocales, useContactsDict,
usePersonalizedDicts, forceReloadMainDictionary, listener, "" /* dictNamePrefix */,
account);
}
@Nullable @Nullable
static DictionaryGroup findDictionaryGroupWithLocale(final DictionaryGroup[] dictionaryGroups, static DictionaryGroup findDictionaryGroupWithLocale(final DictionaryGroup[] dictionaryGroups,
final Locale locale) { final Locale locale) {
@ -363,14 +353,15 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
return null; return null;
} }
public void resetDictionariesWithDictNamePrefix(final Context context, public void resetDictionaries(
final Context context,
final Locale[] newLocales, final Locale[] newLocales,
final boolean useContactsDict, final boolean useContactsDict,
final boolean usePersonalizedDicts, final boolean usePersonalizedDicts,
final boolean forceReloadMainDictionary, final boolean forceReloadMainDictionary,
@Nullable final DictionaryInitializationListener listener, @Nullable final String account,
final String dictNamePrefix, final String dictNamePrefix,
@Nullable final String account) { @Nullable final DictionaryInitializationListener listener) {
final HashMap<Locale, ArrayList<String>> existingDictionariesToCleanup = new HashMap<>(); final HashMap<Locale, ArrayList<String>> existingDictionariesToCleanup = new HashMap<>();
// TODO: Make subDictTypesToUse configurable by resource or a static final list. // TODO: Make subDictTypesToUse configurable by resource or a static final list.
final HashSet<String> subDictTypesToUse = new HashSet<>(); final HashSet<String> subDictTypesToUse = new HashSet<>();

View File

@ -28,10 +28,11 @@ import android.util.LruCache;
/** /**
* Cache for dictionary facilitators of multiple locales. * Cache for dictionary facilitators of multiple locales.
* This class automatically creates and releases facilitator instances using LRU policy. * This class automatically creates and releases up to 3 facilitator instances using LRU policy.
*/ */
public class DictionaryFacilitatorLruCache { public class DictionaryFacilitatorLruCache {
static final String TAG = DictionaryFacilitatorLruCache.class.getSimpleName(); private static final String TAG = "DictionaryFacilitatorLruCache";
private static final int MAX_DICTIONARY_FACILITATOR_COUNT = 3;
private static final int WAIT_FOR_LOADING_MAIN_DICT_IN_MILLISECONDS = 1000; private static final int WAIT_FOR_LOADING_MAIN_DICT_IN_MILLISECONDS = 1000;
private static final int MAX_RETRY_COUNT_FOR_WAITING_FOR_LOADING_DICT = 5; private static final int MAX_RETRY_COUNT_FOR_WAITING_FOR_LOADING_DICT = 5;
@ -74,10 +75,10 @@ public class DictionaryFacilitatorLruCache {
private final Object mLock = new Object(); private final Object mLock = new Object();
private boolean mUseContactsDictionary = false; private boolean mUseContactsDictionary = false;
public DictionaryFacilitatorLruCache(final Context context, final int maxSize, public DictionaryFacilitatorLruCache(final Context context, final String dictionaryNamePrefix) {
final String dictionaryNamePrefix) {
mContext = context; mContext = context;
mLruCache = new DictionaryFacilitatorLruCacheInner(mCachedLocales, maxSize); mLruCache = new DictionaryFacilitatorLruCacheInner(
mCachedLocales, MAX_DICTIONARY_FACILITATOR_COUNT);
mDictionaryNamePrefix = dictionaryNamePrefix; mDictionaryNamePrefix = dictionaryNamePrefix;
} }
@ -103,11 +104,10 @@ public class DictionaryFacilitatorLruCache {
private void resetDictionariesForLocaleLocked(final DictionaryFacilitator dictionaryFacilitator, private void resetDictionariesForLocaleLocked(final DictionaryFacilitator dictionaryFacilitator,
final Locale locale) { final Locale locale) {
// Note: Given that personalized dictionaries are not used here; we can pass null account. // Note: Given that personalized dictionaries are not used here; we can pass null account.
dictionaryFacilitator.resetDictionariesWithDictNamePrefix(mContext, new Locale[] { locale }, dictionaryFacilitator.resetDictionaries(mContext, new Locale[]{locale},
mUseContactsDictionary, false /* usePersonalizedDicts */, mUseContactsDictionary, false /* usePersonalizedDicts */,
false /* forceReloadMainDictionary */, null /* listener */, false /* forceReloadMainDictionary */, null /* account */,
mDictionaryNamePrefix, mDictionaryNamePrefix, null /* listener */);
null /* account */);
} }
public void setUseContactsDictionary(final boolean useContectsDictionary) { public void setUseContactsDictionary(final boolean useContectsDictionary) {

View File

@ -679,7 +679,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mDictionaryFacilitator.resetDictionaries(this /* context */, locales, mDictionaryFacilitator.resetDictionaries(this /* context */, locales,
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
false /* forceReloadMainDictionary */, false /* forceReloadMainDictionary */,
settingsValues.mAccount, settingsValues.mAccount, "" /* dictNamePrefix */,
this /* DictionaryInitializationListener */); this /* DictionaryInitializationListener */);
if (settingsValues.mAutoCorrectionEnabledPerUserSettings) { if (settingsValues.mAutoCorrectionEnabledPerUserSettings) {
mInputLogic.mSuggest.setAutoCorrectionThreshold( mInputLogic.mSuggest.setAutoCorrectionThreshold(
@ -697,7 +697,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mDictionaryFacilitator.getLocales(), settingsValues.mUseContactsDict, mDictionaryFacilitator.getLocales(), settingsValues.mUseContactsDict,
settingsValues.mUsePersonalizedDicts, settingsValues.mUsePersonalizedDicts,
true /* forceReloadMainDictionary */, true /* forceReloadMainDictionary */,
settingsValues.mAccount, settingsValues.mAccount, "" /* dictNamePrefix */,
this /* DictionaryInitializationListener */); this /* DictionaryInitializationListener */);
} }
@ -1810,7 +1810,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mDictionaryFacilitator.resetDictionaries(this, new Locale[] { locale }, mDictionaryFacilitator.resetDictionaries(this, new Locale[] { locale },
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
false /* forceReloadMainDictionary */, false /* forceReloadMainDictionary */,
settingsValues.mAccount, settingsValues.mAccount, "", /* dictionaryNamePrefix */
this /* DictionaryInitializationListener */); this /* DictionaryInitializationListener */);
} }

View File

@ -17,8 +17,6 @@
package com.android.inputmethod.latin.personalization; package com.android.inputmethod.latin.personalization;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.android.inputmethod.annotations.ExternallyReferenced; import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
@ -27,7 +25,6 @@ import com.android.inputmethod.latin.ExpandableBinaryDictionary;
import com.android.inputmethod.latin.NgramContext; import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.define.ProductionFlags; import com.android.inputmethod.latin.define.ProductionFlags;
import com.android.inputmethod.latin.settings.LocalSettingsConstants;
import com.android.inputmethod.latin.utils.DistracterFilter; import com.android.inputmethod.latin.utils.DistracterFilter;
import java.io.File; import java.io.File;

View File

@ -67,10 +67,8 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
// TODO: Make each spell checker session has its own session id. // TODO: Make each spell checker session has its own session id.
private final ConcurrentLinkedQueue<Integer> mSessionIdPool = new ConcurrentLinkedQueue<>(); private final ConcurrentLinkedQueue<Integer> mSessionIdPool = new ConcurrentLinkedQueue<>();
private static final int MAX_DICTIONARY_FACILITATOR_COUNT = 3;
private final DictionaryFacilitatorLruCache mDictionaryFacilitatorCache = private final DictionaryFacilitatorLruCache mDictionaryFacilitatorCache =
new DictionaryFacilitatorLruCache(this /* context */, MAX_DICTIONARY_FACILITATOR_COUNT, new DictionaryFacilitatorLruCache(this /* context */, DICTIONARY_NAME_PREFIX);
DICTIONARY_NAME_PREFIX);
private final ConcurrentHashMap<Locale, Keyboard> mKeyboardCache = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Locale, Keyboard> mKeyboardCache = new ConcurrentHashMap<>();
// The threshold for a suggestion to be considered "recommended". // The threshold for a suggestion to be considered "recommended".

View File

@ -53,7 +53,6 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
DistracterFilterCheckingExactMatchesAndSuggestions.class.getSimpleName(); DistracterFilterCheckingExactMatchesAndSuggestions.class.getSimpleName();
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final int MAX_DICTIONARY_FACILITATOR_CACHE_SIZE = 3;
private static final int MAX_DISTRACTERS_CACHE_SIZE = 1024; private static final int MAX_DISTRACTERS_CACHE_SIZE = 1024;
private final Context mContext; private final Context mContext;
@ -81,8 +80,8 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
mContext = context; mContext = context;
mLocaleToSubtypeCache = new ConcurrentHashMap<>(); mLocaleToSubtypeCache = new ConcurrentHashMap<>();
mLocaleToKeyboardCache = new ConcurrentHashMap<>(); mLocaleToKeyboardCache = new ConcurrentHashMap<>();
mDictionaryFacilitatorLruCache = new DictionaryFacilitatorLruCache(context, mDictionaryFacilitatorLruCache = new DictionaryFacilitatorLruCache(
MAX_DICTIONARY_FACILITATOR_CACHE_SIZE, "" /* dictionaryNamePrefix */); context, "" /* dictionaryNamePrefix */);
mDistractersCache = new LruCache<>(MAX_DISTRACTERS_CACHE_SIZE); mDistractersCache = new LruCache<>(MAX_DISTRACTERS_CACHE_SIZE);
} }

View File

@ -23,12 +23,9 @@ import android.test.suitebuilder.annotation.LargeTest;
@LargeTest @LargeTest
public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase { public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
static final int MAX_CACHE_SIZE = 2;
static final int MAX_CACHE_SIZE_LARGE = 5;
public void testCacheSize() { public void testCacheSize() {
final DictionaryFacilitatorLruCache cache = final DictionaryFacilitatorLruCache cache =
new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, ""); new DictionaryFacilitatorLruCache(getContext(), "");
assertEquals(0, cache.getCachedLocalesForTesting().size()); assertEquals(0, cache.getCachedLocalesForTesting().size());
assertNotNull(cache.get(Locale.US)); assertNotNull(cache.get(Locale.US));
@ -42,12 +39,9 @@ public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
} }
public void testGetFacilitator() { public void testGetFacilitator() {
testGetFacilitator(new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, "")); final DictionaryFacilitatorLruCache cache =
testGetFacilitator(new DictionaryFacilitatorLruCache( new DictionaryFacilitatorLruCache(getContext(), "");
getContext(), MAX_CACHE_SIZE_LARGE, ""));
}
private static void testGetFacilitator(final DictionaryFacilitatorLruCache cache) {
final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US); final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US);
assertNotNull(dictionaryFacilitatorEnUs); assertNotNull(dictionaryFacilitatorEnUs);
assertTrue(dictionaryFacilitatorEnUs.isForLocales(new Locale[] { Locale.US })); assertTrue(dictionaryFacilitatorEnUs.isForLocales(new Locale[] { Locale.US }));
@ -62,13 +56,9 @@ public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
} }
public void testSetUseContactsDictionary() { public void testSetUseContactsDictionary() {
testSetUseContactsDictionary(new DictionaryFacilitatorLruCache( final DictionaryFacilitatorLruCache cache =
getContext(), MAX_CACHE_SIZE, "")); new DictionaryFacilitatorLruCache(getContext(), "");
testSetUseContactsDictionary(new DictionaryFacilitatorLruCache(
getContext(), MAX_CACHE_SIZE_LARGE, ""));
}
private static void testSetUseContactsDictionary(final DictionaryFacilitatorLruCache cache) {
assertNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); assertNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS));
cache.setUseContactsDictionary(true /* useContactsDictionary */); cache.setUseContactsDictionary(true /* useContactsDictionary */);
assertNotNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS)); assertNotNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS));