[REFACTOR] embed file name into manifest/matrix object

Instead of attaching name to the object as a new type Named<T>,
embed the file name or file path of the object into the object
directly.

The type Named<T> is re-written so that its subclass extends its
setFileName() and fileName() methods.

Test: libvintf_test, vintf_object_test
Bug: 118757553

Change-Id: Ib3356cf56632b00c77c26df1cfa1a1aaf8878876
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 2611a56..090f582 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -148,7 +148,7 @@
 status_t VintfObject::getCombinedFrameworkMatrix(
     const std::shared_ptr<const HalManifest>& deviceManifest, CompatibilityMatrix* out,
     std::string* error) {
-    std::vector<Named<CompatibilityMatrix>> matrixFragments;
+    std::vector<CompatibilityMatrix> matrixFragments;
     auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error);
     if (matrixFragmentsStatus != OK) {
         return matrixFragmentsStatus;
@@ -177,8 +177,8 @@
     if (deviceLevel == Level::UNSPECIFIED) {
         // Cannot infer FCM version. Combine all matrices by assuming
         // Shipping FCM Version == min(all supported FCM Versions in the framework)
-        for (auto&& pair : matrixFragments) {
-            Level fragmentLevel = pair.object.level();
+        for (auto&& fragment : matrixFragments) {
+            Level fragmentLevel = fragment.level();
             if (fragmentLevel != Level::UNSPECIFIED && deviceLevel > fragmentLevel) {
                 deviceLevel = fragmentLevel;
             }
@@ -426,24 +426,24 @@
     }
 }
 
-status_t VintfObject::getOneMatrix(const std::string& path, Named<CompatibilityMatrix>* out,
+status_t VintfObject::getOneMatrix(const std::string& path, CompatibilityMatrix* out,
                                    std::string* error) {
     std::string content;
     status_t status = getFileSystem()->fetch(path, &content, error);
     if (status != OK) {
         return status;
     }
-    if (!gCompatibilityMatrixConverter(&out->object, content, error)) {
+    if (!gCompatibilityMatrixConverter(out, content, error)) {
         if (error) {
             error->insert(0, "Cannot parse " + path + ": ");
         }
         return BAD_VALUE;
     }
-    out->name = path;
+    out->setFileName(path);
     return OK;
 }
 
-status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<Named<CompatibilityMatrix>>* results,
+status_t VintfObject::getAllFrameworkMatrixLevels(std::vector<CompatibilityMatrix>* results,
                                                   std::string* error) {
     std::vector<std::string> dirs = {
         kSystemVintfDir,
@@ -461,7 +461,7 @@
         }
         for (const std::string& fileName : fileNames) {
             std::string path = dir + fileName;
-            Named<CompatibilityMatrix> namedMatrix;
+            CompatibilityMatrix namedMatrix;
             std::string matrixError;
             status_t matrixStatus = getOneMatrix(path, &namedMatrix, &matrixError);
             if (matrixStatus != OK) {
@@ -819,7 +819,7 @@
 int32_t VintfObject::checkDeprecation(const ListInstances& listInstances,
                                       const std::vector<HidlInterfaceMetadata>& hidlMetadata,
                                       std::string* error) {
-    std::vector<Named<CompatibilityMatrix>> matrixFragments;
+    std::vector<CompatibilityMatrix> matrixFragments;
     auto matrixFragmentsStatus = getAllFrameworkMatrixLevels(&matrixFragments, error);
     if (matrixFragmentsStatus != OK) {
         return matrixFragmentsStatus;
@@ -843,8 +843,8 @@
 
     const CompatibilityMatrix* targetMatrix = nullptr;
     for (const auto& namedMatrix : matrixFragments) {
-        if (namedMatrix.object.level() == deviceLevel) {
-            targetMatrix = &namedMatrix.object;
+        if (namedMatrix.level() == deviceLevel) {
+            targetMatrix = &namedMatrix;
         }
     }
     if (targetMatrix == nullptr) {
@@ -864,11 +864,10 @@
     // Matrices with unspecified level are considered "current".
     bool isDeprecated = false;
     for (const auto& namedMatrix : matrixFragments) {
-        if (namedMatrix.object.level() == Level::UNSPECIFIED) continue;
-        if (namedMatrix.object.level() >= deviceLevel) continue;
+        if (namedMatrix.level() == Level::UNSPECIFIED) continue;
+        if (namedMatrix.level() >= deviceLevel) continue;
 
-        const auto& oldMatrix = namedMatrix.object;
-        for (const MatrixHal& hal : oldMatrix.getHals()) {
+        for (const MatrixHal& hal : namedMatrix.getHals()) {
             if (IsHalDeprecated(hal, *targetMatrix, listInstances, childrenMap, error)) {
                 isDeprecated = true;
             }
@@ -924,7 +923,7 @@
 }
 
 android::base::Result<bool> VintfObject::hasFrameworkCompatibilityMatrixExtensions() {
-    std::vector<Named<CompatibilityMatrix>> matrixFragments;
+    std::vector<CompatibilityMatrix> matrixFragments;
     std::string error;
     status_t status = getAllFrameworkMatrixLevels(&matrixFragments, &error);
     if (status != OK) {
@@ -933,17 +932,16 @@
     }
     for (const auto& namedMatrix : matrixFragments) {
         // Returns true if product matrix exists.
-        if (android::base::StartsWith(namedMatrix.name, kProductVintfDir)) {
+        if (android::base::StartsWith(namedMatrix.fileName(), kProductVintfDir)) {
             return true;
         }
         // Returns true if system_ext matrix exists.
-        if (android::base::StartsWith(namedMatrix.name, kSystemExtVintfDir)) {
+        if (android::base::StartsWith(namedMatrix.fileName(), kSystemExtVintfDir)) {
             return true;
         }
         // Returns true if device system matrix exists.
-        if (android::base::StartsWith(namedMatrix.name, kSystemVintfDir) &&
-            namedMatrix.object.level() == Level::UNSPECIFIED &&
-            !namedMatrix.object.getHals().empty()) {
+        if (android::base::StartsWith(namedMatrix.fileName(), kSystemVintfDir) &&
+            namedMatrix.level() == Level::UNSPECIFIED && !namedMatrix.getHals().empty()) {
             return true;
         }
     }