fromBinder: check casts
The cast from IBinder to BnHwBase is now justified.
Bug: 132700817
Test: hidl_test_java
Change-Id: I2042d6155f1dcef13d65d49d1841ed9e8fa93695
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h
index a098805..ee0d5c0 100644
--- a/transport/include/hidl/HidlBinderSupport.h
+++ b/transport/include/hidl/HidlBinderSupport.h
@@ -332,10 +332,17 @@
if (binderIface.get() == nullptr) {
return nullptr;
}
+
if (binderIface->localBinder() == nullptr) {
return new ProxyType(binderIface);
}
+
+ // Ensure that IBinder is BnHwBase (not JHwBinder, for instance)
+ if (!binderIface->checkSubclass(IBase::descriptor)) {
+ return new ProxyType(binderIface);
+ }
sp<IBase> base = static_cast<BnHwBase*>(binderIface.get())->getImpl();
+
if (details::canCastInterface(base.get(), IType::descriptor)) {
StubType* stub = static_cast<StubType*>(binderIface.get());
return stub->getImpl();