aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java38
1 files changed, 17 insertions, 21 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index c825ca462..6818c156e 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -92,8 +92,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/** Indicates whether a task for reloading the dictionary has been scheduled. */
private final AtomicBoolean mIsReloading;
- /** Indicates whether the current dictionary needs to be reloaded. */
- private boolean mNeedsToReload;
+ /** Indicates whether the current dictionary needs to be recreated. */
+ private boolean mNeedsToRecreate;
private final ReentrantReadWriteLock mLock;
@@ -107,20 +107,14 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/
protected abstract void loadInitialContentsLocked();
- /**
- * Indicates that the source dictionary contents have changed and a rebuild of the binary file
- * is required. If it returns false, the next reload will only read the current binary
- * dictionary from file.
- */
- protected abstract boolean haveContentsChanged();
-
private boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) {
return formatVersion == FormatSpec.VERSION4;
}
private boolean needsToMigrateDictionary(final int formatVersion) {
- // TODO: Check version.
- return false;
+ // When we bump up the dictionary format version, the old version should be added to here
+ // for supporting migration. Note that native code has to support reading such formats.
+ return formatVersion == FormatSpec.VERSION4_ONLY_FOR_TESTING;
}
public boolean isValidDictionaryLocked() {
@@ -147,7 +141,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
mDictFile = getDictFile(context, dictName, dictFile);
mBinaryDictionary = null;
mIsReloading = new AtomicBoolean();
- mNeedsToReload = false;
+ mNeedsToRecreate = false;
mLock = new ReentrantReadWriteLock();
}
@@ -470,7 +464,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
if (mBinaryDictionary.isValidDictionary()
&& needsToMigrateDictionary(mBinaryDictionary.getFormatVersion())) {
- mBinaryDictionary.migrateTo(DICTIONARY_FORMAT_VERSION);
+ if (!mBinaryDictionary.migrateTo(DICTIONARY_FORMAT_VERSION)) {
+ Log.e(TAG, "Dictionary migration failed: " + mDictName);
+ removeBinaryDictionaryLocked();
+ }
}
}
@@ -486,11 +483,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
/**
- * Marks that the dictionary needs to be reloaded.
+ * Marks that the dictionary needs to be recreated.
*
*/
- protected void setNeedsToReload() {
- mNeedsToReload = true;
+ protected void setNeedsToRecreate() {
+ mNeedsToRecreate = true;
}
/**
@@ -508,7 +505,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* Returns whether a dictionary reload is required.
*/
private boolean isReloadRequired() {
- return mBinaryDictionary == null || mNeedsToReload;
+ return mBinaryDictionary == null || mNeedsToRecreate;
}
/**
@@ -520,8 +517,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
@Override
public void run() {
try {
- // TODO: Quit checking contents in ExpandableBinaryDictionary.
- if (!mDictFile.exists() || (mNeedsToReload && haveContentsChanged())) {
+ if (!mDictFile.exists() || mNeedsToRecreate) {
// If the dictionary file does not exist or contents have been updated,
// generate a new one.
createNewDictionaryLocked();
@@ -533,12 +529,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
&& matchesExpectedBinaryDictFormatVersionForThisType(
mBinaryDictionary.getFormatVersion()))) {
// Binary dictionary or its format version is not valid. Regenerate
- // the dictionary file. writeBinaryDictionary will remove the
+ // the dictionary file. createNewDictionaryLocked will remove the
// existing files if appropriate.
createNewDictionaryLocked();
}
}
- mNeedsToReload = false;
+ mNeedsToRecreate = false;
} finally {
mIsReloading.set(false);
}