From 847c8dfe17c31c88d869ae469194edf574c9a474 Mon Sep 17 00:00:00 2001 From: satok Date: Sat, 11 Aug 2012 01:10:31 +0900 Subject: [PATCH] Fix JNI Change-Id: If134baf52e78fbe18b78611a23870f5d10c80955 --- java/proguard.flags | 4 ++++ .../android/inputmethod/latin/BinaryDictionary.java | 1 + .../inputmethod/latin/DicTraverseSession.java | 8 ++++---- ..._android_inputmethod_latin_DicTraverseSession.cpp | 12 +++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/java/proguard.flags b/java/proguard.flags index 24b4c1987..ac5b7df16 100644 --- a/java/proguard.flags +++ b/java/proguard.flags @@ -44,6 +44,10 @@ (...); } +-keepclasseswithmembernames class * { + native ; +} + -keep class com.android.inputmethod.research.ResearchLogger { void flush(); void publishCurrentLogUnit(...); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 9b85fb65a..f0f5cd320 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -79,6 +79,7 @@ public class BinaryDictionary extends Dictionary { mUseFullEditDistance = useFullEditDistance; loadDictionary(filename, offset, length); mDicTraverseSession = new DicTraverseSession(locale); + mDicTraverseSession.initSession(mNativeDict); } static { diff --git a/java/src/com/android/inputmethod/latin/DicTraverseSession.java b/java/src/com/android/inputmethod/latin/DicTraverseSession.java index 4c3654213..c76815363 100644 --- a/java/src/com/android/inputmethod/latin/DicTraverseSession.java +++ b/java/src/com/android/inputmethod/latin/DicTraverseSession.java @@ -23,8 +23,8 @@ public class DicTraverseSession { JniUtils.loadNativeLibrary(); } private native long setDicTraverseSessionNative(String locale); - //private native void initDicTraverseSessionNative(long nativeDicTraverseSession, - //long dictionary, int[] previousWord, int previousWordLength); + private native void initDicTraverseSessionNative(long nativeDicTraverseSession, + long dictionary, int[] previousWord, int previousWordLength); private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession); private long mNativeDicTraverseSession; @@ -43,8 +43,8 @@ public class DicTraverseSession { } public void initSession(long dictionary, int[] previousWord, int previousWordLength) { - //initDicTraverseSessionNative( - //mNativeDicTraverseSession, dictionary, previousWord, previousWordLength); + initDicTraverseSessionNative( + mNativeDicTraverseSession, dictionary, previousWord, previousWordLength); } private final long createNativeDicTraverseSession(String locale) { diff --git a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp index 6ff953874..806ff1f1d 100644 --- a/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp +++ b/native/jni/com_android_inputmethod_latin_DicTraverseSession.cpp @@ -28,18 +28,20 @@ static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object, jstring return reinterpret_cast(traverseSession); } -#if 0 static void latinime_initDicTraverseSession(JNIEnv *env, jobject object, jlong traverseSession, jlong dictionary, jintArray previousWord, jint previousWordLength) { void *ts = reinterpret_cast(traverseSession); Dictionary *dict = reinterpret_cast(dictionary); + if (!previousWord) { + DicTraverseWrapper::initDicTraverseSession(ts, dict, 0, 0); + return; + } int prevWord[previousWordLength]; env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord); DicTraverseWrapper::initDicTraverseSession(ts, dict, prevWord, previousWordLength); } -#endif -static void latinime_DicTraverseSession_release( +static void latinime_releaseDicTraverseSession( JNIEnv *env, jobject object, jlong traverseSession) { void *ts = reinterpret_cast(traverseSession); DicTraverseWrapper::releaseDicTraverseSession(ts); @@ -47,8 +49,8 @@ static void latinime_DicTraverseSession_release( static JNINativeMethod sMethods[] = { {"setDicTraverseSessionNative", "(Ljava/lang/String;)J", (void*)latinime_setDicTraverseSession}, - //{"initDicTraverseSessionNative", "(JJ[II)V", (void*)latinime_initDicTraverseSession}, - {"releaseDicTraverseSessionNative", "(J)V", (void*)latinime_DicTraverseSession_release} + {"initDicTraverseSessionNative", "(JJ[II)V", (void*)latinime_initDicTraverseSession}, + {"releaseDicTraverseSessionNative", "(J)V", (void*)latinime_releaseDicTraverseSession} }; int register_DicTraverseSession(JNIEnv *env) {