1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #define LOG_TAG "ObjectStreamClass" 19 20 #include "JNIHelp.h" 21 #include "JniConstants.h" 22 23 static jobject getSignature(JNIEnv* env, jclass c, jobject object) { 24 jmethodID mid = env->GetMethodID(c, "getSignature", "()Ljava/lang/String;"); 25 if (!mid) { 26 return NULL; 27 } 28 jclass objectClass = env->GetObjectClass(object); 29 return env->CallNonvirtualObjectMethod(object, objectClass, mid); 30 } 31 32 static jobject ObjectStreamClass_getFieldSignature(JNIEnv* env, jclass, jobject field) { 33 return getSignature(env, JniConstants::fieldClass, field); 34 } 35 36 static jobject ObjectStreamClass_getMethodSignature(JNIEnv* env, jclass, jobject method) { 37 return getSignature(env, JniConstants::methodClass, method); 38 } 39 40 static jobject ObjectStreamClass_getConstructorSignature(JNIEnv* env, jclass, jobject constructor) { 41 return getSignature(env, JniConstants::constructorClass, constructor); 42 } 43 44 static jboolean ObjectStreamClass_hasClinit(JNIEnv * env, jclass, jclass targetClass) { 45 jmethodID mid = env->GetStaticMethodID(targetClass, "<clinit>", "()V"); 46 env->ExceptionClear(); 47 return (mid != 0); 48 } 49 50 static JNINativeMethod gMethods[] = { 51 NATIVE_METHOD(ObjectStreamClass, getConstructorSignature, "(Ljava/lang/reflect/Constructor;)Ljava/lang/String;"), 52 NATIVE_METHOD(ObjectStreamClass, getFieldSignature, "(Ljava/lang/reflect/Field;)Ljava/lang/String;"), 53 NATIVE_METHOD(ObjectStreamClass, getMethodSignature, "(Ljava/lang/reflect/Method;)Ljava/lang/String;"), 54 NATIVE_METHOD(ObjectStreamClass, hasClinit, "(Ljava/lang/Class;)Z"), 55 }; 56 int register_java_io_ObjectStreamClass(JNIEnv* env) { 57 return jniRegisterNativeMethods(env, "java/io/ObjectStreamClass", gMethods, NELEM(gMethods)); 58 } 59