summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2018-03-13 14:36:38 -0500
committerYifan Hong2018-03-14 19:35:18 -0500
commit2b1efaa1de422f702e8b2ab4b922b8408da188cd (patch)
treee3cdb7f486cbcc9b5053a914e3b783ae57ac2ebe /ManifestHal.cpp
parent075b363fb67edc80e688ea5de75fb1fb122509b1 (diff)
downloadplatform-system-libvintf-2b1efaa1de422f702e8b2ab4b922b8408da188cd.tar.gz
platform-system-libvintf-2b1efaa1de422f702e8b2ab4b922b8408da188cd.tar.xz
platform-system-libvintf-2b1efaa1de422f702e8b2ab4b922b8408da188cd.zip
Add <fqname> to manifests.
The format of <fqname> is: <hal> <name>android.hardware.foo</name> <!-- transport, etc. --> <fqname>@1.0::IFoo/default</fqname> </hal> It is possible to mix <fqname> and <version> x <interface> x <instance> ; see tests for details. This allows instances at different versions. For example, it is now allowed to serve @1.0::IFoo/default, @1.1::IFoo/custom simultaneously without serving @1.1::IFoo/default. If override="true" and no <version>x<interface>x<instance> nor <fqname>, the HAL tag is disabled. (Previously, the HAL tag is disabled iff no <version> exists). Bug: 73556059 Test: libvintf_test Test: vintf_object_test Change-Id: I80cb9ccdeec708c2c5530812913b37f8b3cc3ffa
Diffstat (limited to 'ManifestHal.cpp')
-rw-r--r--ManifestHal.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index cd30f16..1576c80 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -18,6 +18,7 @@
18#include <unordered_set> 18#include <unordered_set>
19 19
20#include "MapValueIterator.h" 20#include "MapValueIterator.h"
21#include "parse_string.h"
21 22
22namespace android { 23namespace android {
23namespace vintf { 24namespace vintf {
@@ -43,11 +44,11 @@ bool ManifestHal::operator==(const ManifestHal &other) const {
43 if (!(transportArch == other.transportArch)) return false; 44 if (!(transportArch == other.transportArch)) return false;
44 if (interfaces != other.interfaces) return false; 45 if (interfaces != other.interfaces) return false;
45 if (isOverride() != other.isOverride()) return false; 46 if (isOverride() != other.isOverride()) return false;
47 if (mAdditionalInstances != other.mAdditionalInstances) return false;
46 return true; 48 return true;
47} 49}
48 50
49bool ManifestHal::forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const { 51bool ManifestHal::forEachInstance(const std::function<bool(const ManifestInstance&)>& func) const {
50 // TODO(b/73556059): support <fqname> as well.
51 for (const auto& v : versions) { 52 for (const auto& v : versions) {
52 for (const auto& intf : iterateValues(interfaces)) { 53 for (const auto& intf : iterateValues(interfaces)) {
53 for (const auto& instance : intf.instances) { 54 for (const auto& instance : intf.instances) {
@@ -62,6 +63,13 @@ bool ManifestHal::forEachInstance(const std::function<bool(const ManifestInstanc
62 } 63 }
63 } 64 }
64 } 65 }
66
67 for (const auto& manifestInstance : mAdditionalInstances) {
68 if (!func(manifestInstance)) {
69 return false;
70 }
71 }
72
65 return true; 73 return true;
66} 74}
67 75
@@ -83,5 +91,49 @@ void ManifestHal::appendAllVersions(std::set<Version>* ret) const {
83 }); 91 });
84} 92}
85 93
94static bool verifyInstances(const std::set<FqInstance>& fqInstances, std::string* error) {
95 for (const FqInstance& fqInstance : fqInstances) {
96 if (fqInstance.hasPackage()) {
97 if (error) *error = "Should not specify package: \"" + fqInstance.string() + "\"";
98 return false;
99 }
100 if (!fqInstance.hasVersion()) {
101 if (error) *error = "Should specify version: \"" + fqInstance.string() + "\"";
102 return false;
103 }
104 if (!fqInstance.hasInterface()) {
105 if (error) *error = "Should specify interface: \"" + fqInstance.string() + "\"";
106 return false;
107 }
108 if (!fqInstance.hasInstance()) {
109 if (error) *error = "Should specify instance: \"" + fqInstance.string() + "\"";
110 return false;
111 }
112 }
113 return true;
114}
115
116bool ManifestHal::insertInstances(const std::set<FqInstance>& fqInstances, std::string* error) {
117 if (!verifyInstances(fqInstances, error)) {
118 return false;
119 }
120
121 for (const FqInstance& e : fqInstances) {
122 FqInstance withPackage;
123 if (!withPackage.setTo(this->getName(), e.getMajorVersion(), e.getMinorVersion(),
124 e.getInterface(), e.getInstance())) {
125 if (error) {
126 *error = "Cannot create FqInstance with package='" + this->getName() +
127 "', version='" + to_string(Version(e.getVersion())) + "', interface='" +
128 e.getInterface() + "', instance='" + e.getInstance() + "'";
129 }
130 return false;
131 }
132 mAdditionalInstances.emplace(std::move(withPackage), this->transportArch);
133 }
134
135 return true;
136}
137
86} // namespace vintf 138} // namespace vintf
87} // namespace android 139} // namespace android