1 /*
2 * Copyright 2017, 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 #include "jni.h"
18
19 #include <android/log.h>
20
21 #define ALOG(priority, tag, ...) ((void)__android_log_print(ANDROID_##priority, tag, __VA_ARGS__))
22
23 #define ALOGE(...) ALOG(LOG_ERROR, NULL, __VA_ARGS__)
24
25 #include "../../StaticSharedNativeLibProvider/native/version.h"
26
27 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28
android_os_lib_consumer_UseSharedLibraryTest_getVersion(JNIEnv *,jclass)29 static jint android_os_lib_consumer_UseSharedLibraryTest_getVersion(JNIEnv*, jclass) {
30 return StaticSharedLib::android_os_lib_provider_getVersion();
31 }
32
registerNativeMethods(JNIEnv * env,const char * className,JNINativeMethod * gMethods,int numMethods)33 static int registerNativeMethods(JNIEnv* env, const char* className,
34 JNINativeMethod* gMethods, int numMethods) {
35 jclass clazz;
36 clazz = env->FindClass(className);
37 if (clazz == NULL) {
38 ALOGE("Native registration unable to find class '%s'", className);
39 return JNI_FALSE;
40 }
41 if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
42 ALOGE("RegisterNatives failed for '%s'", className);
43 return JNI_FALSE;
44 }
45 return JNI_TRUE;
46 }
47
JNI_OnLoad(JavaVM * vm,void *)48 extern "C" jint JNI_OnLoad(JavaVM* vm, void*) {
49 JNIEnv *env;
50 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
51 return -1;
52 }
53
54 static JNINativeMethod gMethods[] = {
55 { "getVersion", "()I", (void*) android_os_lib_consumer_UseSharedLibraryTest_getVersion }
56 };
57
58 registerNativeMethods(env, "android/os/lib/consumer/UseSharedLibraryTest",
59 gMethods, ARRAY_SIZE(gMethods));
60
61 return JNI_VERSION_1_6;
62 }
63
64