Add getReferenceInfo to IBase.
Also added a IMPL_STUB_IMPL for HIDL reserved methods that:
* add a method with the same name and signature
to BnHwFoo
* BnHwFoo::onTransact will call BnHwFoo::method instead of
_hidl_mImpl->method
* Content of IMPL_STUB_IMPL will go to BnHwFoo::method.
Test: make and tested NFC / light / audio
Test: hidl_test
Change-Id: I85f6314450178c02c7bcba91c8a9fffbce822c76
diff --git a/Interface.cpp b/Interface.cpp
index ad88e31..c9372a4 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -52,6 +52,7 @@
HIDL_LINK_TO_DEATH_TRANSACTION,
HIDL_UNLINK_TO_DEATH_TRANSACTION,
HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION,
+ HIDL_GET_REF_INFO_TRANSACTION,
LAST_HIDL_TRANSACTION = 0x00ffffff,
};
@@ -264,6 +265,43 @@
return true;
}
+bool Interface::fillGetReferenceInfoMethod(Method *method) const {
+ if (method->name() != "getReferenceInfo") {
+ return false;
+ }
+
+ method->fillImplementation(
+ HIDL_GET_REF_INFO_TRANSACTION,
+ {
+ {IMPL_HEADER,
+ [this](auto &out) {
+ // getReferenceInfo returns N/A for local objects.
+ out << "_hidl_cb({ -1 });\n"
+ << "return ::android::hardware::Void();";
+ }
+ },
+ {IMPL_STUB_IMPL,
+ [this](auto &out) {
+ // TODO(b/34777099): need a kernel debug function to get the
+ // true strong count.
+ // uses BHwBinder->getStrongCount()
+ out << "_hidl_cb({ this->getStrongCount() });\n"
+ << "return ::android::hardware::Void();";
+ }
+ }
+ }, /* cppImpl */
+ { { IMPL_HEADER, [this, method](auto &out) {
+ const Type &refInfo = method->results().front()->type();
+ out << refInfo.getJavaType(false /* forInitializer */) << " info = new "
+ << refInfo.getJavaType(true /* forInitializer */) << "();\n"
+ << "info.refCount = -1;\n"
+ << "return info;";
+ } } } /* javaImpl */
+ );
+
+ return true;
+}
+
static std::map<std::string, Method *> gAllReservedMethods;
bool Interface::addMethod(Method *method) {
@@ -310,7 +348,8 @@
|| fillSyspropsChangedMethod(method)
|| fillLinkToDeathMethod(method)
|| fillUnlinkToDeathMethod(method)
- || fillSetHALInstrumentationMethod(method);
+ || fillSetHALInstrumentationMethod(method)
+ || fillGetReferenceInfoMethod(method);
if (!fillSuccess) {
LOG(ERROR) << "ERROR: hidl-gen does not recognize a reserved method "
<< method->name();