Do not allow first <kernel> version to have non-empty <condition>.
Stating <condition> on a <kernel> tag in fwk compat mat means
the fragment is conditionally used. Older libvintf (libvintf on
O devices) use the first <kernel> tag with a match version
unconditionally. Disable this to allow old libvintf to parse
the requirements more correctly. In detail:
* O libvintf may still falsely accept incompatible fwk comp mat, because
it only looks at the first <kernel> element. The conditional
requirements are not checked.
* O libvintf does not falsely reject a compatible fwk comp mat.
Conditional requirements are never the first <kernel> element and hence
are not checked by O libvintf.
This is a workaround solution for backwards compatibility, since
O has been released.
Test: libvintf_test
Bug: 64124223
Change-Id: I20a9bb768720fc83ac5cdf293a976cb279cb6eab
Merged-In: I20a9bb768720fc83ac5cdf293a976cb279cb6eab
diff --git a/parse_xml.cpp b/parse_xml.cpp
index f56e01a..259fd4e 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -887,6 +887,21 @@
!parseOptionalChild(root, avbConverter, {}, &object->framework.mAvbMetaVersion)) {
return false;
}
+
+ std::set<Version> seenKernelVersions;
+ for (const auto& kernel : object->framework.mKernels) {
+ Version minLts(kernel.minLts().version, kernel.minLts().majorRev);
+ if (seenKernelVersions.find(minLts) != seenKernelVersions.end()) {
+ continue;
+ }
+ if (!kernel.conditions().empty()) {
+ this->mLastError = "First <kernel> for version " + to_string(minLts) +
+ " must have empty <conditions> for backwards compatibility.";
+ return false;
+ }
+ seenKernelVersions.insert(minLts);
+ }
+
} else if (object->mType == SchemaType::DEVICE) {
// <vndk> can be missing because it can be determined at build time, not hard-coded
// in the XML file.