VintfObject: load /vendor/etc/vintf/cm.xml before /vendor/cm.xml

cm => compatibility_matrix

Test: vintf_object_test
Bug: 36790901
Change-Id: Id62cbd1a2a7612c0fbf15adce39dbef67a4c18a8
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 4a3e235..b852665 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -88,8 +88,7 @@
 // static
 std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
     static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix;
-    return Get(&gDeviceMatrix, skipCache,
-               std::bind(&CompatibilityMatrix::fetchAllInformation, _1, kVendorLegacyMatrix, _2));
+    return Get(&gDeviceMatrix, skipCache, &VintfObject::FetchDeviceMatrix);
 }
 
 // static
@@ -234,6 +233,15 @@
     return out->fetchAllInformation(kVendorLegacyManifest, error);
 }
 
+status_t VintfObject::FetchDeviceMatrix(CompatibilityMatrix* out, std::string* error) {
+    CompatibilityMatrix etcMatrix;
+    if (etcMatrix.fetchAllInformation(kVendorMatrix, error) == OK) {
+        *out = std::move(etcMatrix);
+        return OK;
+    }
+    return out->fetchAllInformation(kVendorLegacyMatrix, error);
+}
+
 std::vector<Named<CompatibilityMatrix>> VintfObject::GetAllFrameworkMatrixLevels(
     std::string* error) {
     std::vector<std::string> fileNames;
@@ -510,6 +518,7 @@
 
 const std::string kVendorManifest = kVendorVintfDir + "manifest.xml";
 const std::string kSystemManifest = kSystemVintfDir + "manifest.xml";
+const std::string kVendorMatrix = kVendorVintfDir + "compatibility_matrix.xml";
 
 const std::string kVendorLegacyManifest = "/vendor/manifest.xml";
 const std::string kVendorLegacyMatrix = "/vendor/compatibility_matrix.xml";
diff --git a/include/vintf/VintfObject.h b/include/vintf/VintfObject.h
index 7e47a20..8b1a944 100644
--- a/include/vintf/VintfObject.h
+++ b/include/vintf/VintfObject.h
@@ -119,6 +119,7 @@
     static std::vector<Named<CompatibilityMatrix>> GetAllFrameworkMatrixLevels(
         std::string* error = nullptr);
     static status_t FetchDeviceHalManifest(HalManifest* out, std::string* error = nullptr);
+    static status_t FetchDeviceMatrix(CompatibilityMatrix* out, std::string* error = nullptr);
 };
 
 enum : int32_t {
@@ -139,6 +140,7 @@
 extern const std::string kOdmLegacyManifest;
 extern const std::string kVendorManifest;
 extern const std::string kSystemManifest;
+extern const std::string kVendorMatrix;
 extern const std::string kVendorLegacyManifest;
 extern const std::string kVendorLegacyMatrix;
 extern const std::string kSystemLegacyMatrix;
diff --git a/test/vintf_object_tests.cpp b/test/vintf_object_tests.cpp
index 6e56a43..a415fdb 100644
--- a/test/vintf_object_tests.cpp
+++ b/test/vintf_object_tests.cpp
@@ -194,6 +194,8 @@
             fetched = systemManifestXml;
             return 0;
         }));
+    ON_CALL(*fetcher, fetch(StrEq(kVendorMatrix), _))
+        .WillByDefault(Return(::android::NAME_NOT_FOUND));
     ON_CALL(*fetcher, fetch(StrEq(kVendorLegacyMatrix), _))
         .WillByDefault(Invoke([vendorMatrixXml](const std::string& path, std::string& fetched) {
             (void)path;
@@ -245,6 +247,7 @@
     }
 
     void expectVendorMatrix(size_t times = 1) {
+        EXPECT_CALL(fetcher(), fetch(StrEq(kVendorMatrix), _)).Times(times);
         EXPECT_CALL(fetcher(), fetch(StrEq(kVendorLegacyMatrix), _)).Times(times);
     }