Emit checkSubclass for BnHwBase.
So that casts to BnHwBase can be checked.
Bug: 132700817
Test: hidl_test_java
Change-Id: I1dfff41b1dd8bc7b6bffcae074a44b8d8e952910
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 4caf824..d7b59eb 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -695,6 +695,15 @@
out << "::android::sp<" << iface->localName() << "> getImpl() { return _hidl_mImpl; }\n";
+ // Because the Bn class hierarchy always inherits from BnHwBase (and no other parent classes)
+ // and also no HIDL-specific things exist in the base binder classes, whenever we want to do
+ // C++ HIDL things with a binder, we only have the choice to convert it into a BnHwBase.
+ // Other hwbinder C++ class hierarchies (namely the one used for Java binder) will still
+ // be libhwbinder binders, but they are not instances of BnHwBase.
+ if (isIBase()) {
+ out << "bool checkSubclass(const void* subclassID) const;\n";
+ }
+
generateMethods(out,
[&](const Method* method, const Interface*) {
if (method->isHidlReserved() && method->overridesCppImpl(IMPL_PROXY)) {
@@ -1362,6 +1371,11 @@
.endl()
.endl();
+ if (isIBase()) {
+ out << "bool " << klassName << "::checkSubclass(const void* subclassID) const ";
+ out.block([&] { out << "return subclassID == " << interfaceName << "::descriptor;\n"; });
+ }
+
generateMethods(out,
[&](const Method* method, const Interface* superInterface) {
return generateStaticStubMethodSource(out, iface->fqName(), method, superInterface);