blob: 3a8f4362d957487c919dd2b2a481aaa7d1556853 [file] [log] [blame]
satok8fbd5522011-02-22 17:28:55 +09001/*
Ken Wakasaaaefc4b2013-01-08 17:57:26 +09002 * Copyright (C) 2011 The Android Open Source Project
Ken Wakasa0bbb9172012-07-25 17:51:43 +09003 *
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 Wakasaaaefc4b2013-01-08 17:57:26 +09008 * http://www.apache.org/licenses/LICENSE-2.0
Ken Wakasa0bbb9172012-07-25 17:51:43 +09009 *
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 */
satok8fbd5522011-02-22 17:28:55 +090016
17#define LOG_TAG "LatinIME: jni"
18
Ken Wakasab68e7342013-04-08 17:08:19 +090019#include "jni_common.h"
20
Jean Chalarde7870a22013-08-12 12:44:04 +090021#ifndef HOST_TOOL
satok8fbd5522011-02-22 17:28:55 +090022#include "com_android_inputmethod_keyboard_ProximityInfo.h"
23#include "com_android_inputmethod_latin_BinaryDictionary.h"
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090024#include "com_android_inputmethod_latin_DicTraverseSession.h"
Jean Chalarde7870a22013-08-12 12:44:04 +090025#endif
Yuichiro Hanada112257e2013-08-20 15:48:16 +090026#include "com_android_inputmethod_latin_makedict_Ver3DictDecoder.h"
Ken Wakasa3b088a22012-05-16 23:05:32 +090027#include "defines.h"
satok8fbd5522011-02-22 17:28:55 +090028
satok8fbd5522011-02-22 17:28:55 +090029/*
30 * Returns the JNI version on success, -1 on failure.
31 */
Ken Wakasa0bbb9172012-07-25 17:51:43 +090032jint JNI_OnLoad(JavaVM *vm, void *reserved) {
33 JNIEnv *env = 0;
satok8fbd5522011-02-22 17:28:55 +090034
Ken Wakasa34710b02012-08-14 14:22:27 +090035 if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
satok9fb6f472012-01-13 18:01:22 +090036 AKLOGE("ERROR: GetEnv failed");
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090037 return -1;
satok8fbd5522011-02-22 17:28:55 +090038 }
Ken Wakasaccebd5c2013-01-09 15:21:44 +090039 ASSERT(env);
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090040 if (!env) {
41 AKLOGE("ERROR: JNIEnv is invalid");
42 return -1;
43 }
Jean Chalarde7870a22013-08-12 12:44:04 +090044#ifndef HOST_TOOL
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090045 if (!latinime::register_BinaryDictionary(env)) {
satok9fb6f472012-01-13 18:01:22 +090046 AKLOGE("ERROR: BinaryDictionary native registration failed");
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090047 return -1;
satok8fbd5522011-02-22 17:28:55 +090048 }
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090049 if (!latinime::register_DicTraverseSession(env)) {
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090050 AKLOGE("ERROR: DicTraverseSession native registration failed");
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090051 return -1;
Satoshi Kataokac4e4dfe2012-08-08 19:40:44 +090052 }
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090053 if (!latinime::register_ProximityInfo(env)) {
satok9fb6f472012-01-13 18:01:22 +090054 AKLOGE("ERROR: ProximityInfo native registration failed");
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090055 return -1;
satok8fbd5522011-02-22 17:28:55 +090056 }
Jean Chalarde7870a22013-08-12 12:44:04 +090057#endif
Yuichiro Hanada112257e2013-08-20 15:48:16 +090058 if (!latinime::register_Ver3DictDecoder(env)) {
59 AKLOGE("ERROR: Ver3DictDecoder native registration failed");
Jean Chalarde7870a22013-08-12 12:44:04 +090060 return -1;
61 }
satok8fbd5522011-02-22 17:28:55 +090062 /* success -- return valid version number */
Ken Wakasaaaefc4b2013-01-08 17:57:26 +090063 return JNI_VERSION_1_6;
satok8fbd5522011-02-22 17:28:55 +090064}
Ken Wakasace9e52a2011-06-18 13:09:55 +090065
66namespace latinime {
Ken Wakasaad0c6d72013-06-04 19:16:47 +090067int registerNativeMethods(JNIEnv *env, const char *const className, const JNINativeMethod *methods,
68 const int numMethods) {
Ken Wakasace9e52a2011-06-18 13:09:55 +090069 jclass clazz = env->FindClass(className);
Ken Wakasa5460ea32012-07-30 16:27:44 +090070 if (!clazz) {
satok9fb6f472012-01-13 18:01:22 +090071 AKLOGE("Native registration unable to find class '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090072 return JNI_FALSE;
73 }
74 if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
satok9fb6f472012-01-13 18:01:22 +090075 AKLOGE("RegisterNatives failed for '%s'", className);
Ken Wakasace9e52a2011-06-18 13:09:55 +090076 env->DeleteLocalRef(clazz);
77 return JNI_FALSE;
78 }
79 env->DeleteLocalRef(clazz);
80 return JNI_TRUE;
81}
Ken Wakasace9e52a2011-06-18 13:09:55 +090082} // namespace latinime