1 /* 2 * Copyright (C) 2010 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 #define LOG_TAG "JniConstants" 18 19 #include "ALog-priv.h" 20 #include "JniConstants.h" 21 #include "ScopedLocalRef.h" 22 23 #include <stdlib.h> 24 25 jclass JniConstants::bidiRunClass; 26 jclass JniConstants::bigDecimalClass; 27 jclass JniConstants::booleanClass; 28 jclass JniConstants::byteArrayClass; 29 jclass JniConstants::byteClass; 30 jclass JniConstants::calendarClass; 31 jclass JniConstants::characterClass; 32 jclass JniConstants::charsetICUClass; 33 jclass JniConstants::constructorClass; 34 jclass JniConstants::deflaterClass; 35 jclass JniConstants::doubleClass; 36 jclass JniConstants::errnoExceptionClass; 37 jclass JniConstants::fieldClass; 38 jclass JniConstants::fieldPositionIteratorClass; 39 jclass JniConstants::fileDescriptorClass; 40 jclass JniConstants::floatClass; 41 jclass JniConstants::gaiExceptionClass; 42 jclass JniConstants::inet6AddressClass; 43 jclass JniConstants::inetAddressClass; 44 jclass JniConstants::inetSocketAddressClass; 45 jclass JniConstants::inetUnixAddressClass; 46 jclass JniConstants::inflaterClass; 47 jclass JniConstants::inputStreamClass; 48 jclass JniConstants::integerClass; 49 jclass JniConstants::localeDataClass; 50 jclass JniConstants::longClass; 51 jclass JniConstants::methodClass; 52 jclass JniConstants::mutableIntClass; 53 jclass JniConstants::mutableLongClass; 54 jclass JniConstants::objectClass; 55 jclass JniConstants::objectArrayClass; 56 jclass JniConstants::outputStreamClass; 57 jclass JniConstants::parsePositionClass; 58 jclass JniConstants::patternSyntaxExceptionClass; 59 jclass JniConstants::realToStringClass; 60 jclass JniConstants::referenceClass; 61 jclass JniConstants::shortClass; 62 jclass JniConstants::socketClass; 63 jclass JniConstants::socketImplClass; 64 jclass JniConstants::stringClass; 65 jclass JniConstants::structAddrinfoClass; 66 jclass JniConstants::structFlockClass; 67 jclass JniConstants::structGroupReqClass; 68 jclass JniConstants::structLingerClass; 69 jclass JniConstants::structPasswdClass; 70 jclass JniConstants::structPollfdClass; 71 jclass JniConstants::structStatClass; 72 jclass JniConstants::structStatVfsClass; 73 jclass JniConstants::structTimevalClass; 74 jclass JniConstants::structUcredClass; 75 jclass JniConstants::structUtsnameClass; 76 77 static jclass findClass(JNIEnv* env, const char* name) { 78 ScopedLocalRef<jclass> localClass(env, env->FindClass(name)); 79 jclass result = reinterpret_cast<jclass>(env->NewGlobalRef(localClass.get())); 80 if (result == NULL) { 81 ALOGE("failed to find class '%s'", name); 82 abort(); 83 } 84 return result; 85 } 86 87 void JniConstants::init(JNIEnv* env) { 88 bidiRunClass = findClass(env, "java/text/Bidi$Run"); 89 bigDecimalClass = findClass(env, "java/math/BigDecimal"); 90 booleanClass = findClass(env, "java/lang/Boolean"); 91 byteClass = findClass(env, "java/lang/Byte"); 92 byteArrayClass = findClass(env, "[B"); 93 calendarClass = findClass(env, "java/util/Calendar"); 94 characterClass = findClass(env, "java/lang/Character"); 95 charsetICUClass = findClass(env, "java/nio/charset/CharsetICU"); 96 constructorClass = findClass(env, "java/lang/reflect/Constructor"); 97 floatClass = findClass(env, "java/lang/Float"); 98 deflaterClass = findClass(env, "java/util/zip/Deflater"); 99 doubleClass = findClass(env, "java/lang/Double"); 100 errnoExceptionClass = findClass(env, "libcore/io/ErrnoException"); 101 fieldClass = findClass(env, "java/lang/reflect/Field"); 102 fieldPositionIteratorClass = findClass(env, "libcore/icu/NativeDecimalFormat$FieldPositionIterator"); 103 fileDescriptorClass = findClass(env, "java/io/FileDescriptor"); 104 gaiExceptionClass = findClass(env, "libcore/io/GaiException"); 105 inet6AddressClass = findClass(env, "java/net/Inet6Address"); 106 inetAddressClass = findClass(env, "java/net/InetAddress"); 107 inetSocketAddressClass = findClass(env, "java/net/InetSocketAddress"); 108 inetUnixAddressClass = findClass(env, "java/net/InetUnixAddress"); 109 inflaterClass = findClass(env, "java/util/zip/Inflater"); 110 inputStreamClass = findClass(env, "java/io/InputStream"); 111 integerClass = findClass(env, "java/lang/Integer"); 112 localeDataClass = findClass(env, "libcore/icu/LocaleData"); 113 longClass = findClass(env, "java/lang/Long"); 114 methodClass = findClass(env, "java/lang/reflect/Method"); 115 mutableIntClass = findClass(env, "libcore/util/MutableInt"); 116 mutableLongClass = findClass(env, "libcore/util/MutableLong"); 117 objectClass = findClass(env, "java/lang/Object"); 118 objectArrayClass = findClass(env, "[Ljava/lang/Object;"); 119 outputStreamClass = findClass(env, "java/io/OutputStream"); 120 parsePositionClass = findClass(env, "java/text/ParsePosition"); 121 patternSyntaxExceptionClass = findClass(env, "java/util/regex/PatternSyntaxException"); 122 realToStringClass = findClass(env, "java/lang/RealToString"); 123 referenceClass = findClass(env, "java/lang/ref/Reference"); 124 shortClass = findClass(env, "java/lang/Short"); 125 socketClass = findClass(env, "java/net/Socket"); 126 socketImplClass = findClass(env, "java/net/SocketImpl"); 127 stringClass = findClass(env, "java/lang/String"); 128 structAddrinfoClass = findClass(env, "libcore/io/StructAddrinfo"); 129 structFlockClass = findClass(env, "libcore/io/StructFlock"); 130 structGroupReqClass = findClass(env, "libcore/io/StructGroupReq"); 131 structLingerClass = findClass(env, "libcore/io/StructLinger"); 132 structPasswdClass = findClass(env, "libcore/io/StructPasswd"); 133 structPollfdClass = findClass(env, "libcore/io/StructPollfd"); 134 structStatClass = findClass(env, "libcore/io/StructStat"); 135 structStatVfsClass = findClass(env, "libcore/io/StructStatVfs"); 136 structTimevalClass = findClass(env, "libcore/io/StructTimeval"); 137 structUcredClass = findClass(env, "libcore/io/StructUcred"); 138 structUtsnameClass = findClass(env, "libcore/io/StructUtsname"); 139 } 140