HalManifest uses instances API.

Update HalManifest implementation to use instances API.

Test: libvintf_test
Test: vintf_object_test
Test: assemble_vintf -m

Bug: 73556059
Change-Id: Ib75edfe56e18f1ae8e6cbb22be56eb1e413e5c90
diff --git a/HalManifest.cpp b/HalManifest.cpp
index a33faee..a884b1f 100644
--- a/HalManifest.cpp
+++ b/HalManifest.cpp
@@ -123,11 +123,10 @@
 
 std::set<std::string> HalManifest::getHalNamesAndVersions() const {
     std::set<std::string> names{};
-    for (const auto &hal : getHals()) {
-        for (const auto &version : hal.versions) {
-            names.insert(toFQNameString(hal.name, version));
-        }
-    }
+    forEachInstance([&names](const ManifestInstance& e) {
+        names.insert(toFQNameString(e.interface(), e.version()));
+        return true;
+    });
     return names;
 }
 
@@ -147,14 +146,6 @@
     return transport;
 }
 
-std::set<Version> HalManifest::getSupportedVersions(const std::string &name) const {
-    std::set<Version> ret;
-    for (const ManifestHal *hal : getHals(name)) {
-        ret.insert(hal->versions.begin(), hal->versions.end());
-    }
-    return ret;
-}
-
 bool HalManifest::forEachInstanceOfVersion(
     const std::string& package, const Version& expectVersion,
     const std::function<bool(const ManifestInstance&)>& func) const {
@@ -348,18 +339,15 @@
 CompatibilityMatrix HalManifest::generateCompatibleMatrix() const {
     CompatibilityMatrix matrix;
 
-    for (const ManifestHal &manifestHal : getHals()) {
-        MatrixHal matrixHal{
-            .format = manifestHal.format,
-            .name = manifestHal.name,
+    forEachInstance([&matrix](const ManifestInstance& e) {
+        matrix.add(MatrixHal{
+            .format = e.format(),
+            .name = e.package(),
             .optional = true,
-            .interfaces = manifestHal.interfaces
-        };
-        for (const Version &manifestVersion : manifestHal.versions) {
-            matrixHal.versionRanges.push_back({manifestVersion.majorVer, manifestVersion.minorVer});
-        }
-        matrix.add(std::move(matrixHal));
-    }
+            .versionRanges = {VersionRange{e.version().majorVer, e.version().minorVer}},
+            .interfaces = {{e.interface(), HalInterface{e.interface(), {e.instance()}}}}});
+        return true;
+    });
     if (mType == SchemaType::FRAMEWORK) {
         matrix.mType = SchemaType::DEVICE;
         // VNDK does not need to be added for compatibility
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index 1576c80..c0f4c8e 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -55,8 +55,8 @@
                 // TODO(b/73556059): Store ManifestInstance as well to avoid creating temps
                 FqInstance fqInstance;
                 if (fqInstance.setTo(getName(), v.majorVer, v.minorVer, intf.name, instance)) {
-                    if (!func(ManifestInstance(std::move(fqInstance),
-                                               TransportArch{transportArch}))) {
+                    if (!func(ManifestInstance(std::move(fqInstance), TransportArch{transportArch},
+                                               format))) {
                         return false;
                     }
                 }
@@ -129,7 +129,7 @@
             }
             return false;
         }
-        mAdditionalInstances.emplace(std::move(withPackage), this->transportArch);
+        mAdditionalInstances.emplace(std::move(withPackage), this->transportArch, this->format);
     }
 
     return true;
diff --git a/ManifestInstance.cpp b/ManifestInstance.cpp
index 7a216eb..8bcf531 100644
--- a/ManifestInstance.cpp
+++ b/ManifestInstance.cpp
@@ -36,10 +36,11 @@
 
 ManifestInstance& ManifestInstance::operator=(ManifestInstance&&) = default;
 
-ManifestInstance::ManifestInstance(FqInstance&& fqInstance, TransportArch&& ta)
-    : mFqInstance(std::move(fqInstance)), mTransportArch(std::move(ta)) {}
-ManifestInstance::ManifestInstance(const FqInstance& fqInstance, const TransportArch& ta)
-    : mFqInstance(fqInstance), mTransportArch(ta) {}
+ManifestInstance::ManifestInstance(FqInstance&& fqInstance, TransportArch&& ta, HalFormat fmt)
+    : mFqInstance(std::move(fqInstance)), mTransportArch(std::move(ta)), mHalFormat(fmt) {}
+ManifestInstance::ManifestInstance(const FqInstance& fqInstance, const TransportArch& ta,
+                                   HalFormat fmt)
+    : mFqInstance(fqInstance), mTransportArch(ta), mHalFormat(fmt) {}
 
 const std::string& ManifestInstance::package() const {
     return mFqInstance.getPackage();
@@ -65,17 +66,24 @@
     return mTransportArch.arch;
 }
 
+HalFormat ManifestInstance::format() const {
+    return mHalFormat;
+}
+
 const FqInstance& ManifestInstance::getFqInstance() const {
     return mFqInstance;
 }
 
 bool ManifestInstance::operator==(const ManifestInstance& other) const {
-    return mFqInstance == other.mFqInstance && mTransportArch == other.mTransportArch;
+    return mFqInstance == other.mFqInstance && mTransportArch == other.mTransportArch &&
+           mHalFormat == other.mHalFormat;
 }
 bool ManifestInstance::operator<(const ManifestInstance& other) const {
     if (mFqInstance < other.mFqInstance) return true;
     if (other.mFqInstance < mFqInstance) return false;
-    return mTransportArch < other.mTransportArch;
+    if (mTransportArch < other.mTransportArch) return true;
+    if (other.mTransportArch < mTransportArch) return false;
+    return mHalFormat < other.mHalFormat;
 }
 
 FqInstance ManifestInstance::getFqInstanceNoPackage() const {
diff --git a/include/vintf/HalManifest.h b/include/vintf/HalManifest.h
index 0e77142..a5d01c8 100644
--- a/include/vintf/HalManifest.h
+++ b/include/vintf/HalManifest.h
@@ -63,13 +63,6 @@
     Transport getTransport(const std::string &name, const Version &v,
             const std::string &interfaceName, const std::string &instanceName) const;
 
-    // Given a component name (e.g. "android.hardware.camera"),
-    // return a list of version numbers that are supported by the hardware.
-    // If the component is not found, empty list is returned.
-    // If multiple matches, return a concatenation of version entries
-    // (dupes removed)
-    std::set<Version> getSupportedVersions(const std::string &name) const;
-
     // Check compatibility against a compatibility matrix. Considered compatible if
     // - framework manifest vs. device compat-mat
     //     - checkIncompatibility for HALs returns only optional HALs
diff --git a/include/vintf/ManifestInstance.h b/include/vintf/ManifestInstance.h
index 61abbf1..4eefd65 100644
--- a/include/vintf/ManifestInstance.h
+++ b/include/vintf/ManifestInstance.h
@@ -21,6 +21,7 @@
 
 #include <hidl-util/FqInstance.h>
 
+#include "HalFormat.h"
 #include "TransportArch.h"
 #include "Version.h"
 
@@ -36,14 +37,15 @@
     ManifestInstance& operator=(ManifestInstance&&);
 
     using VersionType = Version;
-    ManifestInstance(FqInstance&& fqInstance, TransportArch&& ta);
-    ManifestInstance(const FqInstance& fqInstance, const TransportArch& ta);
+    ManifestInstance(FqInstance&& fqInstance, TransportArch&& ta, HalFormat fmt);
+    ManifestInstance(const FqInstance& fqInstance, const TransportArch& ta, HalFormat fmt);
     const std::string& package() const;
     Version version() const;
     const std::string& interface() const;
     const std::string& instance() const;
     Transport transport() const;
     Arch arch() const;
+    HalFormat format() const;
 
     bool operator==(const ManifestInstance& other) const;
     bool operator<(const ManifestInstance& other) const;
@@ -57,6 +59,7 @@
    private:
     FqInstance mFqInstance;
     TransportArch mTransportArch;
+    HalFormat mHalFormat;
 };
 
 }  // namespace vintf
diff --git a/include/vintf/VintfObject.h b/include/vintf/VintfObject.h
index 2e260ab..cfa4072 100644
--- a/include/vintf/VintfObject.h
+++ b/include/vintf/VintfObject.h
@@ -33,11 +33,9 @@
  * VintfObject
  *   + GetDeviceHalManfiest
  *   |   + getTransport
- *   |   + getSupportedVersions
  *   |   + checkCompatibility
  *   + GetFrameworkHalManifest
  *   |   + getTransport
- *   |   + getSupportedVersions
  *   |   + checkCompatibility
  *   + GetRuntimeInfo
  *       + checkCompatibility