diff --git a/core/java/android/os/HwParcel.java b/core/java/android/os/HwParcel.java index e4d57184ede9f..180e8f46e93bf 100644 --- a/core/java/android/os/HwParcel.java +++ b/core/java/android/os/HwParcel.java @@ -53,21 +53,13 @@ public class HwParcel { public native final void writeDouble(double val); public native final void writeString(String val); - public native final void writeBoolArray(int size, boolean[] val); public native final void writeBoolVector(boolean[] val); - public native final void writeInt8Array(int size, byte[] val); public native final void writeInt8Vector(byte[] val); - public native final void writeInt16Array(int size, short[] val); public native final void writeInt16Vector(short[] val); - public native final void writeInt32Array(int size, int[] val); public native final void writeInt32Vector(int[] val); - public native final void writeInt64Array(int size, long[] val); public native final void writeInt64Vector(long[] val); - public native final void writeFloatArray(int size, float[] val); public native final void writeFloatVector(float[] val); - public native final void writeDoubleArray(int size, double[] val); public native final void writeDoubleVector(double[] val); - public native final void writeStringArray(int size, String[] val); public native final void writeStringVector(String[] val); public native final void writeStrongBinder(IHwBinder binder); @@ -82,21 +74,13 @@ public class HwParcel { public native final double readDouble(); public native final String readString(); - public native final boolean[] readBoolArray(int size); public native final boolean[] readBoolVector(); - public native final byte[] readInt8Array(int size); public native final byte[] readInt8Vector(); - public native final short[] readInt16Array(int size); public native final short[] readInt16Vector(); - public native final int[] readInt32Array(int size); public native final int[] readInt32Vector(); - public native final long[] readInt64Array(int size); public native final long[] readInt64Vector(); - public native final float[] readFloatArray(int size); public native final float[] readFloatVector(); - public native final double[] readDoubleArray(int size); public native final double[] readDoubleVector(); - public native final String[] readStringArray(int size); public native final String[] readStringVector(); public native final IHwBinder readStrongBinder(); diff --git a/core/jni/android_os_HwParcel.cpp b/core/jni/android_os_HwParcel.cpp index d453b29c0663e..5c879b8894a1c 100644 --- a/core/jni/android_os_HwParcel.cpp +++ b/core/jni/android_os_HwParcel.cpp @@ -431,35 +431,6 @@ static void JHwParcel_native_writeString( signalExceptionForError(env, err); } -#define DEFINE_PARCEL_ARRAY_WRITER(Suffix,Type) \ -static void JHwParcel_native_write ## Suffix ## Array( \ - JNIEnv *env, jobject thiz, jint size, Type ## Array valObj) { \ - if (valObj == NULL) { \ - jniThrowException(env, "java/lang/NullPointerException", NULL); \ - return; \ - } \ - \ - jsize len = env->GetArrayLength(valObj); \ - \ - if (len != size) { \ - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); \ - return; \ - } \ - \ - sp impl = JHwParcel::GetNativeContext(env, thiz); \ - \ - const Type *val = \ - impl->getStorage()->allocTemporary ## Suffix ## Array(env, valObj); \ - \ - hardware::Parcel *parcel = impl->getParcel(); \ - \ - size_t parentHandle; \ - status_t err = parcel->writeBuffer( \ - val, size * sizeof(*val), &parentHandle); \ - \ - signalExceptionForError(env, err); \ -} - #define DEFINE_PARCEL_VECTOR_WRITER(Suffix,Type) \ static void JHwParcel_native_write ## Suffix ## Vector( \ JNIEnv *env, jobject thiz, Type ## Array valObj) { \ @@ -491,13 +462,6 @@ static void JHwParcel_native_write ## Suffix ## Vector( \ signalExceptionForError(env, err); \ } -DEFINE_PARCEL_ARRAY_WRITER(Int8,jbyte) -DEFINE_PARCEL_ARRAY_WRITER(Int16,jshort) -DEFINE_PARCEL_ARRAY_WRITER(Int32,jint) -DEFINE_PARCEL_ARRAY_WRITER(Int64,jlong) -DEFINE_PARCEL_ARRAY_WRITER(Float,jfloat) -DEFINE_PARCEL_ARRAY_WRITER(Double,jdouble) - DEFINE_PARCEL_VECTOR_WRITER(Int8,jbyte) DEFINE_PARCEL_VECTOR_WRITER(Int16,jshort) DEFINE_PARCEL_VECTOR_WRITER(Int32,jint) @@ -505,43 +469,6 @@ DEFINE_PARCEL_VECTOR_WRITER(Int64,jlong) DEFINE_PARCEL_VECTOR_WRITER(Float,jfloat) DEFINE_PARCEL_VECTOR_WRITER(Double,jdouble) -static void JHwParcel_native_writeBoolArray( - JNIEnv *env, jobject thiz, jint size, jbooleanArray valObj) { - if (valObj == NULL) { - jniThrowException(env, "java/lang/NullPointerException", NULL); - return; - } - - jsize len = env->GetArrayLength(valObj); - - if (len != size) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); - return; - } - - sp impl = JHwParcel::GetNativeContext(env, thiz); - - jboolean *src = env->GetBooleanArrayElements(valObj, nullptr); - - bool *dst = - (bool *)impl->getStorage()->allocTemporaryStorage(size * sizeof(bool)); - - for (jint i = 0; i < size; ++i) { - dst[i] = src[i]; - } - - env->ReleaseBooleanArrayElements(valObj, src, 0 /* mode */); - src = nullptr; - - hardware::Parcel *parcel = impl->getParcel(); - - size_t parentHandle; - status_t err = parcel->writeBuffer( - dst, size * sizeof(*dst), &parentHandle); - - signalExceptionForError(env, err); -} - static void JHwParcel_native_writeBoolVector( JNIEnv *env, jobject thiz, jbooleanArray valObj) { if (valObj == NULL) { @@ -651,22 +578,6 @@ static jstring JHwParcel_native_readString(JNIEnv *env, jobject thiz) { return MakeStringObjFromHidlString(env, *s); } -#define DEFINE_PARCEL_ARRAY_READER(Suffix,Type,NewType) \ -static Type ## Array JHwParcel_native_read ## Suffix ## Array( \ - JNIEnv *env, jobject thiz, jint size) { \ - hardware::Parcel *parcel = \ - JHwParcel::GetNativeContext(env, thiz)->getParcel(); \ - \ - size_t parentHandle; \ - const Type *val = static_cast( \ - parcel->readBuffer(&parentHandle)); \ - \ - Type ## Array valObj = env->New ## NewType ## Array(size); \ - env->Set ## NewType ## ArrayRegion(valObj, 0, size, val); \ - \ - return valObj; \ -} - #define DEFINE_PARCEL_VECTOR_READER(Suffix,Type,NewType) \ static Type ## Array JHwParcel_native_read ## Suffix ## Vector( \ JNIEnv *env, jobject thiz) { \ @@ -703,13 +614,6 @@ static Type ## Array JHwParcel_native_read ## Suffix ## Vector( \ return valObj; \ } -DEFINE_PARCEL_ARRAY_READER(Int8,jbyte,Byte) -DEFINE_PARCEL_ARRAY_READER(Int16,jshort,Short) -DEFINE_PARCEL_ARRAY_READER(Int32,jint,Int) -DEFINE_PARCEL_ARRAY_READER(Int64,jlong,Long) -DEFINE_PARCEL_ARRAY_READER(Float,jfloat,Float) -DEFINE_PARCEL_ARRAY_READER(Double,jdouble,Double) - DEFINE_PARCEL_VECTOR_READER(Int8,jbyte,Byte) DEFINE_PARCEL_VECTOR_READER(Int16,jshort,Short) DEFINE_PARCEL_VECTOR_READER(Int32,jint,Int) @@ -717,25 +621,6 @@ DEFINE_PARCEL_VECTOR_READER(Int64,jlong,Long) DEFINE_PARCEL_VECTOR_READER(Float,jfloat,Float) DEFINE_PARCEL_VECTOR_READER(Double,jdouble,Double) -static jbooleanArray JHwParcel_native_readBoolArray( - JNIEnv *env, jobject thiz, jint size) { - hardware::Parcel *parcel = - JHwParcel::GetNativeContext(env, thiz)->getParcel(); - - size_t parentHandle; - const bool *val = static_cast( - parcel->readBuffer(&parentHandle)); - - jbooleanArray valObj = env->NewBooleanArray(size); - - for (jint i = 0; i < size; ++i) { - jboolean x = val[i]; - env->SetBooleanArrayRegion(valObj, i, 1, &x); - } - - return valObj; -} - static jbooleanArray JHwParcel_native_readBoolVector( JNIEnv *env, jobject thiz) { hardware::Parcel *parcel = @@ -797,80 +682,6 @@ static jobjectArray MakeStringArray( return arrayObj; } -static jobjectArray JHwParcel_native_readStringArray( - JNIEnv *env, jobject thiz, jint size) { - hardware::Parcel *parcel = - JHwParcel::GetNativeContext(env, thiz)->getParcel(); - - size_t parentHandle; - const hidl_string *val = static_cast( - parcel->readBuffer(&parentHandle)); - - if (val == NULL) { - signalExceptionForError(env, UNKNOWN_ERROR); - return NULL; - } - - status_t err = OK; - for (jint i = 0; (err == OK) && (i < size); ++i) { - err = const_cast(&val[i]) - ->readEmbeddedFromParcel( - *parcel, - parentHandle, - i * sizeof(hidl_string)); - } - - if (err != OK) { - signalExceptionForError(env, err); - return NULL; - } - - return MakeStringArray(env, val, size); -} - -static void JHwParcel_native_writeStringArray( - JNIEnv *env, jobject thiz, jint size, jobjectArray arrayObj) { - if (arrayObj == NULL) { - jniThrowException(env, "java/lang/NullPointerException", NULL); - return; - } - - jsize len = env->GetArrayLength(arrayObj); - - if (len != size) { - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); - return; - } - - sp impl = JHwParcel::GetNativeContext(env, thiz); - - hidl_string *strings = impl->getStorage()->allocStringArray(len); - - for (jsize i = 0; i < len; ++i) { - ScopedLocalRef stringObj( - env, - (jstring)env->GetObjectArrayElement(arrayObj, i)); - - const hidl_string *s = - impl->getStorage()->allocTemporaryString(env, stringObj.get()); - - strings[i].setToExternal(s->c_str(), s->size()); - } - - hardware::Parcel *parcel = impl->getParcel(); - - size_t parentHandle; - status_t err = parcel->writeBuffer( - strings, sizeof(hidl_string) * len, &parentHandle); - - for (jsize i = 0; (err == OK) && (i < len); ++i) { - err = strings[i].writeEmbeddedToParcel( - parcel, parentHandle, i * sizeof(hidl_string)); - } - - signalExceptionForError(env, err); -} - static jobjectArray JHwParcel_native_readStringVector( JNIEnv *env, jobject thiz) { typedef hidl_vec string_vec; @@ -1047,26 +858,16 @@ static JNINativeMethod gMethods[] = { { "writeString", "(Ljava/lang/String;)V", (void *)JHwParcel_native_writeString }, - { "writeBoolArray", "(I[Z)V", (void *)JHwParcel_native_writeBoolArray }, { "writeBoolVector", "([Z)V", (void *)JHwParcel_native_writeBoolVector }, - { "writeInt8Array", "(I[B)V", (void *)JHwParcel_native_writeInt8Array }, { "writeInt8Vector", "([B)V", (void *)JHwParcel_native_writeInt8Vector }, - { "writeInt16Array", "(I[S)V", (void *)JHwParcel_native_writeInt16Array }, { "writeInt16Vector", "([S)V", (void *)JHwParcel_native_writeInt16Vector }, - { "writeInt32Array", "(I[I)V", (void *)JHwParcel_native_writeInt32Array }, { "writeInt32Vector", "([I)V", (void *)JHwParcel_native_writeInt32Vector }, - { "writeInt64Array", "(I[J)V", (void *)JHwParcel_native_writeInt64Array }, { "writeInt64Vector", "([J)V", (void *)JHwParcel_native_writeInt64Vector }, - { "writeFloatArray", "(I[F)V", (void *)JHwParcel_native_writeFloatArray }, { "writeFloatVector", "([F)V", (void *)JHwParcel_native_writeFloatVector }, - { "writeDoubleArray", "(I[D)V", (void *)JHwParcel_native_writeDoubleArray }, { "writeDoubleVector", "([D)V", (void *)JHwParcel_native_writeDoubleVector }, - { "writeStringArray", "(I[Ljava/lang/String;)V", - (void *)JHwParcel_native_writeStringArray }, - { "writeStringVector", "([Ljava/lang/String;)V", (void *)JHwParcel_native_writeStringVector }, @@ -1087,24 +888,14 @@ static JNINativeMethod gMethods[] = { { "readString", "()Ljava/lang/String;", (void *)JHwParcel_native_readString }, - { "readBoolArray", "(I)[Z", (void *)JHwParcel_native_readBoolArray }, { "readBoolVector", "()[Z", (void *)JHwParcel_native_readBoolVector }, - { "readInt8Array", "(I)[B", (void *)JHwParcel_native_readInt8Array }, { "readInt8Vector", "()[B", (void *)JHwParcel_native_readInt8Vector }, - { "readInt16Array", "(I)[S", (void *)JHwParcel_native_readInt16Array }, { "readInt16Vector", "()[S", (void *)JHwParcel_native_readInt16Vector }, - { "readInt32Array", "(I)[I", (void *)JHwParcel_native_readInt32Array }, { "readInt32Vector", "()[I", (void *)JHwParcel_native_readInt32Vector }, - { "readInt64Array", "(I)[J", (void *)JHwParcel_native_readInt64Array }, { "readInt64Vector", "()[J", (void *)JHwParcel_native_readInt64Vector }, - { "readFloatArray", "(I)[F", (void *)JHwParcel_native_readFloatArray }, { "readFloatVector", "()[F", (void *)JHwParcel_native_readFloatVector }, - { "readDoubleArray", "(I)[D", (void *)JHwParcel_native_readDoubleArray }, { "readDoubleVector", "()[D", (void *)JHwParcel_native_readDoubleVector }, - { "readStringArray", "(I)[Ljava/lang/String;", - (void *)JHwParcel_native_readStringArray }, - { "readStringVector", "()[Ljava/lang/String;", (void *)JHwParcel_native_readStringVector }, diff --git a/core/jni/hwbinder/EphemeralStorage.cpp b/core/jni/hwbinder/EphemeralStorage.cpp index 187beeea4de1e..4996bc86cade5 100644 --- a/core/jni/hwbinder/EphemeralStorage.cpp +++ b/core/jni/hwbinder/EphemeralStorage.cpp @@ -71,21 +71,6 @@ const hidl_string *EphemeralStorage::allocTemporaryString( return s; } -#define DEFINE_ALLOC_ARRAY_METHODS(Suffix,Type,NewType) \ -const Type *EphemeralStorage::allocTemporary ## Suffix ## Array( \ - JNIEnv *env, Type ## Array arrayObj) { \ - Type ## Array obj = (Type ## Array)env->NewGlobalRef(arrayObj); \ - const Type *val = env->Get ## NewType ## ArrayElements(obj, NULL); \ - \ - Item item; \ - item.mType = TYPE_ ## Suffix ## _ARRAY; \ - item.mObj = obj; \ - item.mPtr = (void *)val; \ - mItems.push_back(item); \ - \ - return val; \ -} - #define DEFINE_ALLOC_VECTOR_METHODS(Suffix,Type,NewType) \ const hidl_vec *EphemeralStorage::allocTemporary ## Suffix ## Vector( \ JNIEnv *env, Type ## Array arrayObj) { \ @@ -107,13 +92,6 @@ const hidl_vec *EphemeralStorage::allocTemporary ## Suffix ## Vector( \ return vec; \ } -DEFINE_ALLOC_ARRAY_METHODS(Int8,jbyte,Byte) -DEFINE_ALLOC_ARRAY_METHODS(Int16,jshort,Short) -DEFINE_ALLOC_ARRAY_METHODS(Int32,jint,Int) -DEFINE_ALLOC_ARRAY_METHODS(Int64,jlong,Long) -DEFINE_ALLOC_ARRAY_METHODS(Float,jfloat,Float) -DEFINE_ALLOC_ARRAY_METHODS(Double,jdouble,Double) - DEFINE_ALLOC_VECTOR_METHODS(Int8,jbyte,Byte) DEFINE_ALLOC_VECTOR_METHODS(Int16,jshort,Short) DEFINE_ALLOC_VECTOR_METHODS(Int32,jint,Int) diff --git a/core/jni/hwbinder/EphemeralStorage.h b/core/jni/hwbinder/EphemeralStorage.h index b02ed9f5ea69a..f07c782bfdf78 100644 --- a/core/jni/hwbinder/EphemeralStorage.h +++ b/core/jni/hwbinder/EphemeralStorage.h @@ -26,9 +26,6 @@ namespace android { #define DECLARE_ALLOC_METHODS(Suffix,Type) \ - const Type *allocTemporary ## Suffix ## Array( \ - JNIEnv *env, Type ## Array arrayObj); \ - \ const ::android::hardware::hidl_vec * \ allocTemporary ## Suffix ## Vector( \ JNIEnv *env, Type ## Array arrayObj);