Add VintfObject::getCompatibleKernelRequirement
Fixes: 139015688
Test: vintf_object_test
Test: libvintf_test
Change-Id: I31d5ac319bc61bd340dbc1196dbfc3107f6be101
diff --git a/KernelInfo.cpp b/KernelInfo.cpp
index 1a37bdf..4f3215e 100644
--- a/KernelInfo.cpp
+++ b/KernelInfo.cpp
@@ -60,10 +60,10 @@
minLts.minorRev <= mVersion.minorRev;
}
-bool KernelInfo::matchKernelRequirements(const std::vector<MatrixKernel>& kernels,
- std::string* error) const {
+std::vector<const MatrixKernel*> KernelInfo::getMatchedKernelRequirements(
+ const std::vector<MatrixKernel>& kernels, std::string* error) const {
+ std::vector<const MatrixKernel*> result;
bool foundMatchedKernelVersion = false;
- bool foundMatchedConditions = false;
for (const MatrixKernel& matrixKernel : kernels) {
if (!matchKernelVersion(matrixKernel.minLts())) {
continue;
@@ -73,10 +73,10 @@
if (!matchKernelConfigs(matrixKernel.conditions(), error)) {
continue;
}
- foundMatchedConditions = true;
if (!matchKernelConfigs(matrixKernel.configs(), error)) {
- return false;
+ return {};
}
+ result.push_back(&matrixKernel);
}
if (!foundMatchedKernelVersion) {
if (error != nullptr) {
@@ -86,20 +86,21 @@
for (const MatrixKernel& matrixKernel : kernels) ss << " " << matrixKernel.minLts();
*error = ss.str();
}
- return false;
+ return {};
}
- if (!foundMatchedConditions) {
+ if (result.empty()) {
+ // This means matchKernelVersion passes but matchKernelConfigs(conditions) fails.
// This should not happen because first <conditions> for each <kernel> must be
// empty. Reject here for inconsistency.
if (error != nullptr) {
error->insert(0, "Framework match kernel version with unmet conditions:");
}
- return false;
+ return {};
}
if (error != nullptr) {
error->clear();
}
- return true;
+ return result;
}
bool KernelInfo::operator==(const KernelInfo& other) const {