diff options
Diffstat (limited to 'HalManifest.cpp')
-rw-r--r-- | HalManifest.cpp | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/HalManifest.cpp b/HalManifest.cpp index 45816f6..20ed7eb 100644 --- a/HalManifest.cpp +++ b/HalManifest.cpp | |||
@@ -24,6 +24,8 @@ | |||
24 | #include <mutex> | 24 | #include <mutex> |
25 | #include <set> | 25 | #include <set> |
26 | 26 | ||
27 | #include <android-base/strings.h> | ||
28 | |||
27 | #include "parse_string.h" | 29 | #include "parse_string.h" |
28 | #include "parse_xml.h" | 30 | #include "parse_xml.h" |
29 | #include "utils.h" | 31 | #include "utils.h" |
@@ -37,6 +39,9 @@ bool HalManifest::shouldAdd(const ManifestHal& hal) const { | |||
37 | if (!hal.isValid()) { | 39 | if (!hal.isValid()) { |
38 | return false; | 40 | return false; |
39 | } | 41 | } |
42 | if (hal.isOverride) { | ||
43 | return true; | ||
44 | } | ||
40 | auto existingHals = mHals.equal_range(hal.name); | 45 | auto existingHals = mHals.equal_range(hal.name); |
41 | std::set<size_t> existingMajorVersions; | 46 | std::set<size_t> existingMajorVersions; |
42 | for (auto it = existingHals.first; it != existingHals.second; ++it) { | 47 | for (auto it = existingHals.first; it != existingHals.second; ++it) { |
@@ -53,6 +58,48 @@ bool HalManifest::shouldAdd(const ManifestHal& hal) const { | |||
53 | return true; | 58 | return true; |
54 | } | 59 | } |
55 | 60 | ||
61 | // Remove elements from "list" if p(element) returns true. | ||
62 | template <typename List, typename Predicate> | ||
63 | static void removeIf(List& list, Predicate predicate) { | ||
64 | for (auto it = list.begin(); it != list.end();) { | ||
65 | if (predicate(*it)) { | ||
66 | it = list.erase(it); | ||
67 | } else { | ||
68 | ++it; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | void HalManifest::removeHals(const std::string& name, size_t majorVer) { | ||
74 | removeIf(mHals, [&name, majorVer](auto& existingHalPair) { | ||
75 | auto& existingHal = existingHalPair.second; | ||
76 | if (existingHal.name != name) { | ||
77 | return false; | ||
78 | } | ||
79 | auto& existingVersions = existingHal.versions; | ||
80 | removeIf(existingVersions, [majorVer](const auto& existingVersion) { | ||
81 | return existingVersion.majorVer == majorVer; | ||
82 | }); | ||
83 | return existingVersions.empty(); | ||
84 | }); | ||
85 | } | ||
86 | |||
87 | bool HalManifest::add(ManifestHal&& halToAdd) { | ||
88 | if (halToAdd.isOverride) { | ||
89 | if (halToAdd.versions.empty()) { | ||
90 | // Special syntax when there are no <version> tags at all. Remove all existing HALs | ||
91 | // with the given name. | ||
92 | mHals.erase(halToAdd.name); | ||
93 | } | ||
94 | // If there are <version> tags, remove all existing major versions that causes a conflict. | ||
95 | for (const Version& versionToAdd : halToAdd.versions) { | ||
96 | removeHals(halToAdd.name, versionToAdd.majorVer); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | return HalGroup::add(std::move(halToAdd)); | ||
101 | } | ||
102 | |||
56 | bool HalManifest::shouldAddXmlFile(const ManifestXmlFile& xmlFile) const { | 103 | bool HalManifest::shouldAddXmlFile(const ManifestXmlFile& xmlFile) const { |
57 | auto existingXmlFiles = getXmlFiles(xmlFile.name()); | 104 | auto existingXmlFiles = getXmlFiles(xmlFile.name()); |
58 | for (auto it = existingXmlFiles.first; it != existingXmlFiles.second; ++it) { | 105 | for (auto it = existingXmlFiles.first; it != existingXmlFiles.second; ++it) { |
@@ -254,6 +301,22 @@ static bool checkVendorNdkCompatibility(const VendorNdk& matVendorNdk, | |||
254 | return false; | 301 | return false; |
255 | } | 302 | } |
256 | 303 | ||
304 | static bool checkSystemSdkCompatibility(const SystemSdk& matSystemSdk, | ||
305 | const SystemSdk& manifestSystemSdk, std::string* error) { | ||
306 | SystemSdk notSupported = matSystemSdk.removeVersions(manifestSystemSdk); | ||
307 | if (!notSupported.empty()) { | ||
308 | if (error) { | ||
309 | *error = | ||
310 | "The following System SDK versions are required by device " | ||
311 | "compatibility matrix but not supported by the framework manifest: [" + | ||
312 | base::Join(notSupported.versions(), ", ") + "]. Supported versions are: [" + | ||
313 | base::Join(manifestSystemSdk.versions(), ", ") + "]."; | ||
314 | } | ||
315 | return false; | ||
316 | } | ||
317 | return true; | ||
318 | } | ||
319 | |||
257 | bool HalManifest::checkCompatibility(const CompatibilityMatrix &mat, std::string *error) const { | 320 | bool HalManifest::checkCompatibility(const CompatibilityMatrix &mat, std::string *error) const { |
258 | if (mType == mat.mType) { | 321 | if (mType == mat.mType) { |
259 | if (error != nullptr) { | 322 | if (error != nullptr) { |
@@ -277,6 +340,10 @@ bool HalManifest::checkCompatibility(const CompatibilityMatrix &mat, std::string | |||
277 | if (!checkVendorNdkCompatibility(mat.device.mVendorNdk, framework.mVendorNdks, error)) { | 340 | if (!checkVendorNdkCompatibility(mat.device.mVendorNdk, framework.mVendorNdks, error)) { |
278 | return false; | 341 | return false; |
279 | } | 342 | } |
343 | |||
344 | if (!checkSystemSdkCompatibility(mat.device.mSystemSdk, framework.mSystemSdk, error)) { | ||
345 | return false; | ||
346 | } | ||
280 | } else if (mType == SchemaType::DEVICE) { | 347 | } else if (mType == SchemaType::DEVICE) { |
281 | bool match = false; | 348 | bool match = false; |
282 | for (const auto &range : mat.framework.mSepolicy.sepolicyVersions()) { | 349 | for (const auto &range : mat.framework.mSepolicy.sepolicyVersions()) { |
@@ -379,7 +446,8 @@ bool operator==(const HalManifest &lft, const HalManifest &rgt) { | |||
379 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 446 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
380 | lft.framework.mVndks == rgt.framework.mVndks && | 447 | lft.framework.mVndks == rgt.framework.mVndks && |
381 | #pragma clang diagnostic pop | 448 | #pragma clang diagnostic pop |
382 | lft.framework.mVendorNdks == rgt.framework.mVendorNdks)); | 449 | lft.framework.mVendorNdks == rgt.framework.mVendorNdks && |
450 | lft.framework.mSystemSdk == rgt.framework.mSystemSdk)); | ||
383 | } | 451 | } |
384 | 452 | ||
385 | } // namespace vintf | 453 | } // namespace vintf |