satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 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 | * |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 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 | */ |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 16 | |
| 17 | #define LOG_TAG "LatinIME: jni" |
| 18 | |
Ken Wakasa | b68e734 | 2013-04-08 17:08:19 +0900 | [diff] [blame] | 19 | #include "jni_common.h" |
| 20 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 21 | #include "com_android_inputmethod_keyboard_ProximityInfo.h" |
| 22 | #include "com_android_inputmethod_latin_BinaryDictionary.h" |
Keisuke Kuroyanagi | 9e51c6c | 2014-03-05 12:49:04 +0900 | [diff] [blame] | 23 | #include "com_android_inputmethod_latin_BinaryDictionaryUtils.h" |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame] | 24 | #include "com_android_inputmethod_latin_DicTraverseSession.h" |
Ken Wakasa | 3b088a2 | 2012-05-16 23:05:32 +0900 | [diff] [blame] | 25 | #include "defines.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 26 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 27 | /* |
| 28 | * Returns the JNI version on success, -1 on failure. |
| 29 | */ |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 30 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
| 31 | JNIEnv *env = 0; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 32 | |
Ken Wakasa | 34710b0 | 2012-08-14 14:22:27 +0900 | [diff] [blame] | 33 | if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 34 | AKLOGE("ERROR: GetEnv failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 35 | return -1; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 36 | } |
Ken Wakasa | ccebd5c | 2013-01-09 15:21:44 +0900 | [diff] [blame] | 37 | ASSERT(env); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 38 | if (!env) { |
| 39 | AKLOGE("ERROR: JNIEnv is invalid"); |
| 40 | return -1; |
| 41 | } |
| 42 | if (!latinime::register_BinaryDictionary(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 43 | AKLOGE("ERROR: BinaryDictionary native registration failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 44 | return -1; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 45 | } |
Keisuke Kuroyanagi | 9e51c6c | 2014-03-05 12:49:04 +0900 | [diff] [blame] | 46 | if (!latinime::register_BinaryDictionaryUtils(env)) { |
| 47 | AKLOGE("ERROR: BinaryDictionaryUtils native registration failed"); |
| 48 | return -1; |
| 49 | } |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 50 | if (!latinime::register_DicTraverseSession(env)) { |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame] | 51 | AKLOGE("ERROR: DicTraverseSession native registration failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 52 | return -1; |
Satoshi Kataoka | c4e4dfe | 2012-08-08 19:40:44 +0900 | [diff] [blame] | 53 | } |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 54 | if (!latinime::register_ProximityInfo(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 55 | AKLOGE("ERROR: ProximityInfo native registration failed"); |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 56 | return -1; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 57 | } |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 58 | /* success -- return valid version number */ |
Ken Wakasa | aaefc4b | 2013-01-08 17:57:26 +0900 | [diff] [blame] | 59 | return JNI_VERSION_1_6; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 60 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 61 | |
| 62 | namespace latinime { |
Ken Wakasa | ad0c6d7 | 2013-06-04 19:16:47 +0900 | [diff] [blame] | 63 | int registerNativeMethods(JNIEnv *env, const char *const className, const JNINativeMethod *methods, |
| 64 | const int numMethods) { |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 65 | jclass clazz = env->FindClass(className); |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame] | 66 | if (!clazz) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 67 | AKLOGE("Native registration unable to find class '%s'", className); |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 68 | return JNI_FALSE; |
| 69 | } |
Ken Wakasa | 63b4831 | 2014-03-26 20:47:14 +0900 | [diff] [blame] | 70 | if (env->RegisterNatives(clazz, methods, numMethods) != 0) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 71 | AKLOGE("RegisterNatives failed for '%s'", className); |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 72 | env->DeleteLocalRef(clazz); |
| 73 | return JNI_FALSE; |
| 74 | } |
| 75 | env->DeleteLocalRef(clazz); |
| 76 | return JNI_TRUE; |
| 77 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 78 | } // namespace latinime |