summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2018-01-14 02:26:14 -0600
committerandroid-build-team Robot2018-01-14 02:26:14 -0600
commit920b274fd5ad9d79ffbec1d820f91f703b4d276e (patch)
tree21e4f99d52c6d8ae507625cc07557362254169aa /CompatibilityMatrix.cpp
parenteaffd4a2a652305877545cc8d8c46d5e25b0ad3e (diff)
parentb7008f8d49920594ce28dbeb36057394816d1c59 (diff)
downloadplatform-system-libvintf-920b274fd5ad9d79ffbec1d820f91f703b4d276e.tar.gz
platform-system-libvintf-920b274fd5ad9d79ffbec1d820f91f703b4d276e.tar.xz
platform-system-libvintf-920b274fd5ad9d79ffbec1d820f91f703b4d276e.zip
Snap for 4545621 from b7008f8d49920594ce28dbeb36057394816d1c59 to pi-release
Change-Id: Ifd6e5d95557869080270084b84045bf13dd5c2d8
Diffstat (limited to 'CompatibilityMatrix.cpp')
-rw-r--r--CompatibilityMatrix.cpp128
1 files changed, 127 insertions, 1 deletions
diff --git a/CompatibilityMatrix.cpp b/CompatibilityMatrix.cpp
index 1e7d542..8331f78 100644
--- a/CompatibilityMatrix.cpp
+++ b/CompatibilityMatrix.cpp
@@ -21,6 +21,9 @@
21#include "parse_string.h" 21#include "parse_string.h"
22#include "utils.h" 22#include "utils.h"
23 23
24#include <iostream>
25#include "parse_xml.h"
26
24namespace android { 27namespace android {
25namespace vintf { 28namespace vintf {
26 29
@@ -159,12 +162,135 @@ bool CompatibilityMatrix::addAllXmlFilesAsOptional(CompatibilityMatrix* other, s
159bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) { 162bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
160 return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals && 163 return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals &&
161 lft.mXmlFiles == rgt.mXmlFiles && 164 lft.mXmlFiles == rgt.mXmlFiles &&
162 (lft.mType != SchemaType::DEVICE || (lft.device.mVndk == rgt.device.mVndk)) && 165 (lft.mType != SchemaType::DEVICE ||
166 (
167#pragma clang diagnostic push
168#pragma clang diagnostic ignored "-Wdeprecated-declarations"
169 lft.device.mVndk == rgt.device.mVndk &&
170#pragma clang diagnostic pop
171 lft.device.mVendorNdk == rgt.device.mVendorNdk)) &&
163 (lft.mType != SchemaType::FRAMEWORK || 172 (lft.mType != SchemaType::FRAMEWORK ||
164 (lft.framework.mKernels == rgt.framework.mKernels && 173 (lft.framework.mKernels == rgt.framework.mKernels &&
165 lft.framework.mSepolicy == rgt.framework.mSepolicy && 174 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
166 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion)); 175 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
167} 176}
168 177
178// Find compatibility_matrix.empty.xml (which has unspecified level) and use it
179// as a base matrix.
180CompatibilityMatrix* CompatibilityMatrix::findOrInsertBaseMatrix(
181 std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) {
182 bool multipleFound = false;
183 CompatibilityMatrix* matrix = nullptr;
184 for (auto& e : *matrices) {
185 if (e.object.level() == Level::UNSPECIFIED) {
186 if (!e.object.mHals.empty()) {
187 if (error) {
188 *error = "Error: File \"" + e.name + "\" should not contain " + "HAL elements.";
189 }
190 return nullptr;
191 }
192
193 if (!e.object.mXmlFiles.empty()) {
194 if (error) {
195 *error =
196 "Error: File \"" + e.name + "\" should not contain " + "XML File elements.";
197 }
198 return nullptr;
199 }
200
201 if (matrix != nullptr) {
202 multipleFound = true;
203 }
204
205 matrix = &e.object;
206 // continue to detect multiple files with "unspecified" levels
207 }
208 }
209
210 if (multipleFound) {
211 if (error) {
212 *error =
213 "Error: multiple framework compatibility matrix files have "
214 "unspecified level; there should only be one such file.\n";
215 for (auto& e : *matrices) {
216 if (e.object.level() == Level::UNSPECIFIED) {
217 *error += " " + e.name + "\n";
218 }
219 }
220 }
221 return nullptr;
222 }
223
224 if (matrix == nullptr) {
225 matrix = &matrices->emplace(matrices->end())->object;
226 matrix->mType = SchemaType::FRAMEWORK;
227 matrix->mLevel = Level::UNSPECIFIED;
228 }
229
230 return matrix;
231}
232
233CompatibilityMatrix* CompatibilityMatrix::combine(Level deviceLevel,
234 std::vector<Named<CompatibilityMatrix>>* matrices,
235 std::string* error) {
236 if (deviceLevel == Level::UNSPECIFIED) {
237 if (error) {
238 *error = "Error: device level is unspecified.";
239 }
240 return nullptr;
241 }
242
243 CompatibilityMatrix* matrix = findOrInsertBaseMatrix(matrices, error);
244 if (matrix == nullptr) {
245 return nullptr;
246 }
247
248 matrix->mLevel = deviceLevel;
249
250 for (auto& e : *matrices) {
251 if (&e.object != matrix && e.object.level() == deviceLevel) {
252 if (!matrix->addAllHals(&e.object, error)) {
253 if (error) {
254 *error = "File \"" + e.name + "\" cannot be added: HAL " + *error +
255 " has a conflict.";
256 }
257 return nullptr;
258 }
259
260 if (!matrix->addAllXmlFiles(&e.object, error)) {
261 if (error) {
262 *error = "File \"" + e.name + "\" cannot be added: XML File entry " + *error +
263 " has a conflict.";
264 }
265 return nullptr;
266 }
267 }
268 }
269
270 for (auto& e : *matrices) {
271 if (&e.object != matrix && e.object.level() != Level::UNSPECIFIED &&
272 e.object.level() > deviceLevel) {
273 if (!matrix->addAllHalsAsOptional(&e.object, error)) {
274 if (error) {
275 *error = "File \"" + e.name + "\" cannot be added: " + *error +
276 ". See <hal> with the same name " +
277 "in previously parsed files or previously declared in this file.";
278 }
279 return nullptr;
280 }
281
282 if (!matrix->addAllXmlFilesAsOptional(&e.object, error)) {
283 if (error) {
284 *error = "File \"" + e.name + "\" cannot be added: XML File entry " + *error +
285 " has a conflict.";
286 }
287 return nullptr;
288 }
289 }
290 }
291
292 return matrix;
293}
294
169} // namespace vintf 295} // namespace vintf
170} // namespace android 296} // namespace android