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