assemble_vintf: build and fuse compatibility matrix at build time.

The fused matrix:
(1) has all requirements in compatibilility_matrix.V.xml, where V
is the "level" attribute in device manifest (or is inferred if missing)
(2) has all other HALs as optional HALs in compatibility_matrix.U.xml
files, where U > V, including current.xml.

Bug: 69636193

Test: m (system_)compatibility_matrix/manifest.xml
Test: libvintf_test

Change-Id: I01d2f1ea779e270a9b3ca8de63a064747f36eb2d
Merged-In: I01d2f1ea779e270a9b3ca8de63a064747f36eb2d
diff --git a/MatrixHal.cpp b/MatrixHal.cpp
index 50c5116..96dcf78 100644
--- a/MatrixHal.cpp
+++ b/MatrixHal.cpp
@@ -48,5 +48,23 @@
     return ret;
 }
 
+bool MatrixHal::containsInstances(const MatrixHal& other) const {
+    for (const auto& pair : other.interfaces) {
+        const std::string& interfaceName = pair.first;
+        auto thisIt = interfaces.find(interfaceName);
+        if (thisIt == interfaces.end()) {
+            return false;
+        }
+
+        const std::set<std::string>& thisInstances = thisIt->second.instances;
+        const std::set<std::string>& otherInstances = pair.second.instances;
+        if (!std::includes(thisInstances.begin(), thisInstances.end(), otherInstances.begin(),
+                           otherInstances.end())) {
+            return false;
+        }
+    }
+    return true;
+}
+
 } // namespace vintf
 } // namespace android