summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2017-08-23 14:56:31 -0500
committerYifan Hong2017-08-24 12:16:02 -0500
commitd3650ea0db3fe82fb5f85a1012697cc272625847 (patch)
tree61b82c495b47adebf2790210afdd006ffe4e2170
parentee8bc5e17a95c1abb4587550f61dc32790d1df51 (diff)
downloadplatform-system-libvintf-d3650ea0db3fe82fb5f85a1012697cc272625847.tar.gz
platform-system-libvintf-d3650ea0db3fe82fb5f85a1012697cc272625847.tar.xz
platform-system-libvintf-d3650ea0db3fe82fb5f85a1012697cc272625847.zip
Match /proc/config.gz with fwk comp mat <kernel> fragments
Multiple <kernel> elements with the same version can exist. The <condition> element decides whether the <kernel> element is actually used during matching. Test: libvintf_test Bug: 64124223 Change-Id: I0dd28b8b1bdfe06a4da61aaa81df91f4df5fcf26 Merged-In: I0dd28b8b1bdfe06a4da61aaa81df91f4df5fcf26
-rw-r--r--RuntimeInfo.cpp90
-rw-r--r--include/vintf/MatrixKernel.h3
-rw-r--r--include/vintf/RuntimeInfo.h10
3 files changed, 78 insertions, 25 deletions
diff --git a/RuntimeInfo.cpp b/RuntimeInfo.cpp
index b29a146..0bcb363 100644
--- a/RuntimeInfo.cpp
+++ b/RuntimeInfo.cpp
@@ -69,6 +69,38 @@ const Version &RuntimeInfo::bootAvbVersion() const {
69 return mBootAvbVersion; 69 return mBootAvbVersion;
70} 70}
71 71
72bool RuntimeInfo::matchKernelConfigs(const std::vector<KernelConfig>& matrixConfigs,
73 std::string* error) const {
74 for (const KernelConfig& matrixConfig : matrixConfigs) {
75 const std::string& key = matrixConfig.first;
76 auto it = this->mKernelConfigs.find(key);
77 if (it == this->mKernelConfigs.end()) {
78 // special case: <value type="tristate">n</value> matches if the config doesn't exist.
79 if (matrixConfig.second == KernelConfigTypedValue::gMissingConfig) {
80 continue;
81 }
82 if (error != nullptr) {
83 *error = "Missing config " + key;
84 }
85 return false;
86 }
87 const std::string& kernelValue = it->second;
88 if (!matrixConfig.second.matchValue(kernelValue)) {
89 if (error != nullptr) {
90 *error = "For config " + key + ", value = " + kernelValue + " but required " +
91 to_string(matrixConfig.second);
92 }
93 return false;
94 }
95 }
96 return true;
97}
98
99bool RuntimeInfo::matchKernelVersion(const KernelVersion& minLts) const {
100 return minLts.version == mKernelVersion.version && minLts.majorRev == mKernelVersion.majorRev &&
101 minLts.minorRev <= mKernelVersion.minorRev;
102}
103
72bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat, 104bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
73 std::string *error) const { 105 std::string *error) const {
74 if (mat.mType != SchemaType::FRAMEWORK) { 106 if (mat.mType != SchemaType::FRAMEWORK) {
@@ -86,36 +118,46 @@ bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
86 return false; 118 return false;
87 } 119 }
88 120
89 // mat.mSepolicy.sepolicyVersion() is checked against static HalManifest.device.mSepolicyVersion 121 // mat.mSepolicy.sepolicyVersion() is checked against static
122 // HalManifest.device.mSepolicyVersion in HalManifest::checkCompatibility.
90 123
91 const MatrixKernel *matrixKernel = mat.findKernel(this->mKernelVersion); 124 bool foundMatchedKernelVersion = false;
92 if (matrixKernel == nullptr) { 125 bool foundMatchedConditions = false;
126 for (const MatrixKernel& matrixKernel : mat.framework.mKernels) {
127 if (!matchKernelVersion(matrixKernel.minLts())) {
128 continue;
129 }
130 foundMatchedKernelVersion = true;
131 // ignore this fragment if not all conditions are met.
132 if (!matchKernelConfigs(matrixKernel.conditions(), error)) {
133 continue;
134 }
135 foundMatchedConditions = true;
136 if (!matchKernelConfigs(matrixKernel.configs(), error)) {
137 return false;
138 }
139 }
140 if (!foundMatchedKernelVersion) {
93 if (error != nullptr) { 141 if (error != nullptr) {
94 *error = "Cannot find suitable kernel entry for " + to_string(mKernelVersion); 142 std::stringstream ss;
143 ss << "Framework is incompatible with kernel version " << mKernelVersion
144 << ", compatible kernel versions are";
145 for (const MatrixKernel& matrixKernel : mat.framework.mKernels)
146 ss << " " << matrixKernel.minLts();
147 *error = ss.str();
95 } 148 }
96 return false; 149 return false;
97 } 150 }
98 for (const KernelConfig &matrixConfig : matrixKernel->configs()) { 151 if (!foundMatchedConditions) {
99 const std::string &key = matrixConfig.first; 152 // This should not happen because first <conditions> for each <kernel> must be
100 auto it = this->mKernelConfigs.find(key); 153 // empty. Reject here for inconsistency.
101 if (it == this->mKernelConfigs.end()) { 154 if (error != nullptr) {
102 // special case: <value type="tristate">n</value> matches if the config doesn't exist. 155 error->insert(0, "Framework match kernel version with unmet conditions:");
103 if (matrixConfig.second == KernelConfigTypedValue::gMissingConfig) {
104 continue;
105 }
106 if (error != nullptr) {
107 *error = "Missing config " + key;
108 }
109 return false;
110 }
111 const std::string &kernelValue = it->second;
112 if (!matrixConfig.second.matchValue(kernelValue)) {
113 if (error != nullptr) {
114 *error = "For config " + key + ", value = " + kernelValue
115 + " but required " + to_string(matrixConfig.second);
116 }
117 return false;
118 } 156 }
157 return false;
158 }
159 if (error != nullptr) {
160 error->clear();
119 } 161 }
120 162
121 const Version &matAvb = mat.framework.mAvbMetaVersion; 163 const Version &matAvb = mat.framework.mAvbMetaVersion;
diff --git a/include/vintf/MatrixKernel.h b/include/vintf/MatrixKernel.h
index a2fa7c9..f0990a8 100644
--- a/include/vintf/MatrixKernel.h
+++ b/include/vintf/MatrixKernel.h
@@ -35,7 +35,8 @@ struct KernelConfigKey : public std::string {
35 35
36using KernelConfig = std::pair<KernelConfigKey, KernelConfigTypedValue>; 36using KernelConfig = std::pair<KernelConfigKey, KernelConfigTypedValue>;
37 37
38// A kernel entry to a compatibility matrix 38// A <kernel> entry to a compatibility matrix represents a fragment of kernel
39// config requirements.
39struct MatrixKernel { 40struct MatrixKernel {
40 41
41 MatrixKernel() {} 42 MatrixKernel() {}
diff --git a/include/vintf/RuntimeInfo.h b/include/vintf/RuntimeInfo.h
index 4e34f64..6b510fb 100644
--- a/include/vintf/RuntimeInfo.h
+++ b/include/vintf/RuntimeInfo.h
@@ -25,6 +25,9 @@
25 25
26#include <utils/Errors.h> 26#include <utils/Errors.h>
27 27
28#include "MatrixKernel.h"
29#include "Version.h"
30
28namespace android { 31namespace android {
29namespace vintf { 32namespace vintf {
30 33
@@ -79,6 +82,13 @@ private:
79 82
80 status_t fetchAllInformation(); 83 status_t fetchAllInformation();
81 84
85 // mKernelVersion = x'.y'.z', minLts = x.y.z,
86 // match if x == x' , y == y' , and z <= z'.
87 bool matchKernelVersion(const KernelVersion& minLts) const;
88 // return true if all kernel configs in matrixConfigs matches.
89 bool matchKernelConfigs(const std::vector<KernelConfig>& matrixConfigs,
90 std::string* error = nullptr) const;
91
82 // /proc/config.gz 92 // /proc/config.gz
83 // Key: CONFIG_xxx; Value: the value after = sign. 93 // Key: CONFIG_xxx; Value: the value after = sign.
84 std::map<std::string, std::string> mKernelConfigs; 94 std::map<std::string, std::string> mKernelConfigs;