Update hidl-gen for vts backend.

* Generate the type definition from all imported interface/types.
* Update the logic to generate a single profiler package for a hal
  package.
Test: make hidl-gen
Change-Id: I634c435af9913f74fa0e2495908a1805097649c4
diff --git a/AST.cpp b/AST.cpp
index 6467c4f..ab0e386 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -519,6 +519,14 @@
     importSet->insert(newSet.begin(), newSet.end());
 }
 
+void AST::getAllImportedNames(std::set<FQName> *allImportNames) const {
+    for (const auto& name : mImportedNames) {
+        allImportNames->insert(name);
+        AST *ast = mCoordinator->parse(name);
+        ast->getAllImportedNames(allImportNames);
+    }
+}
+
 bool AST::isJavaCompatible() const {
     std::string ifaceName;
     if (!AST::isInterface(&ifaceName)) {
diff --git a/AST.h b/AST.h
index d89f681..b9bd854 100644
--- a/AST.h
+++ b/AST.h
@@ -100,11 +100,13 @@
 
     // Return the set of FQNames for those interfaces and types that are
     // actually referenced in the AST, not merely imported.
-
     const std::set<FQName>& getImportedNames() const {
         return mImportedNames;
     }
 
+    // Get transitive closure of imported interface/types.
+    void getAllImportedNames(std::set<FQName> *allImportSet) const;
+
     void appendToExportedTypesVector(
             std::vector<const Type *> *exportedTypes) const;
 
@@ -277,8 +279,8 @@
     // Helper function that generates vts type declaration from the current
     // AST and the transitive closure of imported ASTs.
     status_t emitVtsTypeDeclarationsHelper(
-                Formatter &out,
-                std::set<AST*> *allImportSet) const;
+            Formatter &out,
+            std::set<AST*> *allImportSet) const;
 
     DISALLOW_COPY_AND_ASSIGN(AST);
 };
diff --git a/Interface.cpp b/Interface.cpp
index c9372a4..0fdad27 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -732,11 +732,8 @@
 status_t Interface::emitVtsAttributeType(Formatter &out) const {
     out << "type: " << getVtsType() << "\n"
         << "predefined_type: \""
-        << localName()
-        << "\"\n"
-        << "is_callback: "
-        << (StringHelper::EndsWith(localName(), "Callback") ? "true" : "false")
-        << "\n";
+        << fullName()
+        << "\"\n";
     return OK;
 }
 
diff --git a/generateVts.cpp b/generateVts.cpp
index ed8e837..2acb3f9 100644
--- a/generateVts.cpp
+++ b/generateVts.cpp
@@ -35,29 +35,30 @@
 }
 
 status_t AST::emitVtsTypeDeclarationsHelper(
-        Formatter &out,
-        std::set<AST *> *allImportSet) const {
+        Formatter &out, std::set<AST *> *allImportSet) const {
     // First, generate vts type declaration for all imported AST.
-    for (const auto &ast : mImportedASTs) {
+    for (const auto &importedName : mImportedNames) {
+        AST *ast = mCoordinator->parse(importedName);
         // Already processed, skip.
         if (allImportSet->find(ast) != allImportSet->end()) {
             continue;
         }
         allImportSet->insert(ast);
-        std::string ifaceName;
-        // Skip the process of ast within the same package.
-        if (ast->package() != mPackage) {
-            status_t status = ast->emitVtsTypeDeclarationsHelper(out,
-                                                                 allImportSet);
-            if (status != OK) {
-                return status;
-            }
+        status_t status = ast->emitVtsTypeDeclarationsHelper(out,
+                                                             allImportSet);
+        if (status != OK) {
+            return status;
         }
     }
     // Next, generate vts type declaration for the current AST.
     std::string ifaceName;
-    // We only care about types.hal.
-    if (!AST::isInterface(&ifaceName)) {
+    if (AST::isInterface(&ifaceName)) {
+        const Interface *iface = mRootScope->getInterface();
+        status_t status = iface->emitVtsAttributeDeclaration(out);
+        if (status != OK) {
+            return status;
+        }
+    } else {
         for (const auto &type : mRootScope->getSubTypes()) {
             // Skip for TypeDef as it is just an alias of a defined type.
             if (type->isTypeDef()) {
@@ -114,10 +115,13 @@
 
     out << "package: \"" << mPackage.package() << "\"\n\n";
 
-    for (const auto &item : mImportedNames) {
+    // Generate import statement for all imported interface/types.
+    std::set<FQName> allImportedNames;
+    getAllImportedNames(&allImportedNames);
+    for (const auto &name : allImportedNames) {
         // ignore IBase.
-        if (item != gIBaseFqName) {
-            out << "import: \"" << item.string() << "\"\n";
+        if (name != gIBaseFqName) {
+            out << "import: \"" << name.string() << "\"\n";
         }
     }
 
@@ -135,14 +139,6 @@
         if (status != OK) {
             return status;
         }
-        for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
-            const Interface *superInterface = *it;
-            status_t status = superInterface->emitVtsAttributeDeclaration(out);
-            if (status != OK) {
-                return status;
-            }
-        }
-
         // Generate all the method declarations.
         for (auto it = chain.rbegin(); it != chain.rend(); ++it) {
             const Interface *superInterface = *it;
@@ -164,7 +160,3 @@
 }
 
 }  // namespace android
-
-
-
-
diff --git a/main.cpp b/main.cpp
index 067f741..5c50b6c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -851,39 +851,14 @@
         const FQName &packageFQName,
         const char *hidl_gen,
         Coordinator *coordinator) {
-    std::vector<std::vector<FQName>> interfacesForProfiler;
-    bool hasTypesInterface = false;
-    FQName typesInterface;
-    // Split interfaces except for the types interface.
-    for (const auto &fqName : packageInterfaces) {
-        if (fqName.name() == "types") {
-            hasTypesInterface = true;
-            typesInterface = fqName;
-        } else {
-            std::vector<FQName> interfaces;
-            interfaces.push_back(fqName);
-            interfacesForProfiler.push_back(interfaces);
-        }
-    }
-    // Generate profiler library for each interface.
-    for (auto interfaces : interfacesForProfiler) {
-        if (hasTypesInterface) {
-            interfaces.push_back(typesInterface);
-        }
-        const std::string targetLibraryName = makeLibraryName(packageFQName);
-        const std::string libraryName = targetLibraryName + "-"
-            + interfaces[0].name() + "-vts.profiler";
-        status_t status = generateAndroidBpForVtsPackage(out, importedPackages,
-                                                         interfaces,
-                                                         packageFQName,
-                                                         libraryName,
-                                                         "PROFILER", hidl_gen,
-                                                         coordinator);
-        if (status != OK) {
-            return status;
-        }
-    }
-    return OK;
+    const std::string targetLibraryName = makeLibraryName(packageFQName);
+    const std::string libraryName = targetLibraryName + "-vts.profiler";
+    return generateAndroidBpForVtsPackage(out, importedPackages,
+                                          packageInterfaces,
+                                          packageFQName,
+                                          libraryName,
+                                          "PROFILER", hidl_gen,
+                                          coordinator);
 }
 
 static status_t generateAndroidBpForPackage(