1 /* 2 * Copyright (C) 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 "CompatibilityCloseMonitor.h" 20 #include "JniConstants.h" 21 #include "NativeCrypto.h" 22 #include "macros.h" 23 24 #ifndef CONSCRYPT_JNI_VERSION 25 #define CONSCRYPT_JNI_VERSION JNI_VERSION_1_6 26 #endif // !CONSCRYPT_JNI_VERSION 27 28 using namespace conscrypt; 29 30 // Give client libs everything they need to initialize our JNI 31 jint libconscrypt_JNI_OnLoad(JavaVM* vm, void*) { 32 JNIEnv* env; 33 if (vm->GetEnv((void**)&env, CONSCRYPT_JNI_VERSION) != JNI_OK) { 34 ALOGE("Could not get JNIEnv"); 35 return JNI_ERR; 36 } 37 38 // Initialize the JNI constants. 39 JniConstants::init(vm, env); 40 41 // Register all of the native JNI methods. 42 NativeCrypto::registerNativeMethods(env); 43 44 // Perform static initialization of the close monitor (if required on this platform). 45 CompatibilityCloseMonitor::init(); 46 return CONSCRYPT_JNI_VERSION; 47 } 48 49 #ifdef STATIC_LIB 50 51 // A version of OnLoad called when the Conscrypt library has been statically linked to the JVM (For 52 // Java >= 1.8). The manner in which the library is statically linked is implementation specific. 53 // 54 // See http://openjdk.java.net/jeps/178 55 CONSCRYPT_PUBLIC jint JNI_OnLoad_conscrypt(JavaVM* vm, void* reserved) { 56 return libconscrypt_JNI_OnLoad(vm, reserved); 57 } 58 59 #else // !STATIC_LIB 60 61 // Method called by the JVM when the Conscrypt shared library is loaded. 62 CONSCRYPT_PUBLIC jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { 63 return libconscrypt_JNI_OnLoad(vm, reserved); 64 } 65 66 #endif // !STATIC_LIB