Add a debug preference for using only personalization dictionary

Bug: 9429906
Change-Id: I2003060c7065e736d42f3b3303fbba549358dd18
main
Satoshi Kataoka 2013-08-02 15:22:17 +09:00
parent ed56ea86d0
commit d7491e6e81
5 changed files with 48 additions and 11 deletions

View File

@ -428,6 +428,8 @@
<string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string> <string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string>
<!-- Title of the settings for reading an external dictionary file --> <!-- Title of the settings for reading an external dictionary file -->
<string name="prefs_read_external_dictionary">Read external dictionary file</string> <string name="prefs_read_external_dictionary">Read external dictionary file</string>
<!-- Title of the settings for using only personalization dictionary -->
<string name="prefs_use_only_personalization_dictionary" translatable="false">Use only personalization dictionary</string>
<!-- Message to show when there are no files to install as an external dictionary [CHAR LIMIT=100] --> <!-- Message to show when there are no files to install as an external dictionary [CHAR LIMIT=100] -->
<string name="read_external_dictionary_no_files_message">No dictionary files in the Downloads folder</string> <string name="read_external_dictionary_no_files_message">No dictionary files in the Downloads folder</string>
<!-- Title of the dialog that selects a file to install as an external dictionary [CHAR LIMIT=50] --> <!-- Title of the dialog that selects a file to install as an external dictionary [CHAR LIMIT=50] -->

View File

@ -51,6 +51,12 @@
android:persistent="true" android:persistent="true"
android:defaultValue="false" /> android:defaultValue="false" />
<CheckBoxPreference
android:defaultValue="false"
android:key="use_only_personalization_dictionary"
android:persistent="true"
android:title="@string/prefs_use_only_personalization_dictionary_for_debug" />
<PreferenceScreen <PreferenceScreen
android:key="read_external_dictionary" android:key="read_external_dictionary"
android:title="@string/prefs_read_external_dictionary" /> android:title="@string/prefs_read_external_dictionary" />

View File

@ -17,13 +17,16 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary; import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary; import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.AutoCorrectionUtils; import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
import com.android.inputmethod.latin.utils.BoundedTreeSet; import com.android.inputmethod.latin.utils.BoundedTreeSet;
import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CollectionUtils;
@ -55,21 +58,22 @@ public final class Suggest {
// Close to -2**31 // Close to -2**31
private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000; private static final int SUPPRESS_SUGGEST_THRESHOLD = -2000000000;
public static final int MAX_SUGGESTIONS = 18;
public interface SuggestInitializationListener { public interface SuggestInitializationListener {
public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable); public void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable);
} }
private static final boolean DBG = LatinImeLogger.sDBG; private static final boolean DBG = LatinImeLogger.sDBG;
private Dictionary mMainDictionary;
private ContactsBinaryDictionary mContactsDict;
private final ConcurrentHashMap<String, Dictionary> mDictionaries = private final ConcurrentHashMap<String, Dictionary> mDictionaries =
CollectionUtils.newConcurrentHashMap(); CollectionUtils.newConcurrentHashMap();
private HashSet<String> mOnlyDictionarySetForDebug = null;
private Dictionary mMainDictionary;
private ContactsBinaryDictionary mContactsDict;
@UsedForTesting @UsedForTesting
private boolean mIsCurrentlyWaitingForMainDictionary = false; private boolean mIsCurrentlyWaitingForMainDictionary = false;
public static final int MAX_SUGGESTIONS = 18;
private float mAutoCorrectionThreshold; private float mAutoCorrectionThreshold;
// Locale used for upper- and title-casing words // Locale used for upper- and title-casing words
@ -79,6 +83,13 @@ public final class Suggest {
final SuggestInitializationListener listener) { final SuggestInitializationListener listener) {
initAsynchronously(context, locale, listener); initAsynchronously(context, locale, listener);
mLocale = locale; mLocale = locale;
// initialize a debug flag for the personalization
if (Settings.readUseOnlyPersonalizationDictionaryForDebug(
PreferenceManager.getDefaultSharedPreferences(context))) {
mOnlyDictionarySetForDebug = new HashSet<String>();
mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION);
mOnlyDictionarySetForDebug.add(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA);
}
} }
@UsedForTesting @UsedForTesting
@ -87,7 +98,7 @@ public final class Suggest {
false /* useFullEditDistance */, locale); false /* useFullEditDistance */, locale);
mLocale = locale; mLocale = locale;
mMainDictionary = mainDict; mMainDictionary = mainDict;
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict); addOrReplaceDictionaryInternal(Dictionary.TYPE_MAIN, mainDict);
} }
private void initAsynchronously(final Context context, final Locale locale, private void initAsynchronously(final Context context, final Locale locale,
@ -95,6 +106,14 @@ public final class Suggest {
resetMainDict(context, locale, listener); resetMainDict(context, locale, listener);
} }
private void addOrReplaceDictionaryInternal(final String key, final Dictionary dict) {
if (mOnlyDictionarySetForDebug != null && mOnlyDictionarySetForDebug.contains(key)) {
Log.w(TAG, "Ignore add " + key + " dictionary for debug.");
return;
}
addOrReplaceDictionary(mDictionaries, key, dict);
}
private static void addOrReplaceDictionary( private static void addOrReplaceDictionary(
final ConcurrentHashMap<String, Dictionary> dictionaries, final ConcurrentHashMap<String, Dictionary> dictionaries,
final String key, final Dictionary dict) { final String key, final Dictionary dict) {
@ -118,7 +137,7 @@ public final class Suggest {
public void run() { public void run() {
final DictionaryCollection newMainDict = final DictionaryCollection newMainDict =
DictionaryFactory.createMainDictionaryFromManager(context, locale); DictionaryFactory.createMainDictionaryFromManager(context, locale);
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict); addOrReplaceDictionaryInternal(Dictionary.TYPE_MAIN, newMainDict);
mMainDictionary = newMainDict; mMainDictionary = newMainDict;
if (listener != null) { if (listener != null) {
listener.onUpdateMainDictionaryAvailability(hasMainDictionary()); listener.onUpdateMainDictionaryAvailability(hasMainDictionary());
@ -156,7 +175,7 @@ public final class Suggest {
* before the main dictionary, if set. This refers to the system-managed user dictionary. * before the main dictionary, if set. This refers to the system-managed user dictionary.
*/ */
public void setUserDictionary(final UserBinaryDictionary userDictionary) { public void setUserDictionary(final UserBinaryDictionary userDictionary) {
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER, userDictionary); addOrReplaceDictionaryInternal(Dictionary.TYPE_USER, userDictionary);
} }
/** /**
@ -166,18 +185,18 @@ public final class Suggest {
*/ */
public void setContactsDictionary(final ContactsBinaryDictionary contactsDictionary) { public void setContactsDictionary(final ContactsBinaryDictionary contactsDictionary) {
mContactsDict = contactsDictionary; mContactsDict = contactsDictionary;
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_CONTACTS, contactsDictionary); addOrReplaceDictionaryInternal(Dictionary.TYPE_CONTACTS, contactsDictionary);
} }
public void setUserHistoryPredictionDictionary( public void setUserHistoryPredictionDictionary(
final UserHistoryPredictionDictionary userHistoryPredictionDictionary) { final UserHistoryPredictionDictionary userHistoryPredictionDictionary) {
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_USER_HISTORY, addOrReplaceDictionaryInternal(Dictionary.TYPE_USER_HISTORY,
userHistoryPredictionDictionary); userHistoryPredictionDictionary);
} }
public void setPersonalizationPredictionDictionary( public void setPersonalizationPredictionDictionary(
final PersonalizationPredictionDictionary personalizationPredictionDictionary) { final PersonalizationPredictionDictionary personalizationPredictionDictionary) {
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA, addOrReplaceDictionaryInternal(Dictionary.TYPE_PERSONALIZATION_PREDICTION_IN_JAVA,
personalizationPredictionDictionary); personalizationPredictionDictionary);
} }

View File

@ -37,6 +37,8 @@ public final class DebugSettings extends PreferenceFragment
public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch"; public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
public static final String PREF_STATISTICS_LOGGING = "enable_logging"; public static final String PREF_STATISTICS_LOGGING = "enable_logging";
public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG =
"use_only_personalization_dictionary_for_debug";
private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary"; private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
private static final boolean SHOW_STATISTICS_LOGGING = false; private static final boolean SHOW_STATISTICS_LOGGING = false;
@ -66,7 +68,7 @@ public final class DebugSettings extends PreferenceFragment
} }
} }
PreferenceScreen readExternalDictionary = final PreferenceScreen readExternalDictionary =
(PreferenceScreen) findPreference(PREF_READ_EXTERNAL_DICTIONARY); (PreferenceScreen) findPreference(PREF_READ_EXTERNAL_DICTIONARY);
if (null != readExternalDictionary) { if (null != readExternalDictionary) {
readExternalDictionary.setOnPreferenceClickListener( readExternalDictionary.setOnPreferenceClickListener(
@ -111,6 +113,8 @@ public final class DebugSettings extends PreferenceFragment
} else if (key.equals(PREF_FORCE_NON_DISTINCT_MULTITOUCH) } else if (key.equals(PREF_FORCE_NON_DISTINCT_MULTITOUCH)
|| key.equals(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT)) { || key.equals(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT)) {
mServiceNeedsRestart = true; mServiceNeedsRestart = true;
} else if (key.equals(PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG)) {
mServiceNeedsRestart = true;
} }
} }

View File

@ -324,4 +324,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static boolean isInternal(final SharedPreferences prefs) { public static boolean isInternal(final SharedPreferences prefs) {
return prefs.getBoolean(Settings.PREF_KEY_IS_INTERNAL, false); return prefs.getBoolean(Settings.PREF_KEY_IS_INTERNAL, false);
} }
public static boolean readUseOnlyPersonalizationDictionaryForDebug(
final SharedPreferences prefs) {
return prefs.getBoolean(
DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false);
}
} }