From eb8e15f9bb29f8794f8be819530631c358fd6a15 Mon Sep 17 00:00:00 2001 From: Casey Dahlin Date: Tue, 3 Nov 2015 13:50:37 -0800 Subject: Add support for reading/writing a vector of binders Change-Id: Iaa8da704b2ae3c1ca5456177441a335991b40e8a Test: unit tests pass Bug: 24470786 Signed-off-by: Casey Dahlin --- libs/binder/Parcel.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'libs/binder/Parcel.cpp') diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 694916cf10..db1fc5c265 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -1045,6 +1045,56 @@ status_t Parcel::writeStrongBinder(const sp& val) return flatten_binder(ProcessState::self(), val, this); } +status_t Parcel::writeStrongBinderVector(const std::vector>& val) +{ + if (val.size() > std::numeric_limits::max()) { + return BAD_VALUE; + } + + status_t status = writeInt32(val.size()); + + if (status != OK) { + return status; + } + + for (const auto& item : val) { + status = writeStrongBinder(item); + + if (status != OK) { + return status; + } + } + + return OK; +} + +status_t Parcel::readStrongBinderVector(std::vector>* val) const { + val->clear(); + + int32_t size; + status_t status = readInt32(&size); + + if (status != OK) { + return status; + } + + if (size < 0) { + return BAD_VALUE; + } + + val->resize(size); + + for (auto& v : *val) { + status = readStrongBinder(&v); + + if (status != OK) { + return status; + } + } + + return OK; +} + status_t Parcel::writeWeakBinder(const wp& val) { return flatten_binder(ProcessState::self(), val, this); -- cgit v1.2.3-59-g8ed1b