Merge "getService: respect vintf passthrough"
diff --git a/Interface.cpp b/Interface.cpp
index e7ed545..174e544 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -53,6 +53,7 @@
     HIDL_UNLINK_TO_DEATH_TRANSACTION,
     HIDL_SET_HAL_INSTRUMENTATION_TRANSACTION,
     HIDL_GET_REF_INFO_TRANSACTION,
+    HIDL_DEBUG_TRANSACTION,
     LAST_HIDL_TRANSACTION   = 0x00ffffff,
 };
 
@@ -301,6 +302,30 @@
     return true;
 }
 
+bool Interface::fillDebugMethod(Method *method) const {
+    if (method->name() != "debug") {
+        return false;
+    }
+
+    method->fillImplementation(
+        HIDL_DEBUG_TRANSACTION,
+        {
+            {IMPL_HEADER,
+                [this](auto &out) {
+                    out << "(void)fd;\n"
+                        << "(void)options;\n"
+                        << "return ::android::hardware::Void();";
+                }
+            },
+        }, /* cppImpl */
+        {
+            /* unused, as the debug method is hidden from Java */
+        } /* javaImpl */
+    );
+
+    return true;
+}
+
 static std::map<std::string, Method *> gAllReservedMethods;
 
 bool Interface::addMethod(Method *method) {
@@ -348,7 +373,9 @@
             || fillLinkToDeathMethod(method)
             || fillUnlinkToDeathMethod(method)
             || fillSetHALInstrumentationMethod(method)
-            || fillGetDebugInfoMethod(method);
+            || fillGetDebugInfoMethod(method)
+            || fillDebugMethod(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 a063902..376a78c 100644
--- a/Interface.h
+++ b/Interface.h
@@ -121,6 +121,7 @@
     bool fillUnlinkToDeathMethod(Method *method) const;
     bool fillSetHALInstrumentationMethod(Method *method) const;
     bool fillGetDebugInfoMethod(Method *method) const;
+    bool fillDebugMethod(Method *method) const;
 
     DISALLOW_COPY_AND_ASSIGN(Interface);
 };
diff --git a/Method.cpp b/Method.cpp
index 476a10b..9d40856 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -89,6 +89,10 @@
     }
 }
 
