satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +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 | * |
| 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 | */ |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 16 | |
| 17 | #define LOG_TAG "LatinIME: jni" |
| 18 | |
| 19 | #include "com_android_inputmethod_keyboard_ProximityInfo.h" |
| 20 | #include "com_android_inputmethod_latin_BinaryDictionary.h" |
Ken Wakasa | e7b34b9 | 2012-06-08 19:05:47 +0900 | [diff] [blame] | 21 | #include "com_android_inputmethod_latin_NativeUtils.h" |
Ken Wakasa | 3b088a2 | 2012-05-16 23:05:32 +0900 | [diff] [blame] | 22 | #include "defines.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 23 | #include "jni.h" |
| 24 | #include "proximity_info.h" |
| 25 | |
| 26 | #include <assert.h> |
| 27 | #include <errno.h> |
| 28 | #include <stdio.h> |
| 29 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 30 | using namespace latinime; |
| 31 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 32 | /* |
| 33 | * Returns the JNI version on success, -1 on failure. |
| 34 | */ |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 35 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
| 36 | JNIEnv *env = 0; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 37 | jint result = -1; |
| 38 | |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame^] | 39 | if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 40 | AKLOGE("ERROR: GetEnv failed"); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 41 | goto bail; |
| 42 | } |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame^] | 43 | assert(env); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 44 | |
| 45 | if (!register_BinaryDictionary(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 46 | AKLOGE("ERROR: BinaryDictionary native registration failed"); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 47 | goto bail; |
| 48 | } |
| 49 | |
| 50 | if (!register_ProximityInfo(env)) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 51 | AKLOGE("ERROR: ProximityInfo native registration failed"); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 52 | goto bail; |
| 53 | } |
| 54 | |
Ken Wakasa | e7b34b9 | 2012-06-08 19:05:47 +0900 | [diff] [blame] | 55 | if (!register_NativeUtils(env)) { |
| 56 | AKLOGE("ERROR: NativeUtils native registration failed"); |
| 57 | goto bail; |
| 58 | } |
| 59 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 60 | /* success -- return valid version number */ |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame^] | 61 | result = JNI_VERSION_1_6; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 62 | |
| 63 | bail: |
| 64 | return result; |
| 65 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 66 | |
| 67 | namespace latinime { |
| 68 | |
Ken Wakasa | 0bbb917 | 2012-07-25 17:51:43 +0900 | [diff] [blame] | 69 | int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 70 | int numMethods) { |
| 71 | jclass clazz = env->FindClass(className); |
Ken Wakasa | 5460ea3 | 2012-07-30 16:27:44 +0900 | [diff] [blame^] | 72 | if (!clazz) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 73 | AKLOGE("Native registration unable to find class '%s'", className); |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 74 | return JNI_FALSE; |
| 75 | } |
| 76 | if (env->RegisterNatives(clazz, methods, numMethods) < 0) { |
satok | 9fb6f47 | 2012-01-13 18:01:22 +0900 | [diff] [blame] | 77 | AKLOGE("RegisterNatives failed for '%s'", className); |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 78 | env->DeleteLocalRef(clazz); |
| 79 | return JNI_FALSE; |
| 80 | } |
| 81 | env->DeleteLocalRef(clazz); |
| 82 | return JNI_TRUE; |
| 83 | } |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 84 | } // namespace latinime |