Merge "Extend jni interface for dictionary migration."
This commit is contained in:
commit
08d12a1be3
3 changed files with 24 additions and 2 deletions
|
@ -218,6 +218,8 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
int bigramProbability);
|
int bigramProbability);
|
||||||
private static native String getPropertyNative(long dict, String query);
|
private static native String getPropertyNative(long dict, String query);
|
||||||
private static native boolean isCorruptedNative(long dict);
|
private static native boolean isCorruptedNative(long dict);
|
||||||
|
private static native boolean migrateNative(long dict, String dictFilePath,
|
||||||
|
long newFormatVersion);
|
||||||
|
|
||||||
// TODO: Move native dict into session
|
// TODO: Move native dict into session
|
||||||
private final void loadDictionary(final String path, final long startOffset,
|
private final void loadDictionary(final String path, final long startOffset,
|
||||||
|
@ -533,7 +535,9 @@ public final class BinaryDictionary extends Dictionary {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION;
|
final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION;
|
||||||
// TODO: Implement migrateNative(tmpDictFilePath, newFormatVersion).
|
if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
close();
|
close();
|
||||||
final File dictFile = new File(mDictFilePath);
|
final File dictFile = new File(mDictFilePath);
|
||||||
final File tmpDictFile = new File(tmpDictFilePath);
|
final File tmpDictFile = new File(tmpDictFilePath);
|
||||||
|
|
|
@ -470,7 +470,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
}
|
}
|
||||||
if (mBinaryDictionary.isValidDictionary()
|
if (mBinaryDictionary.isValidDictionary()
|
||||||
&& needsToMigrateDictionary(mBinaryDictionary.getFormatVersion())) {
|
&& needsToMigrateDictionary(mBinaryDictionary.getFormatVersion())) {
|
||||||
mBinaryDictionary.migrateTo(DICTIONARY_FORMAT_VERSION);
|
if (!mBinaryDictionary.migrateTo(DICTIONARY_FORMAT_VERSION)) {
|
||||||
|
Log.e(TAG, "Dictionary migration failed: " + mDictName);
|
||||||
|
removeBinaryDictionaryLocked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -489,6 +489,16 @@ static bool latinime_BinaryDictionary_isCorruptedNative(JNIEnv *env, jclass claz
|
||||||
return dictionary->getDictionaryStructurePolicy()->isCorrupted();
|
return dictionary->getDictionaryStructurePolicy()->isCorrupted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool latinime_BinaryDictionary_migrateNative(JNIEnv *env, jclass clazz, jlong dict,
|
||||||
|
jstring dictFilePath, jlong newFormatVersion) {
|
||||||
|
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
|
||||||
|
if (!dictionary) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO: Implement.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static const JNINativeMethod sMethods[] = {
|
static const JNINativeMethod sMethods[] = {
|
||||||
{
|
{
|
||||||
const_cast<char *>("openNative"),
|
const_cast<char *>("openNative"),
|
||||||
|
@ -591,6 +601,11 @@ static const JNINativeMethod sMethods[] = {
|
||||||
const_cast<char *>("isCorruptedNative"),
|
const_cast<char *>("isCorruptedNative"),
|
||||||
const_cast<char *>("(J)Z"),
|
const_cast<char *>("(J)Z"),
|
||||||
reinterpret_cast<void *>(latinime_BinaryDictionary_isCorruptedNative)
|
reinterpret_cast<void *>(latinime_BinaryDictionary_isCorruptedNative)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
const_cast<char *>("migrateNative"),
|
||||||
|
const_cast<char *>("(JLjava/lang/String;J)Z"),
|
||||||
|
reinterpret_cast<void *>(latinime_BinaryDictionary_migrateNative)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue