blob: 0ecb82cee29215de2e5086a1e85f8c8acda2685f [file] [log] [blame]
Yifan Hong676447a2016-11-15 12:57:23 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "CompatibilityMatrix.h"
18
Yifan Hongb6c7f492018-02-27 14:07:57 -080019#include <iostream>
Yifan Hongdbe9db32017-12-11 19:06:11 -080020#include <utility>
21
Yifan Hong1e8febd2019-08-07 16:17:19 -070022#include <android-base/logging.h>
Yifan Honge7837b12018-10-11 10:38:57 -070023#include <android-base/strings.h>
24
Yifan Hongbbfff302017-06-06 17:10:13 -070025#include "parse_string.h"
Yifan Hongddae77e2017-12-18 16:57:07 -080026#include "parse_xml.h"
Yifan Hongb6c7f492018-02-27 14:07:57 -080027#include "utils.h"
Yifan Hongddae77e2017-12-18 16:57:07 -080028
Yifan Hong676447a2016-11-15 12:57:23 -080029namespace android {
30namespace vintf {
31
Yifan Hong4c6962d2019-01-30 15:50:46 -080032using details::mergeField;
33
Yifan Honge7837b12018-10-11 10:38:57 -070034bool CompatibilityMatrix::addKernel(MatrixKernel&& kernel, std::string* error) {
Yifan Hong7c7d7062017-04-04 16:26:51 -070035 if (mType != SchemaType::FRAMEWORK) {
Yifan Honge7837b12018-10-11 10:38:57 -070036 if (error) {
37 *error = "Cannot add <kernel> to a " + to_string(mType) + " compatibility matrix.";
38 }
Yifan Hong7c7d7062017-04-04 16:26:51 -070039 return false;
40 }
Yifan Honge7837b12018-10-11 10:38:57 -070041
42 auto it = framework.mKernels.begin();
43 for (; it != framework.mKernels.end(); ++it) {
44 if (it->minLts() == kernel.minLts()) {
45 break;
46 }
47 if (it->minLts().version == kernel.minLts().version &&
48 it->minLts().majorRev == kernel.minLts().majorRev) {
49 if (error) {
50 *error = "Kernel version mismatch; cannot add " + to_string(kernel.minLts()) +
51 " because " + to_string(it->minLts()) + " was added.";
52 }
53 return false;
54 }
55 }
56
57 bool seenVersion = it != framework.mKernels.end();
58
59 if (seenVersion) {
60 // If no conditions, must be the first among the same minLts
61 // because O libvintf only checks the first <kernel> tag that version matches.
62 if (kernel.conditions().empty()) {
63 // Found first <kernel> with the same minLts.
64 // Append config if it does not have <condition>s, else error.
65 if (it->conditions().empty()) {
66 const auto& configs = kernel.configs();
67 it->mConfigs.insert(it->mConfigs.end(), configs.begin(), configs.end());
68 } else {
69 if (error) {
70 *error =
71 "Base compatibility matrix has <condition> for the first <kernel> "
72 "with minlts " +
73 to_string(kernel.minLts()) + " for unknown reason.";
74 }
75 return false;
76 }
77 return true;
78 }
79 } else {
80 // First <kernel> of a minLts must not have <condition>'s for backwards compatibility
81 // with O libvintf.
82 if (!kernel.conditions().empty()) {
83 framework.mKernels.push_back(MatrixKernel(KernelVersion{kernel.minLts()}, {}));
84 }
85 }
86
Yifan Hong7c7d7062017-04-04 16:26:51 -070087 framework.mKernels.push_back(std::move(kernel));
Yifan Hong676447a2016-11-15 12:57:23 -080088 return true;
89}
90
Yifan Hong398f4c72017-04-13 20:18:01 -070091SchemaType CompatibilityMatrix::type() const {
92 return mType;
93}
94
Yifan Hong2027a492017-12-11 15:21:19 -080095Level CompatibilityMatrix::level() const {
96 return mLevel;
97}
98
Yifan Hong9f78c182018-07-12 14:45:52 -070099status_t CompatibilityMatrix::fetchAllInformation(const FileSystem* fileSystem,
100 const std::string& path, std::string* error) {
101 return details::fetchAllInformation(fileSystem, path, gCompatibilityMatrixConverter, this,
102 error);
Yifan Hong1e5a0542017-04-28 14:37:56 -0700103}
104
Yifan Hongbbfff302017-06-06 17:10:13 -0700105std::string CompatibilityMatrix::getXmlSchemaPath(const std::string& xmlFileName,
106 const Version& version) const {
107 using std::literals::string_literals::operator""s;
108 auto range = getXmlFiles(xmlFileName);
109 for (auto it = range.first; it != range.second; ++it) {
110 const MatrixXmlFile& matrixXmlFile = it->second;
111 if (matrixXmlFile.versionRange().contains(version)) {
112 if (!matrixXmlFile.overriddenPath().empty()) {
113 return matrixXmlFile.overriddenPath();
114 }
115 return "/"s + (type() == SchemaType::DEVICE ? "vendor" : "system") + "/etc/" +
116 xmlFileName + "_V" + std::to_string(matrixXmlFile.versionRange().majorVer) +
117 "_" + std::to_string(matrixXmlFile.versionRange().maxMinor) + "." +
118 to_string(matrixXmlFile.format());
119 }
120 }
121 return "";
122}
123
Yifan Honge7e45532018-03-16 18:11:49 -0700124// Split existingHal into a HAL that contains only interface/instance and a HAL
125// that does not contain it. Return the HAL that contains only interface/instance.
126// - Return nullptr if existingHal does not contain interface/instance
127// - Return existingHal if existingHal contains only interface/instance
128// - Remove interface/instance from existingHal, and return a new MatrixHal (that is added
129// to "this") that contains only interface/instance.
130MatrixHal* CompatibilityMatrix::splitInstance(MatrixHal* existingHal, const std::string& interface,
Yifan Hong643a9ef2018-03-21 14:13:55 -0700131 const std::string& instanceOrPattern, bool isRegex) {
132 bool found = false;
133 bool foundOthers = false;
134 existingHal->forEachInstance([&](const auto& matrixInstance) {
135 bool interfaceMatch = matrixInstance.interface() == interface;
136 bool instanceMatch = false;
137 if (matrixInstance.isRegex() && isRegex) {
138 instanceMatch = (matrixInstance.regexPattern() == instanceOrPattern);
139 } else if (!matrixInstance.isRegex() && !isRegex) {
140 instanceMatch = (matrixInstance.exactInstance() == instanceOrPattern);
141 }
142
143 bool match = interfaceMatch && instanceMatch;
144
145 found |= match;
146 foundOthers |= (!match);
147
148 return !found || !foundOthers;
149 });
150
151 if (!found) {
Yifan Honge7e45532018-03-16 18:11:49 -0700152 return nullptr;
153 }
154
Yifan Hong643a9ef2018-03-21 14:13:55 -0700155 if (!foundOthers) {
Yifan Honge7e45532018-03-16 18:11:49 -0700156 return existingHal;
157 }
158
Yifan Hong643a9ef2018-03-21 14:13:55 -0700159 existingHal->removeInstance(interface, instanceOrPattern, isRegex);
Yifan Honge7e45532018-03-16 18:11:49 -0700160 MatrixHal copy = *existingHal;
161 copy.clearInstances();
Yifan Hong643a9ef2018-03-21 14:13:55 -0700162 copy.insertInstance(interface, instanceOrPattern, isRegex);
Yifan Honge7e45532018-03-16 18:11:49 -0700163
164 return addInternal(std::move(copy));
165}
166
Yifan Hong7967d7b2018-03-15 17:08:58 -0700167// Add all package@other_version::interface/instance as an optional instance.
168// If package@this_version::interface/instance is in this (that is, some instance
169// with the same package and interface and instance exists), then other_version is
170// considered a possible replacement to this_version.
171// See LibVintfTest.AddOptionalHal* tests for details.
Yifan Hongdbe9db32017-12-11 19:06:11 -0800172bool CompatibilityMatrix::addAllHalsAsOptional(CompatibilityMatrix* other, std::string* error) {
173 if (other == nullptr || other->level() <= level()) {
174 return true;
175 }
176
177 for (auto& pair : other->mHals) {
178 const std::string& name = pair.first;
179 MatrixHal& halToAdd = pair.second;
Yifan Hongdbe9db32017-12-11 19:06:11 -0800180
Yifan Honge7e45532018-03-16 18:11:49 -0700181 std::set<std::pair<std::string, std::string>> insertedInstances;
Yifan Hong643a9ef2018-03-21 14:13:55 -0700182 std::set<std::pair<std::string, std::string>> insertedRegex;
Yifan Honge7e45532018-03-16 18:11:49 -0700183 auto existingHals = getHals(name);
184
185 halToAdd.forEachInstance([&](const std::vector<VersionRange>& versionRanges,
Yifan Hong643a9ef2018-03-21 14:13:55 -0700186 const std::string& interface,
187 const std::string& instanceOrPattern, bool isRegex) {
Yifan Honge7e45532018-03-16 18:11:49 -0700188 for (auto* existingHal : existingHals) {
Yifan Hong643a9ef2018-03-21 14:13:55 -0700189 MatrixHal* splitInstance =
190 this->splitInstance(existingHal, interface, instanceOrPattern, isRegex);
Yifan Honge7e45532018-03-16 18:11:49 -0700191 if (splitInstance != nullptr) {
192 splitInstance->insertVersionRanges(versionRanges);
Yifan Hong643a9ef2018-03-21 14:13:55 -0700193 if (isRegex) {
194 insertedRegex.insert(std::make_pair(interface, instanceOrPattern));
195 } else {
196 insertedInstances.insert(std::make_pair(interface, instanceOrPattern));
197 }
Yifan Honge7e45532018-03-16 18:11:49 -0700198 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800199 }
Yifan Honge7e45532018-03-16 18:11:49 -0700200 return true;
201 });
202
203 // Add the remaining instances.
204 for (const auto& pair : insertedInstances) {
Yifan Hong643a9ef2018-03-21 14:13:55 -0700205 halToAdd.removeInstance(pair.first, pair.second, false /* isRegex */);
206 }
207 for (const auto& pair : insertedRegex) {
208 halToAdd.removeInstance(pair.first, pair.second, true /* isRegex */);
Yifan Hong7967d7b2018-03-15 17:08:58 -0700209 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800210
Yifan Hong7e9e04d2018-03-20 13:06:00 -0700211 if (halToAdd.instancesCount() > 0) {
Yifan Hong7967d7b2018-03-15 17:08:58 -0700212 halToAdd.setOptional(true);
213 if (!add(std::move(halToAdd))) {
214 if (error) {
215 *error = "Cannot add HAL " + name + " for unknown reason.";
Yifan Hongdbe9db32017-12-11 19:06:11 -0800216 }
217 return false;
218 }
Yifan Hongdbe9db32017-12-11 19:06:11 -0800219 }
220 }
221 return true;
222}
223
Yifan Hongd4b92fe2017-12-20 15:29:03 -0800224bool CompatibilityMatrix::addAllXmlFilesAsOptional(CompatibilityMatrix* other, std::string* error) {
225 if (other == nullptr || other->level() <= level()) {
226 return true;
227 }
228 for (auto& pair : other->mXmlFiles) {
229 const std::string& name = pair.first;
230 MatrixXmlFile& xmlFileToAdd = pair.second;
231
232 xmlFileToAdd.mOptional = true;
233 if (!addXmlFile(std::move(xmlFileToAdd))) {
234 if (error) {
235 *error = "Cannot add XML File " + name + " for unknown reason.";
236 }
237 return false;
238 }
239 }
240 return true;
241}
242
Yifan Honge7837b12018-10-11 10:38:57 -0700243// Merge Kernel.
244// Add <kernel> from exact "level", then optionally add <kernel> from high levels to low levels.
245// For example, (each letter is a kernel version x.y.z)
246// 1.xml: A1, B1
247// 2.xml: B2, C2, D2
248// 3.xml: D3, E3
249// Then the combined 1.xml should have
250// A1, B1 (from 1.xml, required), C2, D2, E3 (optional, use earliest possible).
251bool CompatibilityMatrix::addAllKernels(CompatibilityMatrix* other, std::string* error) {
252 for (MatrixKernel& kernel : other->framework.mKernels) {
253 KernelVersion ver = kernel.minLts();
254 if (!addKernel(std::move(kernel), error)) {
255 if (error) {
256 *error = "Cannot add kernel version " + to_string(ver) + ": " + *error;
257 }
258 return false;
259 }
260 }
261 return true;
262}
263
Yifan Hongd6de7f62018-04-26 18:40:02 -0700264bool CompatibilityMatrix::addAllKernelsAsOptional(CompatibilityMatrix* other, std::string* error) {
265 if (other == nullptr || other->level() <= level()) {
266 return true;
267 }
268
269 for (MatrixKernel& kernelToAdd : other->framework.mKernels) {
270 bool exists =
271 std::any_of(this->framework.mKernels.begin(), this->framework.mKernels.end(),
272 [&kernelToAdd](const MatrixKernel& existing) {
273 return kernelToAdd.minLts().version == existing.minLts().version &&
274 kernelToAdd.minLts().majorRev == existing.minLts().majorRev;
275 });
276
277 if (exists) {
278 // Shouldn't retroactively add requirements to minLts(), so ignore this.
279 // This happens even when kernelToAdd.conditions() != existing.conditions().
280 continue;
281 }
282
Yifan Hong1e8febd2019-08-07 16:17:19 -0700283 (void)kernelToAdd.setSourceMatrixLevel(other->level());
284
Yifan Hongd6de7f62018-04-26 18:40:02 -0700285 KernelVersion minLts = kernelToAdd.minLts();
Yifan Honge7837b12018-10-11 10:38:57 -0700286 if (!addKernel(std::move(kernelToAdd), error)) {
Yifan Hongd6de7f62018-04-26 18:40:02 -0700287 if (error) {
Yifan Honge7837b12018-10-11 10:38:57 -0700288 *error = "Cannot add " + to_string(minLts) + ": " + *error;
Yifan Hongd6de7f62018-04-26 18:40:02 -0700289 }
290 return false;
291 }
292 }
293 return true;
294}
295
Yifan Honge7837b12018-10-11 10:38:57 -0700296bool CompatibilityMatrix::addSepolicy(CompatibilityMatrix* other, std::string* error) {
297 bool success = mergeField(&this->framework.mSepolicy, &other->framework.mSepolicy);
298 if (!success && error) *error = "<sepolicy> is already defined";
299 return success;
300}
301
302bool CompatibilityMatrix::addAvbMetaVersion(CompatibilityMatrix* other, std::string* error) {
303 bool success = mergeField(&this->framework.mAvbMetaVersion, &other->framework.mAvbMetaVersion);
304 if (!success && error) *error = "<avb><vbmeta-version> is already defined";
305 return success;
306}
307
Yifan Hong5a51ea52019-04-22 14:54:57 -0700308bool CompatibilityMatrix::addVndk(CompatibilityMatrix* other, std::string* error) {
309#pragma clang diagnostic push
310#pragma clang diagnostic ignored "-Wdeprecated-declarations"
311 bool success = mergeField(&this->device.mVndk, &other->device.mVndk);
312#pragma clang diagnostic pop
313 if (!success && error) *error = "<vndk> is already defined";
314 return success;
315}
316
317bool CompatibilityMatrix::addVendorNdk(CompatibilityMatrix* other, std::string* error) {
318 bool success = mergeField(&this->device.mVendorNdk, &other->device.mVendorNdk);
319 if (!success && error) *error = "<vendor-ndk> is already defined";
320 return success;
321}
322
323bool CompatibilityMatrix::addSystemSdk(CompatibilityMatrix* other, std::string* /* error */) {
324 this->device.mSystemSdk.addAll(&other->device.mSystemSdk);
325 return true;
326}
327
Yifan Hongfb7469c2017-04-05 19:15:21 -0700328bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt) {
Yifan Hong2027a492017-12-11 15:21:19 -0800329 return lft.mType == rgt.mType && lft.mLevel == rgt.mLevel && lft.mHals == rgt.mHals &&
330 lft.mXmlFiles == rgt.mXmlFiles &&
Yifan Hongfeb454e2018-01-09 16:16:40 -0800331 (lft.mType != SchemaType::DEVICE ||
332 (
Yifan Hong0f529fa2018-01-10 14:51:59 -0800333#pragma clang diagnostic push
334#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Yifan Hongfeb454e2018-01-09 16:16:40 -0800335 lft.device.mVndk == rgt.device.mVndk &&
Yifan Hong0f529fa2018-01-10 14:51:59 -0800336#pragma clang diagnostic pop
Yifan Honga28729e2018-01-17 13:40:35 -0800337 lft.device.mVendorNdk == rgt.device.mVendorNdk &&
338 lft.device.mSystemSdk == rgt.device.mSystemSdk)) &&
Yifan Hongd4857902017-06-13 14:13:56 -0700339 (lft.mType != SchemaType::FRAMEWORK ||
340 (lft.framework.mKernels == rgt.framework.mKernels &&
341 lft.framework.mSepolicy == rgt.framework.mSepolicy &&
342 lft.framework.mAvbMetaVersion == rgt.framework.mAvbMetaVersion));
Yifan Hongfb7469c2017-04-05 19:15:21 -0700343}
344
Yifan Honge7837b12018-10-11 10:38:57 -0700345std::unique_ptr<CompatibilityMatrix> CompatibilityMatrix::combine(
346 Level deviceLevel, std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) {
347 // Check type.
348 for (const auto& e : *matrices) {
349 if (e.object.type() != SchemaType::FRAMEWORK) {
350 if (error) {
351 *error = "File \"" + e.name + "\" is not a framework compatibility matrix.";
352 return nullptr;
353 }
354 }
355 }
356
357 // Matrices with unspecified (empty) level are auto-filled with deviceLevel.
Yifan Hongddae77e2017-12-18 16:57:07 -0800358 for (auto& e : *matrices) {
Yifan Hongffcaf992018-01-09 17:08:51 -0800359 if (e.object.level() == Level::UNSPECIFIED) {
Yifan Honge7837b12018-10-11 10:38:57 -0700360 e.object.mLevel = deviceLevel;
Yifan Hongddae77e2017-12-18 16:57:07 -0800361 }
362 }
363
Yifan Honge7837b12018-10-11 10:38:57 -0700364 // Add from low to high FCM version so that optional <kernel> requirements are added correctly.
365 // See comment in addAllAsOptional.
366 std::sort(matrices->begin(), matrices->end(),
367 [](const auto& x, const auto& y) { return x.object.level() < y.object.level(); });
368
369 auto baseMatrix = std::make_unique<CompatibilityMatrix>();
370 baseMatrix->mLevel = deviceLevel;
371 baseMatrix->mType = SchemaType::FRAMEWORK;
372
373 std::vector<std::string> parsedFiles;
374 for (auto& e : *matrices) {
375 if (e.object.level() < deviceLevel) {
376 continue;
Yifan Hongddae77e2017-12-18 16:57:07 -0800377 }
Yifan Honge7837b12018-10-11 10:38:57 -0700378
379 bool success = false;
380 if (e.object.level() == deviceLevel) {
381 success = baseMatrix->addAll(&e, error);
382 } else {
383 success = baseMatrix->addAllAsOptional(&e, error);
384 }
385 if (!success) {
386 if (error) {
387 *error = "Conflict when merging \"" + e.name + "\": " + *error + "\n" +
388 "Previous files:\n" + base::Join(parsedFiles, "\n");
389 }
390 return nullptr;
391 }
392 parsedFiles.push_back(e.name);
Yifan Hongddae77e2017-12-18 16:57:07 -0800393 }
Yifan Honge7837b12018-10-11 10:38:57 -0700394
395 return baseMatrix;
Yifan Hongddae77e2017-12-18 16:57:07 -0800396}
397
Yifan Hong5a51ea52019-04-22 14:54:57 -0700398std::unique_ptr<CompatibilityMatrix> CompatibilityMatrix::combineDeviceMatrices(
399 std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) {
400 auto baseMatrix = std::make_unique<CompatibilityMatrix>();
401 baseMatrix->mType = SchemaType::DEVICE;
402
403 std::vector<std::string> parsedFiles;
404 for (auto& e : *matrices) {
405 bool success = baseMatrix->addAll(&e, error);
406 if (!success) {
407 if (error) {
408 *error = "Conflict when merging \"" + e.name + "\": " + *error + "\n" +
409 "Previous files:\n" + base::Join(parsedFiles, "\n");
410 }
411 return nullptr;
412 }
413 parsedFiles.push_back(e.name);
414 }
415 return baseMatrix;
416}
417
Yifan Honge7837b12018-10-11 10:38:57 -0700418bool CompatibilityMatrix::addAll(Named<CompatibilityMatrix>* inputMatrix, std::string* error) {
419 if (!addAllHals(&inputMatrix->object, error) || !addAllXmlFiles(&inputMatrix->object, error) ||
420 !addAllKernels(&inputMatrix->object, error) || !addSepolicy(&inputMatrix->object, error) ||
Yifan Hong5a51ea52019-04-22 14:54:57 -0700421 !addAvbMetaVersion(&inputMatrix->object, error) || !addVndk(&inputMatrix->object, error) ||
422 !addVendorNdk(&inputMatrix->object, error) || !addSystemSdk(&inputMatrix->object, error)) {
Yifan Honge7837b12018-10-11 10:38:57 -0700423 if (error) {
424 *error = "File \"" + inputMatrix->name + "\" cannot be added: " + *error + ".";
Yifan Hongd6de7f62018-04-26 18:40:02 -0700425 }
Yifan Hong5390e3b2019-01-31 14:13:00 -0800426 return false;
Yifan Hongd6de7f62018-04-26 18:40:02 -0700427 }
428 return true;
429}
430
Yifan Honge7837b12018-10-11 10:38:57 -0700431bool CompatibilityMatrix::addAllAsOptional(Named<CompatibilityMatrix>* inputMatrix,
432 std::string* error) {
433 if (!addAllHalsAsOptional(&inputMatrix->object, error) ||
434 !addAllXmlFilesAsOptional(&inputMatrix->object, error) ||
435 !addAllKernelsAsOptional(&inputMatrix->object, error)) {
436 if (error) {
437 *error = "File \"" + inputMatrix->name + "\" cannot be added: " + *error;
Yifan Hongddae77e2017-12-18 16:57:07 -0800438 }
Yifan Honge7837b12018-10-11 10:38:57 -0700439 return false;
Yifan Hongddae77e2017-12-18 16:57:07 -0800440 }
Yifan Honge7837b12018-10-11 10:38:57 -0700441 // ignore <sepolicy> requirement from higher level
442 // ignore <avb> requirement from higher level
443 return true;
Yifan Hongddae77e2017-12-18 16:57:07 -0800444}
445
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800446bool CompatibilityMatrix::forEachInstanceOfVersion(
447 const std::string& package, const Version& expectVersion,
448 const std::function<bool(const MatrixInstance&)>& func) const {
449 for (const MatrixHal* hal : getHals(package)) {
450 bool cont = hal->forEachInstance([&](const MatrixInstance& matrixInstance) {
451 if (matrixInstance.versionRange().contains(expectVersion)) {
452 return func(matrixInstance);
Yifan Honge3a92342018-01-25 17:00:16 -0800453 }
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800454 return true;
455 });
456 if (!cont) return false;
Yifan Honge3a92342018-01-25 17:00:16 -0800457 }
Yifan Hong2a90ffe2018-03-05 17:45:34 -0800458 return true;
Yifan Honge3a92342018-01-25 17:00:16 -0800459}
460
Yifan Hongdef7e7f2018-03-20 13:27:36 -0700461bool CompatibilityMatrix::matchInstance(const std::string& halName, const Version& version,
462 const std::string& interfaceName,
463 const std::string& instance) const {
464 bool found = false;
465 (void)forEachInstanceOfInterface(halName, version, interfaceName,
466 [&found, &instance](const auto& e) {
467 found |= (e.matchInstance(instance));
468 return !found; // if not found, continue
469 });
470 return found;
471}
472
Yifan Hong52b7fae2018-05-22 16:21:31 -0700473std::string CompatibilityMatrix::getVendorNdkVersion() const {
474 return type() == SchemaType::DEVICE ? device.mVendorNdk.version() : "";
475}
476
Yifan Hong1e8febd2019-08-07 16:17:19 -0700477Level CompatibilityMatrix::getSourceMatrixLevel(const MatrixKernel* matrixKernel) const {
478 CHECK(std::find_if(framework.mKernels.begin(), framework.mKernels.end(),
479 [matrixKernel](const auto& e) { return &e == matrixKernel; }) !=
480 framework.mKernels.end());
481 Level ret = matrixKernel->getSourceMatrixLevel();
482 if (ret != Level::UNSPECIFIED) return ret;
483 return level();
484}
485
Yifan Hong676447a2016-11-15 12:57:23 -0800486} // namespace vintf
487} // namespace android