Automatically start threadpool.

Generated code should automatically start a threadpool
in one of the following scenarios:
  - You pass an asynchronous interface to a remote process
    (so you can receive calls on it).
  - You register a death recipient on an interface
    (so the kernel can notify you on this thread when it dies).

Also, updated tests to use the new configure/joinThreadPool() API.

Bug: 31748996
Test: mma, hidl_test, hidl_test_java
Change-Id: I2262580282c9b25c2e004dfd928b7444f4be78d9
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 7f3f4cc..bdc59a1 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -1159,8 +1159,12 @@
     out << "::descriptor);\n";
     out << "if (_hidl_err != ::android::OK) { goto _hidl_error; }\n\n";
 
+    bool hasInterfaceArgument;
     // First DFS: write all buffers and resolve pointers for parent
     for (const auto &arg : method->args()) {
+        if (arg->type().isInterface()) {
+            hasInterfaceArgument = true;
+        }
         emitCppReaderWriter(
                 out,
                 "_hidl_data",
@@ -1183,6 +1187,10 @@
                 false /* addPrefixToName */);
     }
 
+    if (hasInterfaceArgument) {
+        // Start binder threadpool to handle incoming transactions
+        out << "::android::hardware::ProcessState::self()->startThreadPool();\n";
+    }
     out << "_hidl_err = remote()->transact("
         << method->getSerialId()
         << " /* "