Merge "Support driver/profiler for all hals."
diff --git a/Interface.cpp b/Interface.cpp
index 0fdad27..e7ed545 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -265,8 +265,8 @@
     return true;
 }
 
-bool Interface::fillGetReferenceInfoMethod(Method *method) const {
-    if (method->name() != "getReferenceInfo") {
+bool Interface::fillGetDebugInfoMethod(Method *method) const {
+    if (method->name() != "getDebugInfo") {
         return false;
     }
 
@@ -275,17 +275,14 @@
         {
             {IMPL_HEADER,
                 [this](auto &out) {
-                    // getReferenceInfo returns N/A for local objects.
-                    out << "_hidl_cb({ -1 });\n"
+                    // getDebugInfo returns N/A for local objects.
+                    out << "_hidl_cb({ -1 /* pid */, 0 /* ptr */ });\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"
+                    out << "_hidl_cb({ getpid(), reinterpret_cast<uint64_t>(this) });\n"
                         << "return ::android::hardware::Void();";
                 }
             }
@@ -294,7 +291,9 @@
             const Type &refInfo = method->results().front()->type();
             out << refInfo.getJavaType(false /* forInitializer */) << " info = new "
                 << refInfo.getJavaType(true /* forInitializer */) << "();\n"
-                << "info.refCount = -1;\n"
+                // TODO(b/34777099): PID for java.
+                << "info.pid = -1;\n"
+                << "info.ptr = 0;\n"
                 << "return info;";
         } } } /* javaImpl */
     );
@@ -349,7 +348,7 @@
             || fillLinkToDeathMethod(method)
             || fillUnlinkToDeathMethod(method)
             || fillSetHALInstrumentationMethod(method)
-            || fillGetReferenceInfoMethod(method);
+            || fillGetDebugInfoMethod(method);
         if (!fillSuccess) {
             LOG(ERROR) << "ERROR: hidl-gen does not recognize a reserved method "
                        << method->name();
diff --git a/Interface.h b/Interface.h
index 5b0d0cf..a063902 100644
--- a/Interface.h
+++ b/Interface.h
@@ -120,7 +120,7 @@
     bool fillLinkToDeathMethod(Method *method) const;
     bool fillUnlinkToDeathMethod(Method *method) const;
     bool fillSetHALInstrumentationMethod(Method *method) const;
-    bool fillGetReferenceInfoMethod(Method *method) const;
+    bool fillGetDebugInfoMethod(Method *method) const;
 
     DISALLOW_COPY_AND_ASSIGN(Interface);
 };
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 9a51ff9..1a2b45b 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -159,8 +159,8 @@
         << "const std::string &serviceName, bool getStub) ";
     out.block([&] {
         out << "::android::sp<" << interfaceName << "> iface = nullptr;\n";
-        out << "::android::vintf::Transport transport = ::android::hardware::getTransportFromManifest(\""
-            << fqName.package() << "\");\n";
+        out << "::android::vintf::Transport transport = ::android::hardware::getTransport("
+            << interfaceName << "::descriptor);\n";
 
         out.sIf("!getStub && "
                 "(transport == ::android::vintf::Transport::HWBINDER || "
@@ -827,11 +827,7 @@
                 << "::" << method->name() << "_cb;\n";
         }
         method->generateCppSignature(out);
-        out << " ";
-        out.block([&] {
-            method->cppImpl(IMPL_STUB_IMPL, out);
-            out << "\n";
-        }).endl();
+        out << ";\n";
         return OK;
     });
     if (err != OK) {
@@ -1431,6 +1427,17 @@
         out << "}\n\n";
     }
 
+    status_t err = generateMethods(out, [&](const Method *method, const Interface *) {
+        if (!method->isHidlReserved() || !method->overridesCppImpl(IMPL_STUB_IMPL)) {
+            return OK;
+        }
+        method->generateCppSignature(out, iface->getStubName());
+        out << " ";
+        out.block([&] {
+            method->cppImpl(IMPL_STUB_IMPL, out);
+        }).endl();
+        return OK;
+    });
 
     out << "::android::status_t " << klassName << "::onTransact(\n";