From ba07df7fc1ffb8f97b5455b2e88e5d8ac92ba94e Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Fri, 10 Jan 2014 16:30:59 +0900 Subject: [PATCH] Periodic wipe of the personalization dict. Bug: 12216453 Change-Id: Ie59dd19c044e9b1eb9b8bd805366200737ea506a --- java/res/values/config-common.xml | 4 ++++ .../inputmethod/latin/ExpandableBinaryDictionary.java | 4 +++- .../android/inputmethod/latin/settings/Settings.java | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/java/res/values/config-common.xml b/java/res/values/config-common.xml index ab16a9045..c92015288 100644 --- a/java/res/values/config-common.xml +++ b/java/res/values/config-common.xml @@ -139,4 +139,8 @@ 8dp 48 + + + + -1 diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index f785835b8..7757d2910 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -282,7 +282,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { @Override public void run() { if (mDictionaryWriter == null) { - mBinaryDictionary.close(); + if (mBinaryDictionary != null) { + mBinaryDictionary.close(); + } final File file = getDictFile(); if (file.exists() && !FileUtils.deleteRecursively(file)) { Log.e(TAG, "Can't remove a file: " + file.getName()); diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 84ba7223a..7fb518308 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -93,6 +93,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang private static final String PREF_LAST_USED_PERSONALIZATION_TOKEN = "pref_last_used_personalization_token"; + private static final String PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME = + "pref_last_used_personalization_dict_wiped_time"; public static final String PREF_SEND_FEEDBACK = "send_feedback"; public static final String PREF_ABOUT_KEYBOARD = "about_keyboard"; @@ -372,6 +374,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return StringUtils.hexStringToByteArray(tokenStr); } + public void writeLastPersonalizationDictWipedTime(final long timestamp) { + mPrefs.edit().putLong(PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME, timestamp).apply(); + } + + public long readLastPersonalizationDictGeneratedTime() { + return mPrefs.getLong(PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME, 0); + } + public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) { prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply(); }