+bool Method::isHiddenFromJava() const {
+    return isHidlReserved() && name() == "debug";
+}
+
 bool Method::overridesCppImpl(MethodImplType type) const {
     CHECK(mIsHidlReserved);
     return mCppImpl.find(type) != mCppImpl.end();
@@ -204,6 +208,10 @@
 }
 
 bool Method::isJavaCompatible() const {
+    if (isHiddenFromJava()) {
+        return true;
+    }
+
     for (const auto &arg : *mArgs) {
         if (!arg->isJavaCompatible()) {
             return false;
diff --git a/Method.h b/Method.h
index f9d7b8b..38f0dd2 100644
--- a/Method.h
+++ b/Method.h
@@ -61,6 +61,7 @@
     void cppImpl(MethodImplType type, Formatter &out) const;
     void javaImpl(MethodImplType type, Formatter &out) const;
     bool isHidlReserved() const { return mIsHidlReserved; }
+    bool isHiddenFromJava() const;
     const std::vector<Annotation *> &annotations() const;
 
     // Make a copy with the same name, args, results, oneway, annotations.
diff --git a/generateJava.cpp b/generateJava.cpp
index 1241dcd..56ac2d6 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -236,6 +236,10 @@
     }
 
     for (const auto &method : iface->methods()) {
+        if (method->isHiddenFromJava()) {
+            continue;
+        }
+
         const bool returnsValue = !method->results().empty();
         const bool needsCallback = method->results().size() > 1;
 
@@ -302,6 +306,11 @@
     const Interface *prevInterface = nullptr;
     for (const auto &tuple : iface->allMethodsFromRoot()) {
         const Method *method = tuple.method();
+
+        if (method->isHiddenFromJava()) {
+            continue;
+        }
+
         const Interface *superInterface = tuple.interface();
         if (prevInterface != superInterface) {
             out << "// Methods from "
@@ -436,6 +445,10 @@
     out << "}\n\n";
 
     for (Method *method : iface->hidlReservedMethods()) {
+        if (method->isHiddenFromJava()) {
+            continue;
+        }
+
         // b/32383557 this is a hack. We need to change this if we have more reserved methods.
         CHECK_LE(method->results().size(), 1u);
         std::string resultType = method->results().size() == 0 ? "void" :
@@ -492,6 +505,7 @@
 
     for (const auto &tuple : iface->allMethodsFromRoot()) {
         const Method *method = tuple.method();
+
         const Interface *superInterface = tuple.interface();
         const bool returnsValue = !method->results().empty();
         const bool needsCallback = method->results().size() > 1;
@@ -503,6 +517,7 @@
             << " */:\n{\n";
 
         out.indent();
+
         if (method->isHidlReserved() && method->overridesJavaImpl(IMPL_STUB)) {
             method->javaImpl(IMPL_STUB, out);
             out.unindent();
@@ -515,6 +530,19 @@
             << superInterface->fullJavaName()
             << ".kInterfaceName);\n\n";
 
+        if (method->isHiddenFromJava()) {
+            // This is a method hidden from the Java side of things, it must not
+            // return any value and will simply signal success.
+            CHECK(!returnsValue);
+
+            out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
+            out << "_hidl_reply.send();\n";
+            out << "break;\n";
+            out.unindent();
+            out << "}\n\n";
+            continue;
+        }
+
         for (const auto &arg : method->args()) {
             emitJavaReaderWriter(
                     out,
@@ -582,7 +610,7 @@
 
         out << ");\n";
 
-        if (!needsCallback) {
+        if (!needsCallback && !method->isOneway()) {
             out << "_hidl_reply.writeStatus(android.os.HwParcel.STATUS_SUCCESS);\n";
 
             if (returnsValue) {
diff --git a/main.cpp b/main.cpp
index ba4e7ba..7426e65 100644
--- a/main.cpp
+++ b/main.cpp
@@ -513,7 +513,8 @@
             << "-java"
             << staticSuffix
             << "\nLOCAL_MODULE_CLASS := JAVA_LIBRARIES\n\n"
-            << "intermediates := $(local-generated-sources-dir)\n\n"
+            << "intermediates := $(call local-generated-sources-dir, COMMON)"
+            << "\n\n"
             << "HIDL := $(HOST_OUT_EXECUTABLES)/"
             << hidl_gen
             << "$(HOST_EXECUTABLE_SUFFIX)";
@@ -559,7 +560,8 @@
             << libraryName
             << "-java-constants"
             << "\nLOCAL_MODULE_CLASS := JAVA_LIBRARIES\n\n"
-            << "intermediates := $(local-generated-sources-dir)\n\n"
+            << "intermediates := $(call local-generated-sources-dir, COMMON)"
+            << "\n\n"
             << "HIDL := $(HOST_OUT_EXECUTABLES)/"
             << hidl_gen
             << "$(HOST_EXECUTABLE_SUFFIX)";
@@ -606,6 +608,7 @@
         const FQName &packageFQName,
         const char *hidl_gen,
         Coordinator *coordinator,
+        const std::string &halFilegroupName,
         const std::string &genName,
         const char *language,
         const std::vector<FQName> &packageInterfaces,
@@ -626,9 +629,7 @@
 
     out << "srcs: [\n";
     out.indent();
-    for (const auto &fqName : packageInterfaces) {
-        out << "\"" << fqName.name() << ".hal\",\n";
-    }
+    out << "\":" << halFilegroupName << "\",\n";
     out.unindent();
     out << "],\n";
 
@@ -729,6 +730,7 @@
             packageFQName,
             hidl_gen,
             coordinator,
+            halFilegroupName,
             genSourceName,
             "c++",
             packageInterfaces,
@@ -747,6 +749,7 @@
             packageFQName,
             hidl_gen,
             coordinator,
+            halFilegroupName,
             genHeaderName,
             "c++",
             packageInterfaces,
diff --git a/test/vendor/1.0/Android.bp b/test/vendor/1.0/Android.bp
index 12c381f..e1ece49 100644
--- a/test/vendor/1.0/Android.bp
+++ b/test/vendor/1.0/Android.bp
@@ -1,5 +1,13 @@
 // This file is autogenerated by hidl-gen. Do not edit manually.
 
+filegroup {
+    name: "tests.vendor@1.0_hal",
+    srcs: [
+        "types.hal",
+        "IVendor.hal",
+    ],
+}
+
 genrule {
     name: "tests.vendor@1.0_genc++",
     tools: ["hidl-gen"],
diff --git a/test/vendor/1.0/Android.mk b/test/vendor/1.0/Android.mk
index 09b9f53..ef494ab 100644
--- a/test/vendor/1.0/Android.mk
+++ b/test/vendor/1.0/Android.mk
@@ -8,7 +8,7 @@
 LOCAL_MODULE := tests.vendor@1.0-java
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 
-intermediates := $(local-generated-sources-dir)
+intermediates := $(call local-generated-sources-dir, COMMON)
 
 HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
 
@@ -105,7 +105,7 @@
 LOCAL_MODULE := tests.vendor@1.0-java-static
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 
-intermediates := $(local-generated-sources-dir)
+intermediates := $(call local-generated-sources-dir, COMMON)
 
 HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
 
@@ -202,7 +202,7 @@
 LOCAL_MODULE := tests.vendor@1.0-java-constants
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 
-intermediates := $(local-generated-sources-dir)
+intermediates := $(call local-generated-sources-dir, COMMON)
 
 HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
 #