1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "LatinIME: jni" 18 19 #include "jni_common.h" 20 21 #include "com_android_inputmethod_keyboard_ProximityInfo.h" 22 #include "com_android_inputmethod_latin_BinaryDictionary.h" 23 #include "com_android_inputmethod_latin_DicTraverseSession.h" 24 #include "defines.h" 25 26 /* 27 * Returns the JNI version on success, -1 on failure. 28 */ 29 jint JNI_OnLoad(JavaVM *vm, void *reserved) { 30 JNIEnv *env = 0; 31 32 if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) { 33 AKLOGE("ERROR: GetEnv failed"); 34 return -1; 35 } 36 ASSERT(env); 37 if (!env) { 38 AKLOGE("ERROR: JNIEnv is invalid"); 39 return -1; 40 } 41 if (!latinime::register_BinaryDictionary(env)) { 42 AKLOGE("ERROR: BinaryDictionary native registration failed"); 43 return -1; 44 } 45 if (!latinime::register_DicTraverseSession(env)) { 46 AKLOGE("ERROR: DicTraverseSession native registration failed"); 47 return -1; 48 } 49 if (!latinime::register_ProximityInfo(env)) { 50 AKLOGE("ERROR: ProximityInfo native registration failed"); 51 return -1; 52 } 53 /* success -- return valid version number */ 54 return JNI_VERSION_1_6; 55 } 56 57 namespace latinime { 58 int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, 59 int numMethods) { 60 jclass clazz = env->FindClass(className); 61 if (!clazz) { 62 AKLOGE("Native registration unable to find class '%s'", className); 63 return JNI_FALSE; 64 } 65 if (env->RegisterNatives(clazz, methods, numMethods) < 0) { 66 AKLOGE("RegisterNatives failed for '%s'", className); 67 env->DeleteLocalRef(clazz); 68 return JNI_FALSE; 69 } 70 env->DeleteLocalRef(clazz); 71 return JNI_TRUE; 72 } 73 } // namespace latinime 74