Cleanup in preparation of distracter change.
Bug 19296201. Change-Id: If016da2b7f4b3ecb9afd6d7aed9d19fbd4938758
This commit is contained in:
parent
608ef4729c
commit
d6a8adcb04
8 changed files with 34 additions and 61 deletions
|
@ -113,24 +113,22 @@ public interface DictionaryFacilitator {
|
|||
|
||||
boolean isConfidentAboutCurrentLanguageBeing(final Locale mLocale);
|
||||
|
||||
void resetDictionaries(final Context context, final Locale[] newLocales,
|
||||
final boolean useContactsDict, final boolean usePersonalizedDicts,
|
||||
final boolean forceReloadMainDictionary,
|
||||
@Nullable final String account,
|
||||
final DictionaryInitializationListener listener);
|
||||
|
||||
void resetDictionariesWithDictNamePrefix(final Context context,
|
||||
void resetDictionaries(
|
||||
final Context context,
|
||||
final Locale[] newLocales,
|
||||
final boolean useContactsDict,
|
||||
final boolean usePersonalizedDicts,
|
||||
final boolean forceReloadMainDictionary,
|
||||
@Nullable final DictionaryInitializationListener listener,
|
||||
@Nullable final String account,
|
||||
final String dictNamePrefix,
|
||||
@Nullable final String account);
|
||||
@Nullable final DictionaryInitializationListener listener);
|
||||
|
||||
@UsedForTesting
|
||||
void resetDictionariesForTesting(final Context context, final Locale[] locales,
|
||||
final ArrayList<String> dictionaryTypes, final HashMap<String, File> dictionaryFiles,
|
||||
void resetDictionariesForTesting(
|
||||
final Context context,
|
||||
final Locale[] locales,
|
||||
final ArrayList<String> dictionaryTypes,
|
||||
final HashMap<String, File> dictionaryFiles,
|
||||
final Map<String, Map<String, String>> additionalDictAttributes,
|
||||
@Nullable final String account);
|
||||
|
||||
|
|
|
@ -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
|
||||
static DictionaryGroup findDictionaryGroupWithLocale(final DictionaryGroup[] dictionaryGroups,
|
||||
final Locale locale) {
|
||||
|
@ -363,14 +353,15 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void resetDictionariesWithDictNamePrefix(final Context context,
|
||||
public void resetDictionaries(
|
||||
final Context context,
|
||||
final Locale[] newLocales,
|
||||
final boolean useContactsDict,
|
||||
final boolean usePersonalizedDicts,
|
||||
final boolean forceReloadMainDictionary,
|
||||
@Nullable final DictionaryInitializationListener listener,
|
||||
@Nullable final String account,
|
||||
final String dictNamePrefix,
|
||||
@Nullable final String account) {
|
||||
@Nullable final DictionaryInitializationListener listener) {
|
||||
final HashMap<Locale, ArrayList<String>> existingDictionariesToCleanup = new HashMap<>();
|
||||
// TODO: Make subDictTypesToUse configurable by resource or a static final list.
|
||||
final HashSet<String> subDictTypesToUse = new HashSet<>();
|
||||
|
|
|
@ -28,10 +28,11 @@ import android.util.LruCache;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
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 MAX_RETRY_COUNT_FOR_WAITING_FOR_LOADING_DICT = 5;
|
||||
|
||||
|
@ -74,10 +75,10 @@ public class DictionaryFacilitatorLruCache {
|
|||
private final Object mLock = new Object();
|
||||
private boolean mUseContactsDictionary = false;
|
||||
|
||||
public DictionaryFacilitatorLruCache(final Context context, final int maxSize,
|
||||
final String dictionaryNamePrefix) {
|
||||
public DictionaryFacilitatorLruCache(final Context context, final String dictionaryNamePrefix) {
|
||||
mContext = context;
|
||||
mLruCache = new DictionaryFacilitatorLruCacheInner(mCachedLocales, maxSize);
|
||||
mLruCache = new DictionaryFacilitatorLruCacheInner(
|
||||
mCachedLocales, MAX_DICTIONARY_FACILITATOR_COUNT);
|
||||
mDictionaryNamePrefix = dictionaryNamePrefix;
|
||||
}
|
||||
|
||||
|
@ -103,11 +104,10 @@ public class DictionaryFacilitatorLruCache {
|
|||
private void resetDictionariesForLocaleLocked(final DictionaryFacilitator dictionaryFacilitator,
|
||||
final Locale locale) {
|
||||
// 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 */,
|
||||
false /* forceReloadMainDictionary */, null /* listener */,
|
||||
mDictionaryNamePrefix,
|
||||
null /* account */);
|
||||
false /* forceReloadMainDictionary */, null /* account */,
|
||||
mDictionaryNamePrefix, null /* listener */);
|
||||
}
|
||||
|
||||
public void setUseContactsDictionary(final boolean useContectsDictionary) {
|
||||
|
|
|
@ -128,7 +128,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
|
||||
final Settings mSettings;
|
||||
private final DictionaryFacilitator mDictionaryFacilitator =
|
||||
DictionaryFacilitatorProvider.newDictionaryFacilitator(this /* context */);
|
||||
DictionaryFacilitatorProvider.newDictionaryFacilitator(this /* context */);
|
||||
final InputLogic mInputLogic = new InputLogic(this /* LatinIME */,
|
||||
this /* SuggestionStripViewAccessor */, mDictionaryFacilitator);
|
||||
// We expect to have only one decoder in almost all cases, hence the default capacity of 1.
|
||||
|
@ -679,7 +679,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mDictionaryFacilitator.resetDictionaries(this /* context */, locales,
|
||||
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
|
||||
false /* forceReloadMainDictionary */,
|
||||
settingsValues.mAccount,
|
||||
settingsValues.mAccount, "" /* dictNamePrefix */,
|
||||
this /* DictionaryInitializationListener */);
|
||||
if (settingsValues.mAutoCorrectionEnabledPerUserSettings) {
|
||||
mInputLogic.mSuggest.setAutoCorrectionThreshold(
|
||||
|
@ -697,7 +697,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mDictionaryFacilitator.getLocales(), settingsValues.mUseContactsDict,
|
||||
settingsValues.mUsePersonalizedDicts,
|
||||
true /* forceReloadMainDictionary */,
|
||||
settingsValues.mAccount,
|
||||
settingsValues.mAccount, "" /* dictNamePrefix */,
|
||||
this /* DictionaryInitializationListener */);
|
||||
}
|
||||
|
||||
|
@ -1810,7 +1810,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mDictionaryFacilitator.resetDictionaries(this, new Locale[] { locale },
|
||||
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
|
||||
false /* forceReloadMainDictionary */,
|
||||
settingsValues.mAccount,
|
||||
settingsValues.mAccount, "", /* dictionaryNamePrefix */
|
||||
this /* DictionaryInitializationListener */);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
package com.android.inputmethod.latin.personalization;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.android.inputmethod.annotations.ExternallyReferenced;
|
||||
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.common.Constants;
|
||||
import com.android.inputmethod.latin.define.ProductionFlags;
|
||||
import com.android.inputmethod.latin.settings.LocalSettingsConstants;
|
||||
import com.android.inputmethod.latin.utils.DistracterFilter;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -67,10 +67,8 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
|
|||
// TODO: Make each spell checker session has its own session id.
|
||||
private final ConcurrentLinkedQueue<Integer> mSessionIdPool = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private static final int MAX_DICTIONARY_FACILITATOR_COUNT = 3;
|
||||
private final DictionaryFacilitatorLruCache mDictionaryFacilitatorCache =
|
||||
new DictionaryFacilitatorLruCache(this /* context */, MAX_DICTIONARY_FACILITATOR_COUNT,
|
||||
DICTIONARY_NAME_PREFIX);
|
||||
new DictionaryFacilitatorLruCache(this /* context */, DICTIONARY_NAME_PREFIX);
|
||||
private final ConcurrentHashMap<Locale, Keyboard> mKeyboardCache = new ConcurrentHashMap<>();
|
||||
|
||||
// The threshold for a suggestion to be considered "recommended".
|
||||
|
|
|
@ -53,7 +53,6 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
|
|||
DistracterFilterCheckingExactMatchesAndSuggestions.class.getSimpleName();
|
||||
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 final Context mContext;
|
||||
|
@ -81,8 +80,8 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
|
|||
mContext = context;
|
||||
mLocaleToSubtypeCache = new ConcurrentHashMap<>();
|
||||
mLocaleToKeyboardCache = new ConcurrentHashMap<>();
|
||||
mDictionaryFacilitatorLruCache = new DictionaryFacilitatorLruCache(context,
|
||||
MAX_DICTIONARY_FACILITATOR_CACHE_SIZE, "" /* dictionaryNamePrefix */);
|
||||
mDictionaryFacilitatorLruCache = new DictionaryFacilitatorLruCache(
|
||||
context, "" /* dictionaryNamePrefix */);
|
||||
mDistractersCache = new LruCache<>(MAX_DISTRACTERS_CACHE_SIZE);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,9 @@ import android.test.suitebuilder.annotation.LargeTest;
|
|||
|
||||
@LargeTest
|
||||
public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
|
||||
static final int MAX_CACHE_SIZE = 2;
|
||||
static final int MAX_CACHE_SIZE_LARGE = 5;
|
||||
|
||||
public void testCacheSize() {
|
||||
final DictionaryFacilitatorLruCache cache =
|
||||
new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, "");
|
||||
new DictionaryFacilitatorLruCache(getContext(), "");
|
||||
|
||||
assertEquals(0, cache.getCachedLocalesForTesting().size());
|
||||
assertNotNull(cache.get(Locale.US));
|
||||
|
@ -42,12 +39,9 @@ public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
|
|||
}
|
||||
|
||||
public void testGetFacilitator() {
|
||||
testGetFacilitator(new DictionaryFacilitatorLruCache(getContext(), MAX_CACHE_SIZE, ""));
|
||||
testGetFacilitator(new DictionaryFacilitatorLruCache(
|
||||
getContext(), MAX_CACHE_SIZE_LARGE, ""));
|
||||
}
|
||||
final DictionaryFacilitatorLruCache cache =
|
||||
new DictionaryFacilitatorLruCache(getContext(), "");
|
||||
|
||||
private static void testGetFacilitator(final DictionaryFacilitatorLruCache cache) {
|
||||
final DictionaryFacilitator dictionaryFacilitatorEnUs = cache.get(Locale.US);
|
||||
assertNotNull(dictionaryFacilitatorEnUs);
|
||||
assertTrue(dictionaryFacilitatorEnUs.isForLocales(new Locale[] { Locale.US }));
|
||||
|
@ -62,13 +56,9 @@ public class DictionaryFacilitatorLruCacheTests extends AndroidTestCase {
|
|||
}
|
||||
|
||||
public void testSetUseContactsDictionary() {
|
||||
testSetUseContactsDictionary(new DictionaryFacilitatorLruCache(
|
||||
getContext(), MAX_CACHE_SIZE, ""));
|
||||
testSetUseContactsDictionary(new DictionaryFacilitatorLruCache(
|
||||
getContext(), MAX_CACHE_SIZE_LARGE, ""));
|
||||
}
|
||||
final DictionaryFacilitatorLruCache cache =
|
||||
new DictionaryFacilitatorLruCache(getContext(), "");
|
||||
|
||||
private static void testSetUseContactsDictionary(final DictionaryFacilitatorLruCache cache) {
|
||||
assertNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS));
|
||||
cache.setUseContactsDictionary(true /* useContactsDictionary */);
|
||||
assertNotNull(cache.get(Locale.US).getSubDictForTesting(Dictionary.TYPE_CONTACTS));
|
||||
|
|
Loading…
Reference in a new issue