Merge "Extend jni interface for dictionary migration."

main
Keisuke Kuroyanagi 2014-05-08 05:20:33 +00:00 committed by Android (Google) Code Review
commit 08d12a1be3
3 changed files with 24 additions and 2 deletions

View File

@ -218,6 +218,8 @@ public final class BinaryDictionary extends Dictionary {
int bigramProbability);
private static native String getPropertyNative(long dict, String query);
private static native boolean isCorruptedNative(long dict);
private static native boolean migrateNative(long dict, String dictFilePath,
long newFormatVersion);
// TODO: Move native dict into session
private final void loadDictionary(final String path, final long startOffset,
@ -533,7 +535,9 @@ public final class BinaryDictionary extends Dictionary {
return false;
}
final String tmpDictFilePath = mDictFilePath + DICT_FILE_NAME_SUFFIX_FOR_MIGRATION;
// TODO: Implement migrateNative(tmpDictFilePath, newFormatVersion).
if (!migrateNative(mNativeDict, tmpDictFilePath, newFormatVersion)) {
return false;
}
close();
final File dictFile = new File(mDictFilePath);
final File tmpDictFile = new File(tmpDictFilePath);

View File

@ -470,7 +470,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();
}
}
}

View File

@ -489,6 +489,16 @@ static bool latinime_BinaryDictionary_isCorruptedNative(JNIEnv *env, jclass claz
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[] = {
{
const_cast<char *>("openNative"),
@ -591,6 +601,11 @@ static const JNINativeMethod sMethods[] = {
const_cast<char *>("isCorruptedNative"),
const_cast<char *>("(J)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_isCorruptedNative)
},
{
const_cast<char *>("migrateNative"),
const_cast<char *>("(JLjava/lang/String;J)Z"),
reinterpret_cast<void *>(latinime_BinaryDictionary_migrateNative)
}
};