Remove DictionaryFacilitatorForSuggest.getMainDictionary().

Bug: 8187060
Change-Id: Ide087f1e39b24695b610bd2b3c464b7e3cb9cd29
This commit is contained in:
Keisuke Kuroyanagi 2013-12-26 20:47:46 +09:00
parent a374482719
commit be147f1fdc
3 changed files with 20 additions and 30 deletions

View file

@ -125,10 +125,6 @@ public class DictionaryFacilitatorForSuggest {
return mIsCurrentlyWaitingForMainDictionary; return mIsCurrentlyWaitingForMainDictionary;
} }
public Dictionary getMainDictionary() {
return mMainDictionary;
}
private void setMainDictionary(final Dictionary mainDictionary) { private void setMainDictionary(final Dictionary mainDictionary) {
mMainDictionary = mainDictionary; mMainDictionary = mainDictionary;
addOrReplaceDictionary(Dictionary.TYPE_MAIN, mainDictionary); addOrReplaceDictionary(Dictionary.TYPE_MAIN, mainDictionary);
@ -319,6 +315,13 @@ public class DictionaryFacilitatorForSuggest {
} }
} }
public boolean isValidMainDictWord(final String word) {
if (TextUtils.isEmpty(word) || !hasMainDictionary()) {
return false;
}
return mMainDictionary.isValidWord(word);
}
public boolean isValidWord(final String word, final boolean ignoreCase) { public boolean isValidWord(final String word, final boolean ignoreCase) {
if (TextUtils.isEmpty(word)) { if (TextUtils.isEmpty(word)) {
return false; return false;

View file

@ -99,14 +99,14 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
mDictionaryForTesting = dictionary; mDictionaryForTesting = dictionary;
} }
private Dictionary getDictionary() { private boolean isValidDictWord(final String word) {
if (mDictionaryForTesting != null) { if (mDictionaryForTesting != null) {
return mDictionaryForTesting; return mDictionaryForTesting.isValidWord(word);
} }
if (mDictionaryFacilitator == null || !mDictionaryFacilitator.hasMainDictionary()) { if (mDictionaryFacilitator != null) {
return null; return mDictionaryFacilitator.isValidMainDictWord(word);
} }
return mDictionaryFacilitator.getMainDictionary(); return false;
} }
public void setIsStopping() { public void setIsStopping() {
@ -155,8 +155,8 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
} }
// Reload the dictionary in case it has changed (e.g., because the user has changed // Reload the dictionary in case it has changed (e.g., because the user has changed
// languages). // languages).
final Dictionary dictionary = getDictionary(); if ((mDictionaryFacilitator == null || !mDictionaryFacilitator.hasMainDictionary())
if (dictionary == null) { && mDictionaryForTesting == null) {
// Main dictionary is unavailable. Since we cannot check it, we cannot tell if a // Main dictionary is unavailable. Since we cannot check it, we cannot tell if a
// word is out-of-vocabulary or not. Therefore, we must judge the entire buffer // word is out-of-vocabulary or not. Therefore, we must judge the entire buffer
// contents to potentially pose a privacy risk. // contents to potentially pose a privacy risk.
@ -166,7 +166,6 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
// Check each word in the buffer. If any word poses a privacy threat, we cannot upload // Check each word in the buffer. If any word poses a privacy threat, we cannot upload
// the complete buffer contents in detail. // the complete buffer contents in detail.
int numWordsInLogUnitList = 0; int numWordsInLogUnitList = 0;
final int length = logUnits.size();
for (final LogUnit logUnit : logUnits) { for (final LogUnit logUnit : logUnits) {
if (!logUnit.hasOneOrMoreWords()) { if (!logUnit.hasOneOrMoreWords()) {
// Digits outside words are a privacy threat. // Digits outside words are a privacy threat.
@ -178,11 +177,11 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
final String[] words = logUnit.getWordsAsStringArray(); final String[] words = logUnit.getWordsAsStringArray();
for (final String word : words) { for (final String word : words) {
// Words not in the dictionary are a privacy threat. // Words not in the dictionary are a privacy threat.
if (ResearchLogger.hasLetters(word) && !(dictionary.isValidWord(word))) { if (ResearchLogger.hasLetters(word) && !isValidDictWord(word)) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "\"" + word + "\" NOT SAFE!: hasLetters: " Log.d(TAG, "\"" + word + "\" NOT SAFE!: hasLetters: "
+ ResearchLogger.hasLetters(word) + ResearchLogger.hasLetters(word)
+ ", isValid: " + (dictionary.isValidWord(word))); + ", isValid: " + isValidDictWord(word));
} }
return PUBLISHABILITY_UNPUBLISHABLE_NOT_IN_DICTIONARY; return PUBLISHABILITY_UNPUBLISHABLE_NOT_IN_DICTIONARY;
} }

View file

@ -52,7 +52,6 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest; import com.android.inputmethod.latin.DictionaryFacilitatorForSuggest;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
@ -254,10 +253,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
+ ", cipd: " + canIncludePrivateData); + ", cipd: " + canIncludePrivateData);
} }
for (final String word : logUnit.getWordsAsStringArray()) { for (final String word : logUnit.getWordsAsStringArray()) {
final Dictionary dictionary = getDictionary(); final boolean isDictionaryWord = mDictionaryFacilitator != null
&& mDictionaryFacilitator.isValidMainDictWord(word);
mStatistics.recordWordEntered( mStatistics.recordWordEntered(
dictionary != null && dictionary.isValidWord(word), isDictionaryWord, logUnit.containsUserDeletions());
logUnit.containsUserDeletions());
} }
} }
publishLogUnits(logUnits, mMainResearchLog, canIncludePrivateData); publishLogUnits(logUnits, mMainResearchLog, canIncludePrivateData);
@ -664,13 +663,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
} }
private Dictionary getDictionary() {
if (mDictionaryFacilitator == null) {
return null;
}
return mDictionaryFacilitator.getMainDictionary();
}
private void setIsPasswordView(boolean isPasswordView) { private void setIsPasswordView(boolean isPasswordView) {
mIsPasswordView = isPasswordView; mIsPasswordView = isPasswordView;
} }
@ -964,11 +956,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
private String scrubWord(String word) { private String scrubWord(String word) {
final Dictionary dictionary = getDictionary(); if (mDictionaryFacilitator != null && mDictionaryFacilitator.isValidMainDictWord(word)) {
if (dictionary == null) {
return WORD_REPLACEMENT_STRING;
}
if (dictionary.isValidWord(word)) {
return word; return word;
} }
return WORD_REPLACEMENT_STRING; return WORD_REPLACEMENT_STRING;