libbinder: Make null handling explicit for strong binders
Bug: 27156495
Test: Compiles
Change-Id: I62cade1761377a9ec2921a758307582552e4c2ac
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 44fd59e..9c3877e 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -252,6 +252,7 @@
const char16_t* readString16Inplace(size_t* outLen) const;
sp<IBinder> readStrongBinder() const;
status_t readStrongBinder(sp<IBinder>* val) const;
+ status_t readNullableStrongBinder(sp<IBinder>* val) const;
wp<IBinder> readWeakBinder() const;
template<typename T>
@@ -268,6 +269,9 @@
template<typename T>
status_t readStrongBinder(sp<T>* val) const;
+ template<typename T>
+ status_t readNullableStrongBinder(sp<T>* val) const;
+
status_t readStrongBinderVector(std::unique_ptr<std::vector<sp<IBinder>>>* val) const;
status_t readStrongBinderVector(std::vector<sp<IBinder>>* val) const;
@@ -574,6 +578,20 @@
return ret;
}
+template<typename T>
+status_t Parcel::readNullableStrongBinder(sp<T>* val) const {
+ sp<IBinder> tmp;
+ status_t ret = readNullableStrongBinder(&tmp);
+
+ if (ret == OK) {
+ *val = interface_cast<T>(tmp);
+
+ if (val->get() == nullptr) {
+ return UNKNOWN_ERROR;
+ }
+ }
+}
+
template<typename T, typename U>
status_t Parcel::unsafeReadTypedVector(
std::vector<T>* val,