summaryrefslogtreecommitdiffstats
path: root/libs/binder/Parcel.cpp
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2013-09-05 08:41:06 -0700
committerMike Lockwood <lockwood@google.com>2013-09-05 08:43:22 -0700
commitcbe36fe1ec21e22e6649d47144c91260ba51d753 (patch)
tree0f3d6dcf289ae91d626554b2c7500138dfa5c52d /libs/binder/Parcel.cpp
parent31344a6d4d77a763db5ce627932bd6ccc24353a3 (diff)
downloadframeworks_native-cbe36fe1ec21e22e6649d47144c91260ba51d753.zip
frameworks_native-cbe36fe1ec21e22e6649d47144c91260ba51d753.tar.gz
frameworks_native-cbe36fe1ec21e22e6649d47144c91260ba51d753.tar.bz2
Add support for sending and receiving ParcelFileDescriptors from native Binder code
Change-Id: I7f308e28ebac0755628e19c9b4d0d7399341b435
Diffstat (limited to 'libs/binder/Parcel.cpp')
-rw-r--r--libs/binder/Parcel.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 7a5919f..d130d7c 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -750,6 +750,32 @@ status_t Parcel::writeDupFileDescriptor(int fd)
return err;
}
+// WARNING: This method must stay in sync with
+// Parcelable.Creator<ParcelFileDescriptor> CREATOR
+// in frameworks/base/core/java/android/os/ParcelFileDescriptor.java
+status_t Parcel::writeParcelFileDescriptor(int fd, int commChannel) {
+ status_t status;
+
+ if (fd < 0) {
+ status = writeInt32(0); // ParcelFileDescriptor is null
+ if (status) return status;
+ } else {
+ status = writeInt32(1); // ParcelFileDescriptor is not null
+ if (status) return status;
+ status = writeDupFileDescriptor(fd);
+ if (status) return status;
+ if (commChannel < 0) {
+ status = writeInt32(0); // commChannel is null
+ if (status) return status;
+ } else {
+ status = writeInt32(1); // commChannel is not null
+ if (status) return status;
+ status = writeDupFileDescriptor(commChannel);
+ }
+ }
+ return status;
+}
+
status_t Parcel::writeBlob(size_t len, WritableBlob* outBlob)
{
status_t status;
@@ -1148,6 +1174,23 @@ int Parcel::readFileDescriptor() const
return BAD_TYPE;
}
+// WARNING: This method must stay in sync with writeToParcel()
+// in frameworks/base/core/java/android/os/ParcelFileDescriptor.java
+int Parcel::readParcelFileDescriptor(int& outCommChannel) const {
+ int fd;
+ outCommChannel = -1;
+
+ if (readInt32() == 0) {
+ fd = -1;
+ } else {
+ fd = readFileDescriptor();
+ if (fd >= 0 && readInt32() != 0) {
+ outCommChannel = readFileDescriptor();
+ }
+ }
+ return fd;
+}
+
status_t Parcel::readBlob(size_t len, ReadableBlob* outBlob) const
{
int32_t useAshmem;