Add readStrongBinder that takes an interface
We use a template function to let us pass arbitrary interfaces, all of which
can be cast to IBinder.
Change-Id: Iadf21c495cde43e8a5adb85a49e6592196f401ff
Test: unit tests
Bug: 23600713
Signed-off-by: Casey Dahlin <sadmac@google.com>
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 5a37e6a..637a1e9 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -27,6 +27,8 @@
#include <utils/Flattenable.h>
#include <linux/binder.h>
+#include <binder/IInterface.h>
+
// ---------------------------------------------------------------------------
namespace android {
@@ -196,8 +198,12 @@
status_t readString16(String16* pArg) const;
const char16_t* readString16Inplace(size_t* outLen) const;
sp<IBinder> readStrongBinder() const;
+ status_t readStrongBinder(sp<IBinder>* val) const;
wp<IBinder> readWeakBinder() const;
+ template<typename T>
+ status_t readStrongBinder(sp<T>* val) const;
+
status_t readByteVector(std::vector<int8_t>* val) const;
status_t readInt32Vector(std::vector<int32_t>* val) const;
status_t readInt64Vector(std::vector<int64_t>* val) const;
@@ -430,6 +436,22 @@
return NO_ERROR;
}
+template<typename T>
+status_t Parcel::readStrongBinder(sp<T>* val) const {
+ sp<IBinder> tmp;
+ status_t ret = readStrongBinder(&tmp);
+
+ if (ret == OK) {
+ *val = interface_cast<T>(tmp);
+
+ if (val->get() == nullptr) {
+ return UNKNOWN_ERROR;
+ }
+ }
+
+ return ret;
+}
+
// ---------------------------------------------------------------------------
inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)