summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2017-09-11 16:38:46 -0500
committerYifan Hong2017-09-11 17:00:56 -0500
commit66444507bb258a895059544855be2f47cc523f1c (patch)
tree072a0e4a74da9f2b63e53d2fc64f294210742c6c
parentbfbbdeac0982c3c3851075fe000fe626a2bb54bf (diff)
downloadplatform-system-libvintf-66444507bb258a895059544855be2f47cc523f1c.tar.gz
platform-system-libvintf-66444507bb258a895059544855be2f47cc523f1c.tar.xz
platform-system-libvintf-66444507bb258a895059544855be2f47cc523f1c.zip
Allow to disable certain checks in VintfObject::CheckCompatibility
Allow to disable AVB version checks. Test: builds Test: vintf_object_test Test: libvintf_test Bug: 38325029 Bug: 65270190 Change-Id: Iadc2408f635a5487a5af4e19f516147930f4bc4b Merged-In: Iadc2408f635a5487a5af4e19f516147930f4bc4b
-rw-r--r--RuntimeInfo.cpp41
-rw-r--r--VintfObject.cpp17
-rw-r--r--include/vintf/DisabledChecks.h33
-rw-r--r--include/vintf/RuntimeInfo.h8
-rw-r--r--include/vintf/VintfObject.h15
-rw-r--r--test/main.cpp25
6 files changed, 98 insertions, 41 deletions
diff --git a/RuntimeInfo.cpp b/RuntimeInfo.cpp
index 0bcb363..b343138 100644
--- a/RuntimeInfo.cpp
+++ b/RuntimeInfo.cpp
@@ -101,8 +101,8 @@ bool RuntimeInfo::matchKernelVersion(const KernelVersion& minLts) const {
101 minLts.minorRev <= mKernelVersion.minorRev; 101 minLts.minorRev <= mKernelVersion.minorRev;
102} 102}
103 103
104bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat, 104bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix& mat, std::string* error,
105 std::string *error) const { 105 DisabledChecks disabledChecks) const {
106 if (mat.mType != SchemaType::FRAMEWORK) { 106 if (mat.mType != SchemaType::FRAMEWORK) {
107 if (error != nullptr) { 107 if (error != nullptr) {
108 *error = "Should not check runtime info against " + to_string(mat.mType) 108 *error = "Should not check runtime info against " + to_string(mat.mType)
@@ -160,25 +160,28 @@ bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
160 error->clear(); 160 error->clear();
161 } 161 }
162 162
163 const Version &matAvb = mat.framework.mAvbMetaVersion; 163 if ((disabledChecks & DISABLE_AVB_CHECK) == 0) {
164 if (mBootAvbVersion.majorVer != matAvb.majorVer || mBootAvbVersion.minorVer < matAvb.minorVer) { 164 const Version& matAvb = mat.framework.mAvbMetaVersion;
165 if (error != nullptr) { 165 if (mBootAvbVersion.majorVer != matAvb.majorVer ||
166 std::stringstream ss; 166 mBootAvbVersion.minorVer < matAvb.minorVer) {
167 ss << "AVB version " << mBootAvbVersion << " does not match framework matrix " 167 if (error != nullptr) {
168 << matAvb; 168 std::stringstream ss;
169 *error = ss.str(); 169 ss << "AVB version " << mBootAvbVersion << " does not match framework matrix "
170 << matAvb;
171 *error = ss.str();
172 }
173 return false;
170 } 174 }
171 return false; 175 if (mBootVbmetaAvbVersion.majorVer != matAvb.majorVer ||
172 } 176 mBootVbmetaAvbVersion.minorVer < matAvb.minorVer) {
173 if (mBootVbmetaAvbVersion.majorVer != matAvb.majorVer || 177 if (error != nullptr) {
174 mBootVbmetaAvbVersion.minorVer < matAvb.minorVer) { 178 std::stringstream ss;
175 if (error != nullptr) { 179 ss << "Vbmeta version " << mBootVbmetaAvbVersion
176 std::stringstream ss; 180 << " does not match framework matrix " << matAvb;
177 ss << "Vbmeta version " << mBootVbmetaAvbVersion << " does not match framework matrix " 181 *error = ss.str();
178 << matAvb; 182 }
179 *error = ss.str(); 183 return false;
180 } 184 }
181 return false;
182 } 185 }
183 186
184 return true; 187 return true;
diff --git a/VintfObject.cpp b/VintfObject.cpp
index f785e6b..d441245 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -172,9 +172,9 @@ struct UpdatedInfo {
172// Checks given compatibility info against info on the device. If no 172// Checks given compatibility info against info on the device. If no
173// compatability info is given then the device info will be checked against 173// compatability info is given then the device info will be checked against
174// itself. 174// itself.
175int32_t checkCompatibility(const std::vector<std::string> &xmls, bool mount, 175int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount,
176 const PartitionMounter &mounter, std::string *error) { 176 const PartitionMounter& mounter, std::string* error,
177 177 DisabledChecks disabledChecks) {
178 status_t status; 178 status_t status;
179 ParseStatus parseStatus; 179 ParseStatus parseStatus;
180 PackageInfo pkg; // All information from package. 180 PackageInfo pkg; // All information from package.
@@ -277,7 +277,7 @@ int32_t checkCompatibility(const std::vector<std::string> &xmls, bool mount,
277 } 277 }
278 } 278 }
279 if (updated.runtimeInfo && updated.fwk.matrix) { 279 if (updated.runtimeInfo && updated.fwk.matrix) {
280 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error)) { 280 if (!updated.runtimeInfo->checkCompatibility(*updated.fwk.matrix, error, disabledChecks)) {
281 if (error) 281 if (error)
282 error->insert(0, "Runtime info and framework compatibility matrix " 282 error->insert(0, "Runtime info and framework compatibility matrix "
283 "are incompatible: "); 283 "are incompatible: ");
@@ -291,11 +291,10 @@ int32_t checkCompatibility(const std::vector<std::string> &xmls, bool mount,
291} // namespace details 291} // namespace details
292 292
293// static 293// static
294int32_t VintfObject::CheckCompatibility( 294int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
295 const std::vector<std::string> &xmls, std::string *error) { 295 DisabledChecks disabledChecks) {
296 return details::checkCompatibility(xmls, false /* mount */, 296 return details::checkCompatibility(xmls, false /* mount */, *details::gPartitionMounter, error,
297 *details::gPartitionMounter, 297 disabledChecks);
298 error);
299} 298}
300 299
301 300
diff --git a/include/vintf/DisabledChecks.h b/include/vintf/DisabledChecks.h
new file mode 100644
index 0000000..09f49a3
--- /dev/null
+++ b/include/vintf/DisabledChecks.h
@@ -0,0 +1,33 @@
1/*
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#ifndef ANDROID_VINTF_DISABLED_CHECKS_H_
18#define ANDROID_VINTF_DISABLED_CHECKS_H_
19
20namespace android {
21namespace vintf {
22
23// Flags for *::checkCompatibility functions.
24enum DisabledChecks : int32_t {
25 ENABLE_ALL_CHECKS = 0,
26 // Disable AVB version check in RuntimeInfo::checkCompatibility
27 DISABLE_AVB_CHECK = 1 << 0,
28};
29
30} // namespace vintf
31} // namespace android
32
33#endif // ANDROID_VINTF_DISABLED_CHECKS_H_
diff --git a/include/vintf/RuntimeInfo.h b/include/vintf/RuntimeInfo.h
index 6b510fb..1505c15 100644
--- a/include/vintf/RuntimeInfo.h
+++ b/include/vintf/RuntimeInfo.h
@@ -25,6 +25,7 @@
25 25
26#include <utils/Errors.h> 26#include <utils/Errors.h>
27 27
28#include "DisabledChecks.h"
28#include "MatrixKernel.h" 29#include "MatrixKernel.h"
29#include "Version.h" 30#include "Version.h"
30 31
@@ -70,11 +71,10 @@ struct RuntimeInfo {
70 // RuntimeInfo object is created (the first time VintfObject::GetRuntimeInfo is called), 71 // RuntimeInfo object is created (the first time VintfObject::GetRuntimeInfo is called),
71 // not when RuntimeInfo::checkCompatibility is called. 72 // not when RuntimeInfo::checkCompatibility is called.
72 // - avb-vbmetaversion matches related sysprops 73 // - avb-vbmetaversion matches related sysprops
73 bool checkCompatibility(const CompatibilityMatrix &mat, 74 bool checkCompatibility(const CompatibilityMatrix& mat, std::string* error = nullptr,
74 std::string *error = nullptr) const; 75 DisabledChecks disabledChecks = ENABLE_ALL_CHECKS) const;
75
76private:
77 76
77 private:
78 friend struct RuntimeInfoFetcher; 78 friend struct RuntimeInfoFetcher;
79 friend class VintfObject; 79 friend class VintfObject;
80 friend struct LibVintfTest; 80 friend struct LibVintfTest;
diff --git a/include/vintf/VintfObject.h b/include/vintf/VintfObject.h
index 9d5cc6f..e4dbe7c 100644
--- a/include/vintf/VintfObject.h
+++ b/include/vintf/VintfObject.h
@@ -18,6 +18,7 @@
18#define ANDROID_VINTF_VINTF_OBJECT_H_ 18#define ANDROID_VINTF_VINTF_OBJECT_H_
19 19
20#include "CompatibilityMatrix.h" 20#include "CompatibilityMatrix.h"
21#include "DisabledChecks.h"
21#include "HalManifest.h" 22#include "HalManifest.h"
22#include "RuntimeInfo.h" 23#include "RuntimeInfo.h"
23 24
@@ -84,14 +85,16 @@ public:
84 * 85 *
85 * @param packageInfo a list of XMLs of HalManifest / 86 * @param packageInfo a list of XMLs of HalManifest /
86 * CompatibilityMatrix objects. 87 * CompatibilityMatrix objects.
88 * @param error error message
89 * @param disabledChecks flags to disable certain checks. See DisabledChecks.
87 * 90 *
88 * @return = 0 if success (compatible) 91 * @return = 0 if success (compatible)
89 * > 0 if incompatible 92 * > 0 if incompatible
90 * < 0 if any error (mount partition fails, illformed XML, etc.) 93 * < 0 if any error (mount partition fails, illformed XML, etc.)
91 */ 94 */
92 static int32_t CheckCompatibility( 95 static int32_t CheckCompatibility(const std::vector<std::string>& packageInfo,
93 const std::vector<std::string> &packageInfo, 96 std::string* error = nullptr,
94 std::string *error = nullptr); 97 DisabledChecks disabledChecks = ENABLE_ALL_CHECKS);
95}; 98};
96 99
97enum : int32_t { 100enum : int32_t {
@@ -102,9 +105,9 @@ enum : int32_t {
102// exposed for testing and VintfObjectRecovery. 105// exposed for testing and VintfObjectRecovery.
103namespace details { 106namespace details {
104class PartitionMounter; 107class PartitionMounter;
105int32_t checkCompatibility(const std::vector<std::string> &xmls, bool mount, 108int32_t checkCompatibility(const std::vector<std::string>& xmls, bool mount,
106 const PartitionMounter& partitionMounter, 109 const PartitionMounter& partitionMounter, std::string* error,
107 std::string *error); 110 DisabledChecks disabledChecks = ENABLE_ALL_CHECKS);
108} // namespace details 111} // namespace details
109 112
110} // namespace vintf 113} // namespace vintf
diff --git a/test/main.cpp b/test/main.cpp
index 94a4d8e..495b35c 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -771,8 +771,7 @@ TEST_F(LibVintfTest, RuntimeInfo) {
771 CompatibilityMatrix cm = testMatrix(std::move(kernel)); 771 CompatibilityMatrix cm = testMatrix(std::move(kernel));
772 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for integer"; 772 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for integer";
773 } 773 }
774// TODO(b/38325029) enable avb check when avb version is injected to fwk matrix. 774
775#if 0
776 RuntimeInfo badAvb = testRuntimeInfo(); 775 RuntimeInfo badAvb = testRuntimeInfo();
777 CompatibilityMatrix cm = testMatrix(MatrixKernel(KernelVersion{3, 18, 31}, {})); 776 CompatibilityMatrix cm = testMatrix(MatrixKernel(KernelVersion{3, 18, 31}, {}));
778 { 777 {
@@ -792,7 +791,6 @@ TEST_F(LibVintfTest, RuntimeInfo) {
792 setAvb(badAvb, {2, 3}, {2, 1}); 791 setAvb(badAvb, {2, 3}, {2, 1});
793 EXPECT_TRUE(badAvb.checkCompatibility(cm, &error)); 792 EXPECT_TRUE(badAvb.checkCompatibility(cm, &error));
794 } 793 }
795#endif
796} 794}
797 795
798TEST_F(LibVintfTest, MissingAvb) { 796TEST_F(LibVintfTest, MissingAvb) {
@@ -809,6 +807,27 @@ TEST_F(LibVintfTest, MissingAvb) {
809 EXPECT_EQ(getAvb(cm), Version(0, 0)); 807 EXPECT_EQ(getAvb(cm), Version(0, 0));
810} 808}
811 809
810TEST_F(LibVintfTest, DisableAvb) {
811 std::string xml =
812 "<compatibility-matrix version=\"1.0\" type=\"framework\">\n"
813 " <kernel version=\"3.18.31\"></kernel>"
814 " <sepolicy>\n"
815 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
816 " <sepolicy-version>25.5</sepolicy-version>\n"
817 " </sepolicy>\n"
818 " <avb>\n"
819 " <vbmeta-version>1.0</vbmeta-version>\n"
820 " </avb>\n"
821 "</compatibility-matrix>\n";
822 CompatibilityMatrix cm;
823 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml));
824 RuntimeInfo ki = testRuntimeInfo();
825 std::string error;
826 EXPECT_FALSE(ki.checkCompatibility(cm, &error));
827 EXPECT_STREQ(error.c_str(), "AVB version 2.1 does not match framework matrix 1.0");
828 EXPECT_TRUE(ki.checkCompatibility(cm, &error, DISABLE_AVB_CHECK)) << error;
829}
830
812// This is the test extracted from VINTF Object doc 831// This is the test extracted from VINTF Object doc
813TEST_F(LibVintfTest, HalCompat) { 832TEST_F(LibVintfTest, HalCompat) {
814 CompatibilityMatrix matrix; 833 CompatibilityMatrix matrix;