diff options
| author | 2015-10-28 23:41:58 +0000 | |
|---|---|---|
| committer | 2015-10-28 23:41:58 +0000 | |
| commit | 71b70a244c56719d30654b7123a944d971eb8d02 (patch) | |
| tree | 4eb8034f279468c6a5b902ca5a9feec591f21782 | |
| parent | 1f76049c955c605b61ef0d923582c740c325b1a0 (diff) | |
| parent | f0c13772d95486d98f034361883b2415bb26a614 (diff) | |
Merge "Add readStrongBinder that takes an interface"
| -rw-r--r-- | include/binder/Parcel.h | 22 | ||||
| -rw-r--r-- | libs/binder/Parcel.cpp | 7 |
2 files changed, 28 insertions, 1 deletions
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 5a37e6a408..637a1e9b64 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 @@ public: 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 @@ status_t Parcel::read(LightFlattenable<T>& val) const { 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) diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 48bf799c3d..ab2cdab215 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -1781,10 +1781,15 @@ const char16_t* Parcel::readString16Inplace(size_t* outLen) const return NULL; } +status_t Parcel::readStrongBinder(sp<IBinder>* val) const +{ + return unflatten_binder(ProcessState::self(), *this, val); +} + sp<IBinder> Parcel::readStrongBinder() const { sp<IBinder> val; - unflatten_binder(ProcessState::self(), *this, &val); + readStrongBinder(&val); return val; } |