diff options
author | Casey Dahlin | 2015-11-04 18:12:57 -0600 |
---|---|---|
committer | Gerrit Code Review | 2015-11-04 18:12:57 -0600 |
commit | fd6843236fe9094fc8868f1a58e6ba4364a485a7 (patch) | |
tree | 758ac103000c7f15c1c5e457fca1f496de61b9a5 | |
parent | c84da67d723ce4bafc3622cd269207ea3995ff1c (diff) | |
parent | eb8e15f9bb29f8794f8be819530631c358fd6a15 (diff) | |
download | frameworks-native-fd6843236fe9094fc8868f1a58e6ba4364a485a7.tar.gz frameworks-native-fd6843236fe9094fc8868f1a58e6ba4364a485a7.tar.xz frameworks-native-fd6843236fe9094fc8868f1a58e6ba4364a485a7.zip |
Merge "Add support for reading/writing a vector of binders"
-rw-r--r-- | include/binder/Parcel.h | 6 | ||||
-rw-r--r-- | libs/binder/Parcel.cpp | 50 |
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 | ||
1048 | status_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 | |||
1071 | status_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 | |||
1048 | status_t Parcel::writeWeakBinder(const wp<IBinder>& val) | 1098 | status_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); |