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 "JniConstants.h"
18
19 using namespace conscrypt;
20
21 JavaVM *JniConstants::gJavaVM;
22 jclass JniConstants::cryptoUpcallsClass;
23 jclass JniConstants::openSslInputStreamClass;
24 jclass JniConstants::nativeRefClass;
25
26 jclass JniConstants::byteArrayClass;
27 jclass JniConstants::calendarClass;
28 jclass JniConstants::objectClass;
29 jclass JniConstants::objectArrayClass;
30 jclass JniConstants::integerClass;
31 jclass JniConstants::inputStreamClass;
32 jclass JniConstants::outputStreamClass;
33 jclass JniConstants::stringClass;
34
35 jfieldID JniConstants::nativeRef_context;
36
37 jmethodID JniConstants::calendar_setMethod;
38 jmethodID JniConstants::inputStream_readMethod;
39 jmethodID JniConstants::integer_valueOfMethod;
40 jmethodID JniConstants::openSslInputStream_readLineMethod;
41 jmethodID JniConstants::outputStream_writeMethod;
42 jmethodID JniConstants::outputStream_flushMethod;
43
init(JavaVM * vm,JNIEnv * env)44 void JniConstants::init(JavaVM *vm, JNIEnv *env) {
45 gJavaVM = vm;
46
47 byteArrayClass = JniUtil::findClass(env, "[B");
48 calendarClass = JniUtil::findClass(env, "java/util/Calendar");
49 inputStreamClass = JniUtil::findClass(env, "java/io/InputStream");
50 integerClass = JniUtil::findClass(env, "java/lang/Integer");
51 objectClass = JniUtil::findClass(env, "java/lang/Object");
52 objectArrayClass = JniUtil::findClass(env, "[Ljava/lang/Object;");
53 outputStreamClass = JniUtil::findClass(env, "java/io/OutputStream");
54 stringClass = JniUtil::findClass(env, "java/lang/String");
55
56 cryptoUpcallsClass = JniUtil::getGlobalRefToClass(
57 env, TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/CryptoUpcalls");
58 nativeRefClass = JniUtil::getGlobalRefToClass(
59 env, TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/NativeRef");
60 openSslInputStreamClass = JniUtil::getGlobalRefToClass(
61 env, TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/OpenSSLBIOInputStream");
62
63 nativeRef_context = JniUtil::getFieldRef(env, nativeRefClass, "context", "J");
64
65 calendar_setMethod = JniUtil::getMethodRef(env, calendarClass, "set", "(IIIIII)V");
66 inputStream_readMethod = JniUtil::getMethodRef(env, inputStreamClass, "read", "([B)I");
67 integer_valueOfMethod =
68 env->GetStaticMethodID(integerClass, "valueOf", "(I)Ljava/lang/Integer;");
69 openSslInputStream_readLineMethod =
70 JniUtil::getMethodRef(env, openSslInputStreamClass, "gets", "([B)I");
71 outputStream_writeMethod = JniUtil::getMethodRef(env, outputStreamClass, "write", "([B)V");
72 outputStream_flushMethod = JniUtil::getMethodRef(env, outputStreamClass, "flush", "()V");
73 }
74