summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Dahlin2015-11-03 15:50:37 -0600
committerCasey Dahlin2015-11-03 15:50:37 -0600
commiteb8e15f9bb29f8794f8be819530631c358fd6a15 (patch)
treed15174000ffbcfcafd8a4a43b7a568510b22c58f
parentfe98e8d6e53ffef172c4571e6c408c4801c3e96c (diff)
downloadframeworks-native-eb8e15f9bb29f8794f8be819530631c358fd6a15.tar.gz
frameworks-native-eb8e15f9bb29f8794f8be819530631c358fd6a15.tar.xz
frameworks-native-eb8e15f9bb29f8794f8be819530631c358fd6a15.zip
Add support for reading/writing a vector of binders
Change-Id: Iaa8da704b2ae3c1ca5456177441a335991b40e8a Test: unit tests pass Bug: 24470786 Signed-off-by: Casey Dahlin <sadmac@google.com>
-rw-r--r--include/binder/Parcel.h6
-rw-r--r--libs/binder/Parcel.cpp50
2 files changed, 55 insertions, 1 deletions
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 637a1e9b6..695d5f1a0 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -125,6 +125,8 @@ public:
125 status_t writeCharVector(const std::vector<char16_t>& val); 125 status_t writeCharVector(const std::vector<char16_t>& val);
126 status_t writeString16Vector(const std::vector<String16>& val); 126 status_t writeString16Vector(const std::vector<String16>& val);
127 127
128 status_t writeStrongBinderVector(const std::vector<sp<IBinder>>& val);
129
128 template<typename T> 130 template<typename T>
129 status_t write(const Flattenable<T>& val); 131 status_t write(const Flattenable<T>& val);
130 132
@@ -202,7 +204,9 @@ public:
202 wp<IBinder> readWeakBinder() const; 204 wp<IBinder> readWeakBinder() const;
203 205
204 template<typename T> 206 template<typename T>
205 status_t readStrongBinder(sp<T>* val) const; 207 status_t readStrongBinder(sp<T>* val) const;
208
209 status_t readStrongBinderVector(std::vector<sp<IBinder>>* val) const;
206 210
207 status_t readByteVector(std::vector<int8_t>* val) const; 211 status_t readByteVector(std::vector<int8_t>* val) const;
208 status_t readInt32Vector(std::vector<int32_t>* val) const; 212 status_t readInt32Vector(std::vector<int32_t>* val) const;
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 694916cf1..db1fc5c26 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -1045,6 +1045,56 @@ status_t Parcel::writeStrongBinder(const sp<IBinder>& val)
1045 return flatten_binder(ProcessState::self(), val, this); 1045 return flatten_binder(ProcessState::self(), val, this);
1046} 1046}
1047 1047
1048status_t Parcel::writeStrongBinderVector(const std::vector<sp<IBinder>>& val)
1049{
1050 if (val.size() > std::numeric_limits<int32_t>::max()) {
1051 return BAD_VALUE;
1052 }
1053
1054 status_t status = writeInt32(val.size());
1055
1056 if (status != OK) {
1057 return status;
1058 }
1059
1060 for (const auto& item : val) {
1061 status = writeStrongBinder(item);
1062
1063 if (status != OK) {
1064 return status;
1065 }
1066 }
1067
1068 return OK;
1069}
1070
1071status_t Parcel::readStrongBinderVector(std::vector<sp<IBinder>>* val) const {
1072 val->clear();
1073
1074 int32_t size;
1075 status_t status = readInt32(&size);
1076
1077 if (status != OK) {
1078 return status;
1079 }
1080
1081 if (size < 0) {
1082 return BAD_VALUE;
1083 }
1084
1085 val->resize(size);
1086
1087 for (auto& v : *val) {
1088 status = readStrongBinder(&v);
1089
1090 if (status != OK) {
1091 return status;
1092 }
1093 }
1094
1095 return OK;
1096}
1097
1048status_t Parcel::writeWeakBinder(const wp<IBinder>& val) 1098status_t Parcel::writeWeakBinder(const wp<IBinder>& val)
1049{ 1099{
1050 return flatten_binder(ProcessState::self(), val, this); 1100 return flatten_binder(ProcessState::self(), val, this);