VintfObject (+test): Refactor to use string constants.

Test: vintf_object_test
Bug: 36790901
Change-Id: I1a7e23c75c80f2b57ede1486bfec5665f3b47d41
diff --git a/VintfObject.cpp b/VintfObject.cpp
index ee834eb..0fb4ee2 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -32,14 +32,14 @@
 
 #include <android-base/logging.h>
 
-#define FRAMEWORK_MATRIX_DIR "/system/etc/vintf/"
-
 using std::placeholders::_1;
 using std::placeholders::_2;
 
 namespace android {
 namespace vintf {
 
+using namespace details;
+
 template <typename T>
 struct LockedSharedPtr {
     std::shared_ptr<T> object;
@@ -81,7 +81,7 @@
 std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) {
     static LockedSharedPtr<HalManifest> gFrameworkManifest;
     return Get(&gFrameworkManifest, skipCache,
-               std::bind(&HalManifest::fetchAllInformation, _1, "/system/manifest.xml", _2));
+               std::bind(&HalManifest::fetchAllInformation, _1, kSystemManifest, _2));
 }
 
 
@@ -89,8 +89,7 @@
 std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
     static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix;
     return Get(&gDeviceMatrix, skipCache,
-               std::bind(&CompatibilityMatrix::fetchAllInformation, _1,
-                         "/vendor/compatibility_matrix.xml", _2));
+               std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kVendorLegacyMatrix, _2));
 }
 
 // static
