Add support for writing byte arrays to parcels b/13418320 Cherrypicked from f0190bff38b6c29abbfc4a877442f71fc3d7dad8 https://googleplex-android-review.git.corp.google.com/#/c/433320/ Change-Id: I2285df9e9d3dc8a6a54055b13b352b81660bf45d
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 33b2f00..939cfbe 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h
@@ -101,6 +101,7 @@ status_t writeStrongBinder(const sp<IBinder>& val); status_t writeWeakBinder(const wp<IBinder>& val); status_t write(const Flattenable& val); + status_t writeByteArray(size_t len, const uint8_t *val); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index dea14bb..1162681 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp
@@ -617,6 +617,17 @@ return writeAligned(val); } +status_t Parcel::writeByteArray(size_t len, const uint8_t *val) { + if (!val) { + return writeAligned(-1); + } + status_t ret = writeAligned(len); + if (ret == NO_ERROR) { + ret = write(val, len * sizeof(*val)); + } + return ret; +} + status_t Parcel::writeInt64(int64_t val) { return writeAligned(val);