diff options
| author | 2020-11-19 09:18:17 +0900 | |
|---|---|---|
| committer | 2020-11-19 09:51:45 +0900 | |
| commit | 04d19615a4080215a6de31b72f35705a4ffecd17 (patch) | |
| tree | 520a1356e224a5cbec38db009cc1502189c78f8a | |
| parent | 4d9f91a1d58eb010d8a9ebfaee7c696f20fe1173 (diff) | |
Parcel: add "optional" variant of writeParcelableVector
Since Android R, Parcel provides read/write methods for "@nullable"
values using std::optional.
Adding "optional" variant of writeParcelableVector which was missed
when adding optional variants of read/write methods before deprecating
"unique_ptr" variants.
Bug: 149784838
Test: m
Change-Id: I2f6781ea5e367d414a371c55a3eb8fe794c144d0
| -rw-r--r-- | libs/binder/include/binder/Parcel.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index ece25a0730..4b2d50df86 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -210,6 +210,8 @@ public: template<typename T> status_t writeParcelableVector(const std::shared_ptr<std::vector<std::unique_ptr<T>>>& val); template<typename T> + status_t writeParcelableVector(const std::shared_ptr<std::vector<std::optional<T>>>& val); + template<typename T> status_t writeParcelableVector(const std::vector<T>& val); template<typename T> @@ -1229,6 +1231,16 @@ status_t Parcel::writeParcelableVector(const std::shared_ptr<std::vector<std::un return unsafeWriteTypedVector<NullableT, const NullableT&>(*val, &Parcel::writeNullableParcelable); } +template<typename T> +status_t Parcel::writeParcelableVector(const std::shared_ptr<std::vector<std::optional<T>>>& val) { + if (val.get() == nullptr) { + return this->writeInt32(-1); + } + + using NullableT = std::optional<T>; + return unsafeWriteTypedVector<NullableT, const NullableT&>(*val, &Parcel::writeNullableParcelable); +} + template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int32_t>, bool>> status_t Parcel::writeEnum(const T& val) { return writeInt32(static_cast<int32_t>(val)); |