2011-02-22 08:28:55 +00:00
|
|
|
/*
|
2013-01-08 08:57:26 +00:00
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
2012-07-25 08:51:43 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2013-01-08 08:57:26 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-07-25 08:51:43 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
#define LOG_TAG "LatinIME: jni"
|
|
|
|
|
2013-04-08 08:08:19 +00:00
|
|
|
#include "jni_common.h"
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
#include "com_android_inputmethod_keyboard_ProximityInfo.h"
|
|
|
|
#include "com_android_inputmethod_latin_BinaryDictionary.h"
|
2014-03-05 03:49:04 +00:00
|
|
|
#include "com_android_inputmethod_latin_BinaryDictionaryUtils.h"
|
2012-08-08 10:40:44 +00:00
|
|
|
#include "com_android_inputmethod_latin_DicTraverseSession.h"
|
2012-05-16 14:05:32 +00:00
|
|
|
#include "defines.h"
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the JNI version on success, -1 on failure.
|
|
|
|
*/
|
2012-07-25 08:51:43 +00:00
|
|
|
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
|
|
JNIEnv *env = 0;
|
2011-02-22 08:28:55 +00:00
|
|
|
|
2012-08-14 05:22:27 +00:00
|
|
|
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("ERROR: GetEnv failed");
|
2013-01-08 08:57:26 +00:00
|
|
|
return -1;
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
2013-01-09 06:21:44 +00:00
|
|
|
ASSERT(env);
|
2013-01-08 08:57:26 +00:00
|
|
|
if (!env) {
|
|
|
|
AKLOGE("ERROR: JNIEnv is invalid");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!latinime::register_BinaryDictionary(env)) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("ERROR: BinaryDictionary native registration failed");
|
2014-03-05 03:49:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!latinime::register_BinaryDictionaryUtils(env)) {
|
|
|
|
AKLOGE("ERROR: BinaryDictionaryUtils native registration failed");
|
2013-01-08 08:57:26 +00:00
|
|
|
return -1;
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
2013-01-08 08:57:26 +00:00
|
|
|
if (!latinime::register_DicTraverseSession(env)) {
|
2012-08-08 10:40:44 +00:00
|
|
|
AKLOGE("ERROR: DicTraverseSession native registration failed");
|
2013-01-08 08:57:26 +00:00
|
|
|
return -1;
|
2012-08-08 10:40:44 +00:00
|
|
|
}
|
2013-01-08 08:57:26 +00:00
|
|
|
if (!latinime::register_ProximityInfo(env)) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("ERROR: ProximityInfo native registration failed");
|
2013-01-08 08:57:26 +00:00
|
|
|
return -1;
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
|
|
|
/* success -- return valid version number */
|
2013-01-08 08:57:26 +00:00
|
|
|
return JNI_VERSION_1_6;
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
2011-06-18 04:09:55 +00:00
|
|
|
|
|
|
|
namespace latinime {
|
2013-06-04 10:16:47 +00:00
|
|
|
int registerNativeMethods(JNIEnv *env, const char *const className, const JNINativeMethod *methods,
|
|
|
|
const int numMethods) {
|
2011-06-18 04:09:55 +00:00
|
|
|
jclass clazz = env->FindClass(className);
|
2012-07-30 07:27:44 +00:00
|
|
|
if (!clazz) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("Native registration unable to find class '%s'", className);
|
2011-06-18 04:09:55 +00:00
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
if (env->RegisterNatives(clazz, methods, numMethods) < 0) {
|
2012-01-13 09:01:22 +00:00
|
|
|
AKLOGE("RegisterNatives failed for '%s'", className);
|
2011-06-18 04:09:55 +00:00
|
|
|
env->DeleteLocalRef(clazz);
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
env->DeleteLocalRef(clazz);
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
} // namespace latinime
|