Support to enable profiling dynamically.

* Add an additonal reserved method setHALInstrumentation to
  enable/disable instrumentation during the hal execution.

Test: make hidl-gen
Change-Id: Iaf20e3f798a51b111bffd2e7294973bce0cabf9e
diff --git a/Interface.cpp b/Interface.cpp
index 4c9e9a5..77681d4 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -50,6 +50,7 @@
     HIDL_SYSPROPS_CHANGED_TRANSACTION,
     HIDL_LINK_TO_DEATH_TRANSACTION,
     HIDL_UNLINK_TO_DEATH_TRANSACTION,
+    HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION,
     LAST_HIDL_TRANSACTION   = 0x00ffffff,
 };
 
@@ -61,6 +62,7 @@
     mReservedMethods.push_back(createSyspropsChangedMethod());
     mReservedMethods.push_back(createLinkToDeathMethod());
     mReservedMethods.push_back(createUnlinkToDeathMethod());
+    mReservedMethods.push_back(createSetHALInstrumentationMethod());
 }
 
 std::string Interface::typeName() const {
@@ -185,6 +187,44 @@
     );
 }
 
+Method *Interface::createSetHALInstrumentationMethod() const {
+    return new Method("setHALInstrumentation",
+            new std::vector<TypedVar *>() /*args */,
+            new std::vector<TypedVar *>() /*results */,
+            true /*oneway */,
+            new std::vector<Annotation *>(),
+            HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION,
+            {
+                {IMPL_HEADER,
+                    [this](auto &out) {
+                        // do nothing for base class.
+                        out << "return ::android::hardware::Void();\n";
+                    }
+                },
+                {IMPL_PROXY,
+                    [](auto &out) {
+                        out << "configureInstrumentation();\n";
+                        out << "return ::android::hardware::Void();\n";
+                    }
+                },
+                {IMPL_STUB,
+                    [](auto &out) {
+                        out << "configureInstrumentation();\n";
+                    }
+                },
+                {IMPL_PASSTHROUGH,
+                    [](auto &out) {
+                        out << "configureInstrumentation();\n";
+                        out << "return ::android::hardware::Void();\n";
+                    }
+                },
+            }, /*cppImpl */
+            { { IMPL_HEADER, [](auto & /*out*/) { /* javaImpl */
+                // Not support for Java Impl for now.
+            } } } /*javaImpl */
+    );
+}
+
 Method *Interface::createDescriptorChainMethod() const {
     VectorType *vecType = new VectorType();
     vecType->setElementType(new StringType());
diff --git a/Interface.h b/Interface.h
index 6cde462..0182818 100644
--- a/Interface.h
+++ b/Interface.h
@@ -113,6 +113,7 @@
     Method *createSyspropsChangedMethod() const;
     Method *createLinkToDeathMethod() const;
     Method *createUnlinkToDeathMethod() const;
+    Method *createSetHALInstrumentationMethod() const;
 
     DISALLOW_COPY_AND_ASSIGN(Interface);
 };
diff --git a/Method.h b/Method.h
index ac681a5..8a05ffc 100644
--- a/Method.h
+++ b/Method.h
@@ -38,7 +38,8 @@
 enum MethodImplType {
     IMPL_HEADER,
     IMPL_PROXY,
-    IMPL_STUB
+    IMPL_STUB,
+    IMPL_PASSTHROUGH,
 };
 
 using MethodImpl = std::map<MethodImplType, std::function<void(Formatter &)>>;
diff --git a/generateCpp.cpp b/generateCpp.cpp
index a4af202..e3ce85c 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -537,6 +537,14 @@
     out << " {\n";
     out.indent();
 
+    if (method->isHidlReserved()
+        && method->overridesCppImpl(IMPL_PASSTHROUGH)) {
+        method->cppImpl(IMPL_PASSTHROUGH, out);
+        out.unindent();
+        out << "}\n\n";
+        return OK;
+    }
+
     const bool returnsValue = !method->results().empty();
     const TypedVar *elidedReturn = method->canElideCallback();