Delete history on upgrade in LatinIME.

Bug 20733902.

Change-Id: Ibe27e6cafe4db87ba62d7df708229e0d8564ffa8
This commit is contained in:
Dan Zivkovic 2015-05-01 12:45:07 -07:00
parent 89f9070264
commit f22571e2d9
3 changed files with 40 additions and 7 deletions

View File

@ -107,6 +107,10 @@ public interface DictionaryFacilitator {
Locale getLocale();
boolean usesContacts();
String getAccount();
void resetDictionaries(
final Context context,
final Locale newLocale,
@ -162,7 +166,7 @@ public interface DictionaryFacilitator {
boolean isValidSuggestionWord(final String word);
void clearUserHistoryDictionary(final Context context);
boolean clearUserHistoryDictionary(final Context context);
String dump(final Context context);

View File

@ -234,6 +234,16 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
return mDictionaryGroup.mLocale;
}
@Override
public boolean usesContacts() {
return mDictionaryGroup.getSubDict(Dictionary.TYPE_CONTACTS) != null;
}
@Override
public String getAccount() {
return null;
}
@Nullable
private static ExpandableBinaryDictionary getSubDict(final String dictType,
final Context context, final Locale locale, final File dictFile,
@ -660,16 +670,18 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
return maxFreq;
}
private void clearSubDictionary(final String dictName) {
private boolean clearSubDictionary(final String dictName) {
final ExpandableBinaryDictionary dictionary = mDictionaryGroup.getSubDict(dictName);
if (dictionary != null) {
dictionary.clear();
if (dictionary == null) {
return false;
}
dictionary.clear();
return true;
}
@Override
public void clearUserHistoryDictionary(final Context context) {
clearSubDictionary(Dictionary.TYPE_USER_HISTORY);
public boolean clearUserHistoryDictionary(final Context context) {
return clearSubDictionary(Dictionary.TYPE_USER_HISTORY);
}
@Override

View File

@ -29,13 +29,14 @@ import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.dictionarypack.CommonPreferences;
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.setup.SetupActivity;
import com.android.inputmethod.latin.utils.UncachedInputMethodManagerUtils;
import java.util.Locale;
/**
* This class detects the {@link Intent#ACTION_MY_PACKAGE_REPLACED} broadcast intent when this IME
* package has been replaced by a newer version of the same package. This class also detects
@ -76,6 +77,22 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
toggleAppIcon(context);
downloadLatestDictionaries(context);
// TODO: This is only for dogfood builds. Remove this from the final release.
DictionaryFacilitator keyboardFacilitator =
DictionaryFacilitatorProvider.getDictionaryFacilitator(false);
boolean historyCleared = keyboardFacilitator.clearUserHistoryDictionary(context);
Locale keyboardLocale = keyboardFacilitator.getLocale();
if (historyCleared && keyboardLocale != null) {
keyboardFacilitator.resetDictionaries(
context,
keyboardLocale,
keyboardFacilitator.usesContacts(),
true /* history */,
true /* force */,
keyboardFacilitator.getAccount(),
"" /* prefix */,
null /* listener */);
}
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
Log.i(TAG, "Boot has been completed");
toggleAppIcon(context);