summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CompatibilityMatrix.cpp10
-rw-r--r--HalManifest.cpp4
-rw-r--r--VintfObject.cpp36
-rw-r--r--assemble_vintf.cpp10
-rw-r--r--check_vintf.cpp6
-rw-r--r--include/vintf/CompatibilityMatrix.h2
-rw-r--r--include/vintf/HalManifest.h2
-rw-r--r--test/LibVintfTest.cpp1
-rw-r--r--test/utils-fake.h8
-rw-r--r--utils.h22
10 files changed, 58 insertions, 43 deletions
diff --git a/CompatibilityMatrix.cpp b/CompatibilityMatrix.cpp
index 7afaa9b..1e7d542 100644
--- a/CompatibilityMatrix.cpp
+++ b/CompatibilityMatrix.cpp
@@ -50,8 +50,8 @@ Version CompatibilityMatrix::getMinimumMetaVersion() const {
50 return {1, 0}; 50 return {1, 0};
51} 51}
52 52
53status_t CompatibilityMatrix::fetchAllInformation(const std::string &path) { 53status_t CompatibilityMatrix::fetchAllInformation(const std::string& path, std::string* error) {
54 return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this); 54 return details::fetchAllInformation(path, gCompatibilityMatrixConverter, this, error);
55} 55}
56 56
57std::string CompatibilityMatrix::getXmlSchemaPath(const std::string& xmlFileName, 57std::string CompatibilityMatrix::getXmlSchemaPath(const std::string& xmlFileName,
@@ -108,8 +108,10 @@ bool CompatibilityMatrix::addAllHalsAsOptional(CompatibilityMatrix* other, std::
108 std::tie(existingHal, existingVr) = getHalWithMajorVersion(name, vr.majorVer); 108 std::tie(existingHal, existingVr) = getHalWithMajorVersion(name, vr.majorVer);
109 109
110 if (existingHal == nullptr) { 110 if (existingHal == nullptr) {
111 halToAdd.optional = true; 111 MatrixHal optionalHalToAdd(halToAdd);
112 if (!add(std::move(halToAdd))) { 112 optionalHalToAdd.optional = true;
113 optionalHalToAdd.versionRanges = {vr};
114 if (!add(std::move(optionalHalToAdd))) {
113 if (error) { 115 if (error) {
114 *error = "Cannot add HAL " + name + " for unknown reason."; 116 *error = "Cannot add HAL " + name + " for unknown reason.";
115 } 117 }
diff --git a/HalManifest.cpp b/HalManifest.cpp
index 9683729..cd4302f 100644
--- a/HalManifest.cpp
+++ b/HalManifest.cpp
@@ -311,8 +311,8 @@ CompatibilityMatrix HalManifest::generateCompatibleMatrix() const {
311 return matrix; 311 return matrix;
312} 312}
313 313
314status_t HalManifest::fetchAllInformation(const std::string &path) { 314status_t HalManifest::fetchAllInformation(const std::string& path, std::string* error) {
315 return details::fetchAllInformation(path, gHalManifestConverter, this); 315 return details::fetchAllInformation(path, gHalManifestConverter, this, error);
316} 316}
317 317
318SchemaType HalManifest::type() const { 318SchemaType HalManifest::type() const {
diff --git a/VintfObject.cpp b/VintfObject.cpp
index efe6242..a49fc24 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -28,6 +28,11 @@
28#include <android-base/properties.h> 28#include <android-base/properties.h>
29#endif 29#endif
30 30
31#include <android-base/logging.h>
32
33using std::placeholders::_1;
34using std::placeholders::_2;
35
31namespace android { 36namespace android {
32namespace vintf { 37namespace vintf {
33 38
@@ -35,6 +40,7 @@ template <typename T>
35struct LockedSharedPtr { 40struct LockedSharedPtr {
36 std::shared_ptr<T> object; 41 std::shared_ptr<T> object;
37 std::mutex mutex; 42 std::mutex mutex;
43 bool fetchedOnce = false;
38}; 44};
39 45
40struct LockedRuntimeInfoCache { 46struct LockedRuntimeInfoCache {
@@ -49,11 +55,14 @@ static std::shared_ptr<const T> Get(
49 bool skipCache, 55 bool skipCache,
50 const F &fetchAllInformation) { 56 const F &fetchAllInformation) {
51 std::unique_lock<std::mutex> _lock(ptr->mutex); 57 std::unique_lock<std::mutex> _lock(ptr->mutex);
52 if (skipCache || ptr->object == nullptr) { 58 if (skipCache || !ptr->fetchedOnce) {
53 ptr->object = std::make_unique<T>(); 59 ptr->object = std::make_unique<T>();
54 if (fetchAllInformation(ptr->object.get()) != OK) { 60 std::string error;
61 if (fetchAllInformation(ptr->object.get(), &error) != OK) {
62 LOG(WARNING) << error;
55 ptr->object = nullptr; // frees the old object 63 ptr->object = nullptr; // frees the old object
56 } 64 }
65 ptr->fetchedOnce = true;
57 } 66 }
58 return ptr->object; 67 return ptr->object;
59} 68}
@@ -73,32 +82,29 @@ std::shared_ptr<const HalManifest> VintfObject::GetDeviceHalManifest(bool skipCa
73 std::string productModel = android::base::GetProperty("ro.product.model", ""); 82 std::string productModel = android::base::GetProperty("ro.product.model", "");
74 if (!productModel.empty()) { 83 if (!productModel.empty()) {
75 auto product = Get(&gProductManifest, skipCache, 84 auto product = Get(&gProductManifest, skipCache,
76 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1, 85 std::bind(&HalManifest::fetchAllInformation, _1,
77 "/odm/manifest_" + productModel + ".xml")); 86 "/odm/manifest_" + productModel + ".xml", _2));
78 if (product != nullptr) { 87 if (product != nullptr) {
79 return product; 88 return product;
80 } 89 }
81 } 90 }
82#endif 91#endif
83 92
84 auto odm = Get( 93 auto odm = Get(&gOdmManifest, skipCache,
85 &gOdmManifest, skipCache, 94 std::bind(&HalManifest::fetchAllInformation, _1, "/odm/manifest.xml", _2));
86 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1, "/odm/manifest.xml"));
87 if (odm != nullptr) { 95 if (odm != nullptr) {
88 return odm; 96 return odm;
89 } 97 }
90 98
91 return Get(&gVendorManifest, skipCache, 99 return Get(&gVendorManifest, skipCache,
92 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1, 100 std::bind(&HalManifest::fetchAllInformation, _1, "/vendor/manifest.xml", _2));
93 "/vendor/manifest.xml"));
94} 101}
95 102
96// static 103// static
97std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) { 104std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool skipCache) {
98 static LockedSharedPtr<HalManifest> gFrameworkManifest; 105 static LockedSharedPtr<HalManifest> gFrameworkManifest;
99 return Get(&gFrameworkManifest, skipCache, 106 return Get(&gFrameworkManifest, skipCache,
100 std::bind(&HalManifest::fetchAllInformation, std::placeholders::_1, 107 std::bind(&HalManifest::fetchAllInformation, _1, "/system/manifest.xml", _2));
101 "/system/manifest.xml"));
102} 108}
103 109
104 110
@@ -106,16 +112,16 @@ std::shared_ptr<const HalManifest> VintfObject::GetFrameworkHalManifest(bool ski
106std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) { 112std::shared_ptr<const CompatibilityMatrix> VintfObject::GetDeviceCompatibilityMatrix(bool skipCache) {
107 static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix; 113 static LockedSharedPtr<CompatibilityMatrix> gDeviceMatrix;
108 return Get(&gDeviceMatrix, skipCache, 114 return Get(&gDeviceMatrix, skipCache,
109 std::bind(&CompatibilityMatrix::fetchAllInformation, std::placeholders::_1, 115 std::bind(&CompatibilityMatrix::fetchAllInformation, _1,
110 "/vendor/compatibility_matrix.xml")); 116 "/vendor/compatibility_matrix.xml", _2));
111} 117}
112 118
113// static 119// static
114std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) { 120std::shared_ptr<const CompatibilityMatrix> VintfObject::GetFrameworkCompatibilityMatrix(bool skipCache) {
115 static LockedSharedPtr<CompatibilityMatrix> gFrameworkMatrix; 121 static LockedSharedPtr<CompatibilityMatrix> gFrameworkMatrix;
116 return Get(&gFrameworkMatrix, skipCache, 122 return Get(&gFrameworkMatrix, skipCache,
117 std::bind(&CompatibilityMatrix::fetchAllInformation, std::placeholders::_1, 123 std::bind(&CompatibilityMatrix::fetchAllInformation, _1,
118 "/system/compatibility_matrix.xml")); 124 "/system/compatibility_matrix.xml", _2));
119} 125}
120 126
121// static 127// static
diff --git a/assemble_vintf.cpp b/assemble_vintf.cpp
index fd8eb9f..0aa79fd 100644
--- a/assemble_vintf.cpp
+++ b/assemble_vintf.cpp
@@ -344,16 +344,6 @@ class AssembleVintf {
344 } 344 }
345 345
346 bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) { 346 bool assembleFrameworkCompatibilityMatrixKernels(CompatibilityMatrix* matrix) {
347 if (!matrix->framework.mKernels.empty()) {
348 // Remove hard-coded <kernel version="x.y.z" /> in legacy files.
349 std::cerr << "WARNING: framework compatibility matrix has hard-coded kernel"
350 << " requirements for version";
351 for (const auto& kernel : matrix->framework.mKernels) {
352 std::cerr << " " << kernel.minLts();
353 }
354 std::cerr << ". Hard-coded requirements are removed." << std::endl;
355 matrix->framework.mKernels.clear();
356 }
357 for (const auto& pair : mKernels) { 347 for (const auto& pair : mKernels) {
358 std::vector<ConditionedConfig> conditionedConfigs; 348 std::vector<ConditionedConfig> conditionedConfigs;
359 if (!parseFilesForKernelConfigs(pair.second, &conditionedConfigs)) { 349 if (!parseFilesForKernelConfigs(pair.second, &conditionedConfigs)) {
diff --git a/check_vintf.cpp b/check_vintf.cpp
index 211702e..67ecd4e 100644
--- a/check_vintf.cpp
+++ b/check_vintf.cpp
@@ -25,9 +25,11 @@ namespace vintf {
25template <typename T> 25template <typename T>
26std::unique_ptr<T> readObject(const std::string& path, const XmlConverter<T>& converter) { 26std::unique_ptr<T> readObject(const std::string& path, const XmlConverter<T>& converter) {
27 std::string xml; 27 std::string xml;
28 status_t err = details::gFetcher->fetch(path, xml); 28 std::string error;
29 status_t err = details::gFetcher->fetch(path, xml, &error);
29 if (err != OK) { 30 if (err != OK) {
30 std::cerr << "Error: Cannot read '" << path << "': " << strerror(-err) << std::endl; 31 std::cerr << "Error: Cannot read '" << path << "' (" << strerror(-err) << "): " << error
32 << std::endl;
31 return nullptr; 33 return nullptr;
32 } 34 }
33 auto ret = std::make_unique<T>(); 35 auto ret = std::make_unique<T>();
diff --git a/include/vintf/CompatibilityMatrix.h b/include/vintf/CompatibilityMatrix.h
index 1bb6387..bfb4dbf 100644
--- a/include/vintf/CompatibilityMatrix.h
+++ b/include/vintf/CompatibilityMatrix.h
@@ -71,7 +71,7 @@ struct CompatibilityMatrix : public HalGroup<MatrixHal>, public XmlFileGroup<Mat
71 // Similar to addAllHalsAsOptional but on <xmlfile> entries. 71 // Similar to addAllHalsAsOptional but on <xmlfile> entries.
72 bool addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error); 72 bool addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error);
73 73
74 status_t fetchAllInformation(const std::string &path); 74 status_t fetchAllInformation(const std::string& path, std::string* error = nullptr);
75 75
76 friend struct HalManifest; 76 friend struct HalManifest;
77 friend struct RuntimeInfo; 77 friend struct RuntimeInfo;
diff --git a/include/vintf/HalManifest.h b/include/vintf/HalManifest.h
index 46657de..cc64201 100644
--- a/include/vintf/HalManifest.h
+++ b/include/vintf/HalManifest.h
@@ -127,7 +127,7 @@ struct HalManifest : public HalGroup<ManifestHal>, public XmlFileGroup<ManifestX
127 friend std::string dump(const HalManifest &vm); 127 friend std::string dump(const HalManifest &vm);
128 friend bool operator==(const HalManifest &lft, const HalManifest &rgt); 128 friend bool operator==(const HalManifest &lft, const HalManifest &rgt);
129 129
130 status_t fetchAllInformation(const std::string &path); 130 status_t fetchAllInformation(const std::string& path, std::string* error = nullptr);
131 131
132 // Check if all instances in matrixHal is supported in this manifest. 132 // Check if all instances in matrixHal is supported in this manifest.
133 bool isCompatible(const MatrixHal& matrixHal) const; 133 bool isCompatible(const MatrixHal& matrixHal) const;
diff --git a/test/LibVintfTest.cpp b/test/LibVintfTest.cpp
index 8c07075..af2bc67 100644
--- a/test/LibVintfTest.cpp
+++ b/test/LibVintfTest.cpp
@@ -2203,6 +2203,7 @@ TEST_F(LibVintfTest, AddOptionalHalMajorVersion) {
2203 "<compatibility-matrix version=\"1.0\" type=\"framework\" level=\"2\">\n" 2203 "<compatibility-matrix version=\"1.0\" type=\"framework\" level=\"2\">\n"
2204 " <hal format=\"hidl\" optional=\"false\">\n" 2204 " <hal format=\"hidl\" optional=\"false\">\n"
2205 " <name>android.hardware.foo</name>\n" 2205 " <name>android.hardware.foo</name>\n"
2206 " <version>1.2-3</version>\n"
2206 " <version>2.0-4</version>\n" 2207 " <version>2.0-4</version>\n"
2207 " <interface>\n" 2208 " <interface>\n"
2208 " <name>IFoo</name>\n" 2209 " <name>IFoo</name>\n"
diff --git a/test/utils-fake.h b/test/utils-fake.h
index dd93542..7d7caf2 100644
--- a/test/utils-fake.h
+++ b/test/utils-fake.h
@@ -31,11 +31,17 @@ class MockFileFetcher : public FileFetcher {
31 public: 31 public:
32 MockFileFetcher() { 32 MockFileFetcher() {
33 // By default call through to the original. 33 // By default call through to the original.
34 ON_CALL(*this, fetch(_, _)).WillByDefault(Invoke(&real_, &FileFetcher::fetch)); 34 ON_CALL(*this, fetch(_, _)).WillByDefault(Invoke([this](const auto& path, auto& fetched) {
35 return real_.fetchInternal(path, fetched, nullptr);
36 }));
35 } 37 }
36 38
37 MOCK_METHOD2(fetch, status_t(const std::string& path, std::string& fetched)); 39 MOCK_METHOD2(fetch, status_t(const std::string& path, std::string& fetched));
38 40
41 status_t fetch(const std::string& path, std::string& fetched, std::string*) override final {
42 return fetch(path, fetched);
43 }
44
39 private: 45 private:
40 FileFetcher real_; 46 FileFetcher real_;
41}; 47};
diff --git a/utils.h b/utils.h
index c08a22e..dce03b3 100644
--- a/utils.h
+++ b/utils.h
@@ -21,7 +21,6 @@
21#include <iostream> 21#include <iostream>
22#include <sstream> 22#include <sstream>
23 23
24#include <android-base/logging.h>
25#include <utils/Errors.h> 24#include <utils/Errors.h>
26#include <vintf/RuntimeInfo.h> 25#include <vintf/RuntimeInfo.h>
27#include <vintf/parse_xml.h> 26#include <vintf/parse_xml.h>
@@ -36,12 +35,14 @@ namespace details {
36class FileFetcher { 35class FileFetcher {
37 public: 36 public:
38 virtual ~FileFetcher() {} 37 virtual ~FileFetcher() {}
39 virtual status_t fetch(const std::string& path, std::string& fetched) { 38 status_t fetchInternal(const std::string& path, std::string& fetched, std::string* error) {
40 std::ifstream in; 39 std::ifstream in;
41 40
42 in.open(path); 41 in.open(path);
43 if (!in.is_open()) { 42 if (!in.is_open()) {
44 LOG(WARNING) << "Cannot open " << path; 43 if (error) {
44 *error = "Cannot open " + path;
45 }
45 return INVALID_OPERATION; 46 return INVALID_OPERATION;
46 } 47 }
47 48
@@ -51,6 +52,12 @@ class FileFetcher {
51 52
52 return OK; 53 return OK;
53 } 54 }
55 virtual status_t fetch(const std::string& path, std::string& fetched, std::string* error) {
56 return fetchInternal(path, fetched, error);
57 }
58 virtual status_t fetch(const std::string& path, std::string& fetched) {
59 return fetchInternal(path, fetched, nullptr);
60 }
54}; 61};
55 62
56extern FileFetcher* gFetcher; 63extern FileFetcher* gFetcher;
@@ -68,7 +75,7 @@ extern PartitionMounter* gPartitionMounter;
68 75
69template <typename T> 76template <typename T>
70status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& converter, 77status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& converter,
71 T* outObject) { 78 T* outObject, std::string* error = nullptr) {
72 std::string info; 79 std::string info;
73 80
74 if (gFetcher == nullptr) { 81 if (gFetcher == nullptr) {
@@ -76,7 +83,7 @@ status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& con
76 return NO_INIT; 83 return NO_INIT;
77 } 84 }
78 85
79 status_t result = gFetcher->fetch(path, info); 86 status_t result = gFetcher->fetch(path, info, error);
80 87
81 if (result != OK) { 88 if (result != OK) {
82 return result; 89 return result;
@@ -84,8 +91,9 @@ status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& con
84 91
85 bool success = converter(outObject, info); 92 bool success = converter(outObject, info);
86 if (!success) { 93 if (!success) {
87 LOG(ERROR) << "Illformed file: " << path << ": " 94 if (error) {
88 << converter.lastError(); 95 *error = "Illformed file: " + path + ": " + converter.lastError();
96 }
89 return BAD_VALUE; 97 return BAD_VALUE;
90 } 98 }
91 return OK; 99 return OK;