123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include "KernelInfo.h"
- #include "parse_string.h"
- namespace android {
- namespace vintf {
- const KernelVersion& KernelInfo::version() const {
- return mVersion;
- }
- const std::map<std::string, std::string>& KernelInfo::configs() const {
- return mConfigs;
- }
- bool KernelInfo::matchKernelConfigs(const std::vector<KernelConfig>& matrixConfigs,
- std::string* error) const {
- for (const KernelConfig& matrixConfig : matrixConfigs) {
- const std::string& key = matrixConfig.first;
- auto it = this->mConfigs.find(key);
- if (it == this->mConfigs.end()) {
-
- if (matrixConfig.second == KernelConfigTypedValue::gMissingConfig) {
- continue;
- }
- if (error != nullptr) {
- *error = "Missing config " + key;
- }
- return false;
- }
- const std::string& kernelValue = it->second;
- if (!matrixConfig.second.matchValue(kernelValue)) {
- if (error != nullptr) {
- *error = "For config " + key + ", value = " + kernelValue + " but required " +
- to_string(matrixConfig.second);
- }
- return false;
- }
- }
- return true;
- }
- bool KernelInfo::matchKernelVersion(const KernelVersion& minLts) const {
- return minLts.version == mVersion.version && minLts.majorRev == mVersion.majorRev &&
- minLts.minorRev <= mVersion.minorRev;
- }
- bool KernelInfo::matchKernelRequirements(const std::vector<MatrixKernel>& kernels,
- std::string* error) const {
- bool foundMatchedKernelVersion = false;
- bool foundMatchedConditions = false;
- for (const MatrixKernel& matrixKernel : kernels) {
- if (!matchKernelVersion(matrixKernel.minLts())) {
- continue;
- }
- foundMatchedKernelVersion = true;
-
- if (!matchKernelConfigs(matrixKernel.conditions(), error)) {
- continue;
- }
- foundMatchedConditions = true;
- if (!matchKernelConfigs(matrixKernel.configs(), error)) {
- return false;
- }
- }
- if (!foundMatchedKernelVersion) {
- if (error != nullptr) {
- std::stringstream ss;
- ss << "Framework is incompatible with kernel version " << version()
- << ", compatible kernel versions are";
- for (const MatrixKernel& matrixKernel : kernels) ss << " " << matrixKernel.minLts();
- *error = ss.str();
- }
- return false;
- }
- if (!foundMatchedConditions) {
-
-
- if (error != nullptr) {
- error->insert(0, "Framework match kernel version with unmet conditions:");
- }
- return false;
- }
- if (error != nullptr) {
- error->clear();
- }
- return true;
- }
- bool KernelInfo::operator==(const KernelInfo& other) const {
- return mVersion == other.mVersion && mConfigs == other.mConfigs;
- }
- }
- }
|