diff options
author | Steven Moreland <smoreland@google.com> | 2021-09-08 00:29:29 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-09-08 00:29:29 +0000 |
commit | 0f2729a96e0c225ca389d3b81ea172e252545c53 (patch) | |
tree | 8b3f4d99193e35bd0187214cbb2937dacc3c0a07 | |
parent | c8eb0a1df79925a039b873c202c03c10ca0e23ee (diff) | |
parent | 580ab9141167d39b511321bdab623fff3789c32e (diff) | |
download | base-0f2729a96e0c225ca389d3b81ea172e252545c53.tar.gz |
Merge "Parcel: markForBinder"
-rw-r--r-- | core/java/android/os/Parcel.java | 28 | ||||
-rw-r--r-- | core/jni/android_os_Parcel.cpp | 13 |
2 files changed, 39 insertions, 2 deletions
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 00db972bf709..d23b219b055e 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -282,6 +282,8 @@ public final class Parcel { @CriticalNative private static native void nativeMarkSensitive(long nativePtr); + @FastNative + private static native void nativeMarkForBinder(long nativePtr, IBinder binder); @CriticalNative private static native int nativeDataSize(long nativePtr); @CriticalNative @@ -498,6 +500,16 @@ public final class Parcel { /** * Parcel data should be zero'd before realloc'd or deleted. + * + * Note: currently this feature requires multiple things to work in concert: + * - markSensitive must be called on every relative Parcel + * - FLAG_CLEAR_BUF must be passed into the kernel + * This requires having code which does the right thing in every method and in every backend + * of AIDL. Rather than exposing this API, it should be replaced with a single API on + * IBinder objects which can be called once, and the information should be fed into the + * Parcel using markForBinder APIs. In terms of code size and number of API calls, this is + * much more extensible. + * * @hide */ public final void markSensitive() { @@ -505,9 +517,23 @@ public final class Parcel { } /** + * Associate this parcel with a binder object. This marks the parcel as being prepared for a + * transaction on this specific binder object. Based on this, the format of the wire binder + * protocol may change. This should be called before any data is written to the parcel. If this + * is called multiple times, this will only be marked for the last binder. For future + * compatibility, it is recommended to call this on all parcels which are being sent over + * binder. + * + * @hide + */ + public void markForBinder(@NonNull IBinder binder) { + nativeMarkForBinder(mNativePtr, binder); + } + + /** * Returns the total amount of data contained in the parcel. */ - public final int dataSize() { + public int dataSize() { return nativeDataSize(mNativePtr); } diff --git a/core/jni/android_os_Parcel.cpp b/core/jni/android_os_Parcel.cpp index 241570a7f9d3..ac320386c3f3 100644 --- a/core/jni/android_os_Parcel.cpp +++ b/core/jni/android_os_Parcel.cpp @@ -98,6 +98,15 @@ static void android_os_Parcel_markSensitive(jlong nativePtr) } } +static void android_os_Parcel_markForBinder(JNIEnv* env, jclass clazz, jlong nativePtr, + jobject binder) +{ + Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr); + if (parcel) { + parcel->markForBinder(ibinderForJavaObject(env, binder)); + } +} + static jint android_os_Parcel_dataSize(jlong nativePtr) { Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr); @@ -766,7 +775,9 @@ static jboolean android_os_Parcel_replaceCallingWorkSourceUid(jlong nativePtr, j static const JNINativeMethod gParcelMethods[] = { // @CriticalNative - {"nativeMarkSensitive", "(J)V", (void*)android_os_Parcel_markSensitive}, + {"nativeMarkSensitive", "(J)V", (void*)android_os_Parcel_markSensitive}, + // @FastNative + {"nativeMarkForBinder", "(JLandroid/os/IBinder;)V", (void*)android_os_Parcel_markForBinder}, // @CriticalNative {"nativeDataSize", "(J)I", (void*)android_os_Parcel_dataSize}, // @CriticalNative |