@@ -112,8 +111,7 @@
     }
 
     return Get(&gFrameworkMatrix, skipCache,
-               std::bind(&CompatibilityMatrix::fetchAllInformation, _1,
-                         "/system/compatibility_matrix.xml", _2));
+               std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kSystemLegacyMatrix, _2));
 }
 
 status_t VintfObject::GetCombinedFrameworkMatrix(
@@ -156,7 +154,7 @@
         // None of the fragments specify any FCM version. Should never happen except
         // for inconsistent builds.
         if (error) {
-            *error = "No framework compatibility matrix files under " FRAMEWORK_MATRIX_DIR
+            *error = "No framework compatibility matrix files under " + kSystemVintfDir +
                      " declare FCM version.";
         }
         return NAME_NOT_FOUND;
@@ -187,7 +185,7 @@
 status_t VintfObject::FetchDeviceHalManifest(HalManifest* out, std::string* error) {
     // fetchAllInformation returns NAME_NOT_FOUND if file is missing.
     HalManifest vendorManifest;
-    status_t vendorStatus = vendorManifest.fetchAllInformation("/vendor/etc/manifest.xml", error);
+    status_t vendorStatus = vendorManifest.fetchAllInformation(kVendorManifest, error);
     if (vendorStatus != OK && vendorStatus != NAME_NOT_FOUND) {
         return vendorStatus;
     }
@@ -198,8 +196,8 @@
 #ifdef LIBVINTF_TARGET
     std::string productModel = android::base::GetProperty("ro.boot.product.hardware.sku", "");
     if (!productModel.empty()) {
-        odmStatus =
-            odmManifest.fetchAllInformation("/odm/etc/manifest_" + productModel + ".xml", error);
+        odmStatus = odmManifest.fetchAllInformation(
+            kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", error);
         if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
             return odmStatus;
         }
@@ -207,7 +205,7 @@
 #endif
 
     if (odmStatus == NAME_NOT_FOUND) {
-        odmStatus = odmManifest.fetchAllInformation("/odm/etc/manifest.xml", error);
+        odmStatus = odmManifest.fetchAllInformation(kOdmLegacyManifest, error);
         if (odmStatus != OK && odmStatus != NAME_NOT_FOUND) {
             return odmStatus;
         }
@@ -233,7 +231,7 @@
     }
 
     // Use legacy /vendor/manifest.xml
-    return out->fetchAllInformation("/vendor/manifest.xml", error);
+    return out->fetchAllInformation(kVendorLegacyManifest, error);
 }
 
 std::vector<Named<CompatibilityMatrix>> VintfObject::GetAllFrameworkMatrixLevels(
@@ -241,11 +239,11 @@
     std::vector<std::string> fileNames;
     std::vector<Named<CompatibilityMatrix>> results;
 
-    if (details::gFetcher->listFiles(FRAMEWORK_MATRIX_DIR, &fileNames, error) != OK) {
+    if (details::gFetcher->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
         return {};
     }
     for (const std::string& fileName : fileNames) {
-        std::string path = FRAMEWORK_MATRIX_DIR + fileName;
+        std::string path = kSystemVintfDir + fileName;
 
         std::string content;
         std::string fetchError;
@@ -271,9 +269,8 @@
 
     if (results.empty()) {
         if (error) {
-            *error = "No framework matrices under " FRAMEWORK_MATRIX_DIR
-                     " can be fetched or parsed.\n" +
-                     *error;
+            *error = "No framework matrices under " + kSystemVintfDir +
+                     " can be fetched or parsed.\n" + *error;
         }
     } else {
         if (error && !error->empty()) {
@@ -508,6 +505,18 @@
     return COMPATIBLE;
 }
 
+const std::string kSystemVintfDir = "/system/etc/vintf/";
+const std::string kVendorVintfDir = "/vendor/etc/";
+
+const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
+const std::string kSystemManifest = "/system/manifest.xml";
+
+const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
+const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
+const std::string kSystemLegacyMatrix = "/system/compatibility_matrix.xml";
+const std::string kOdmLegacyVintfDir = "/odm/etc/";
+const std::string kOdmLegacyManifest = kOdmLegacyVintfDir + "manifest.xml";
+
 } // namespace details
 
 // static
diff --git a/include/vintf/VintfObject.h b/include/vintf/VintfObject.h
index 19cede9..7e47a20 100644
--- a/include/vintf/VintfObject.h
+++ b/include/vintf/VintfObject.h
@@ -132,6 +132,17 @@
 int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount,
                            const PartitionMounter& partitionMounter, std::string* error,
                            DisabledChecks disabledChecks = ENABLE_ALL_CHECKS);
+
+extern const std::string kSystemVintfDir;
+extern const std::string kVendorVintfDir;
+extern const std::string kOdmLegacyVintfDir;
+extern const std::string kOdmLegacyManifest;
+extern const std::string kVendorManifest;
+extern const std::string kSystemManifest;
+extern const std::string kVendorLegacyManifest;
+extern const std::string kVendorLegacyMatrix;
+extern const std::string kSystemLegacyMatrix;
+
 } // namespace details
 
 } // namespace vintf
diff --git a/test/vintf_object_tests.cpp b/test/vintf_object_tests.cpp
index a7a618f..6e56a43 100644
--- a/test/vintf_object_tests.cpp
+++ b/test/vintf_object_tests.cpp
@@ -175,40 +175,39 @@
     MockFileFetcher* fetcher = static_cast<MockFileFetcher*>(gFetcher);
 
     if (!productModel.empty()) {
-        ON_CALL(*fetcher, fetch(StrEq("/odm/etc/manifest_" + productModel + ".xml"), _))
+        ON_CALL(*fetcher, fetch(StrEq(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml"), _))
             .WillByDefault(Return(::android::NAME_NOT_FOUND));
     }
-    ON_CALL(*fetcher, fetch(StrEq("/odm/etc/manifest.xml"), _))
+    ON_CALL(*fetcher, fetch(StrEq(kOdmLegacyManifest), _))
         .WillByDefault(Return(::android::NAME_NOT_FOUND));
-    ON_CALL(*fetcher, fetch(StrEq("/vendor/etc/manifest.xml"), _))
+    ON_CALL(*fetcher, fetch(StrEq(kVendorManifest), _))
         .WillByDefault(Return(::android::NAME_NOT_FOUND));
-    ON_CALL(*fetcher, fetch(StrEq("/vendor/manifest.xml"), _))
+    ON_CALL(*fetcher, fetch(StrEq(kVendorLegacyManifest), _))
         .WillByDefault(Invoke([vendorManifestXml](const std::string& path, std::string& fetched) {
             (void)path;
             fetched = vendorManifestXml;
             return 0;
         }));
-    ON_CALL(*fetcher, fetch(StrEq("/system/manifest.xml"), _))
+    ON_CALL(*fetcher, fetch(StrEq(kSystemManifest), _))
         .WillByDefault(Invoke([systemManifestXml](const std::string& path, std::string& fetched) {
             (void)path;
             fetched = systemManifestXml;
             return 0;
         }));
-    ON_CALL(*fetcher, fetch(StrEq("/vendor/compatibility_matrix.xml"), _))
+    ON_CALL(*fetcher, fetch(StrEq(kVendorLegacyMatrix), _))
         .WillByDefault(Invoke([vendorMatrixXml](const std::string& path, std::string& fetched) {
             (void)path;
             fetched = vendorMatrixXml;
             return 0;
         }));
-    ON_CALL(*fetcher, fetch(StrEq("/system/compatibility_matrix.xml"), _))
+    ON_CALL(*fetcher, fetch(StrEq(kSystemLegacyMatrix), _))
         .WillByDefault(Invoke([systemMatrixXml](const std::string& path, std::string& fetched) {
             (void)path;
             fetched = systemMatrixXml;
             return 0;
         }));
     // Don't list /system/etc/vintf unless otherwise specified.
-    ON_CALL(*fetcher, listFiles(StrEq("/system/etc/vintf/"), _, _))
-        .WillByDefault(Return(::android::OK));
+    ON_CALL(*fetcher, listFiles(StrEq(kSystemVintfDir), _, _)).WillByDefault(Return(::android::OK));
 }
 
 static MockPartitionMounter &mounter() {
@@ -231,25 +230,26 @@
     }
 
     void expectVendorManifest(size_t times = 1) {
-        EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/etc/manifest.xml"), _)).Times(times);
+        EXPECT_CALL(fetcher(), fetch(StrEq(kVendorManifest), _)).Times(times);
         if (!productModel.empty()) {
-            EXPECT_CALL(fetcher(), fetch(StrEq("/odm/etc/manifest_" + productModel + ".xml"), _))
+            EXPECT_CALL(fetcher(),
+                        fetch(StrEq(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml"), _))
                 .Times(times);
         }
-        EXPECT_CALL(fetcher(), fetch(StrEq("/odm/etc/manifest.xml"), _)).Times(times);
-        EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/manifest.xml"), _)).Times(times);
+        EXPECT_CALL(fetcher(), fetch(StrEq(kOdmLegacyManifest), _)).Times(times);
+        EXPECT_CALL(fetcher(), fetch(StrEq(kVendorLegacyManifest), _)).Times(times);
     }
 
     void expectSystemManifest(size_t times = 1) {
-        EXPECT_CALL(fetcher(), fetch(StrEq("/system/manifest.xml"), _)).Times(times);
+        EXPECT_CALL(fetcher(), fetch(StrEq(kSystemManifest), _)).Times(times);
     }
 
     void expectVendorMatrix(size_t times = 1) {
-        EXPECT_CALL(fetcher(), fetch(StrEq("/vendor/compatibility_matrix.xml"), _)).Times(times);
+        EXPECT_CALL(fetcher(), fetch(StrEq(kVendorLegacyMatrix), _)).Times(times);
     }
 
     void expectSystemMatrix(size_t times = 1) {
-        EXPECT_CALL(fetcher(), fetch(StrEq("/system/compatibility_matrix.xml"), _)).Times(times);
+        EXPECT_CALL(fetcher(), fetch(StrEq(kSystemLegacyMatrix), _)).Times(times);
     }
 
     void expectFetch(const std::string& path, const std::string& content = "", size_t times = 1) {
@@ -542,7 +542,7 @@
 
 // Test framework compatibility matrix is combined at runtime
 TEST_F(VintfObjectTest, FrameworkCompatibilityMatrixCombine) {
-    EXPECT_CALL(fetcher(), listFiles(StrEq("/system/etc/vintf/"), _, _))
+    EXPECT_CALL(fetcher(), listFiles(StrEq(kSystemVintfDir), _, _))
         .WillOnce(Invoke([](const auto&, auto* out, auto*) {
             *out = {
                 "compatibility_matrix.1.xml",
@@ -550,9 +550,9 @@
             };
             return ::android::OK;
         }));
-    expectFetch("/system/etc/vintf/compatibility_matrix.1.xml",
+    expectFetch(kSystemVintfDir + "compatibility_matrix.1.xml",
                 "<compatibility-matrix version=\"1.0\" type=\"framework\" level=\"1\"/>");
-    expectFetch("/system/etc/vintf/compatibility_matrix.empty.xml",
+    expectFetch(kSystemVintfDir + "compatibility_matrix.empty.xml",
                 "<compatibility-matrix version=\"1.0\" type=\"framework\"/>");
     expectSystemMatrix(0);
 
@@ -636,8 +636,8 @@
 TEST_F(VintfObjectTest, DeviceManifestCombine1) {
     if (productModel.empty()) return;
 
-    expectFetch("/vendor/etc/manifest.xml", vendorEtcManifest);
-    expectFetch("/odm/etc/manifest_" + productModel + ".xml", odmProductManifest);
+    expectFetch(kVendorManifest, vendorEtcManifest);
+    expectFetch(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", odmProductManifest);
 
     auto p = VintfObject::GetDeviceHalManifest(true /* skipCache */);
     ASSERT_NE(nullptr, p);
@@ -650,11 +650,11 @@
 
 // Test /vendor/etc/manifest.xml + /odm/etc/manifest.xml
 TEST_F(VintfObjectTest, DeviceManifestCombine2) {
-    expectFetch("/vendor/etc/manifest.xml", vendorEtcManifest);
+    expectFetch(kVendorManifest, vendorEtcManifest);
     if (!productModel.empty()) {
-        expectFetch("/odm/etc/manifest_" + productModel + ".xml");
+        expectFetch(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml");
     }
-    expectFetch("/odm/etc/manifest.xml", odmManifest);
+    expectFetch(kOdmLegacyManifest, odmManifest);
 
     auto p = VintfObject::GetDeviceHalManifest(true /* skipCache */);
     ASSERT_NE(nullptr, p);
@@ -667,11 +667,11 @@
 
 // Test /vendor/etc/manifest.xml
 TEST_F(VintfObjectTest, DeviceManifestCombine3) {
-    expectFetch("/vendor/etc/manifest.xml", vendorEtcManifest);
+    expectFetch(kVendorManifest, vendorEtcManifest);
     if (!productModel.empty()) {
-        expectFetch("/odm/etc/manifest_" + productModel + ".xml");
+        expectFetch(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml");
     }
-    expectFetch("/odm/etc/manifest.xml");
+    expectFetch(kOdmLegacyManifest);
 
     auto p = VintfObject::GetDeviceHalManifest(true /* skipCache */);
     ASSERT_NE(nullptr, p);
@@ -686,8 +686,8 @@
 TEST_F(VintfObjectTest, DeviceManifestCombine4) {
     if (productModel.empty()) return;
 
-    expectFetch("/vendor/etc/manifest.xml");
-    expectFetch("/odm/etc/manifest_" + productModel + ".xml", odmProductManifest);
+    expectFetch(kVendorManifest);
+    expectFetch(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml", odmProductManifest);
 
     auto p = VintfObject::GetDeviceHalManifest(true /* skipCache */);
     ASSERT_NE(nullptr, p);
@@ -700,11 +700,11 @@
 
 // Test /odm/etc/manifest.xml
 TEST_F(VintfObjectTest, DeviceManifestCombine5) {
-    expectFetch("/vendor/etc/manifest.xml");
+    expectFetch(kVendorManifest);
     if (!productModel.empty()) {
-        expectFetch("/odm/etc/manifest_" + productModel + ".xml");
+        expectFetch(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml");
     }
-    expectFetch("/odm/etc/manifest.xml", odmManifest);
+    expectFetch(kOdmLegacyManifest, odmManifest);
 
     auto p = VintfObject::GetDeviceHalManifest(true /* skipCache */);
     ASSERT_NE(nullptr, p);
@@ -717,12 +717,12 @@
 
 // Test /vendor/manifest.xml
 TEST_F(VintfObjectTest, DeviceManifestCombine6) {
-    expectFetch("/vendor/etc/manifest.xml");
+    expectFetch(kVendorManifest);
     if (!productModel.empty()) {
-        expectFetch("/odm/etc/manifest_" + productModel + ".xml");
+        expectFetch(kOdmLegacyVintfDir + "manifest_" + productModel + ".xml");
     }
-    expectFetch("/odm/etc/manifest.xml");
-    expectFetch("/vendor/manifest.xml", vendorManifest);
+    expectFetch(kOdmLegacyManifest);
+    expectFetch(kVendorLegacyManifest, vendorManifest);
 
     auto p = VintfObject::GetDeviceHalManifest(true /* skipCache */);
     ASSERT_NE(nullptr, p);