summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorInseob Kim <inseob@google.com>2020-04-07 04:07:50 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-04-07 04:07:50 +0000
commitfd544842ca78c8acfd5ab3724b3d1ab7bd45991a (patch)
tree86571ae888b3375db9af745d384d2e233dc23a32
parent6b5cdec1194e19a6f67e2ca3ee4b4ef988b6170b (diff)
parent48d4417668f0fcae61425af4e337bb1167c1fdc1 (diff)
downloadplatform_system_tools_sysprop-fd544842ca78c8acfd5ab3724b3d1ab7bd45991a.tar.gz
platform_system_tools_sysprop-fd544842ca78c8acfd5ab3724b3d1ab7bd45991a.tar.bz2
platform_system_tools_sysprop-fd544842ca78c8acfd5ab3724b3d1ab7bd45991a.zip
Add check type of legacy_prop_name am: 37116b5567 am: 48d4417668
Change-Id: I2df8d85b7d5352dae2619739a3effd1e77ec7918
-rw-r--r--TypeChecker.cpp28
-rw-r--r--tests/TypeCheckerTest.cpp9
2 files changed, 25 insertions, 12 deletions
diff --git a/TypeChecker.cpp b/TypeChecker.cpp
index 70fd395..f78e57b 100644
--- a/TypeChecker.cpp
+++ b/TypeChecker.cpp
@@ -96,17 +96,23 @@ Result<void> CheckPropertyTypes(const sysprop::SyspropLibraryApis& api,
for (auto& props : api.props()) {
for (auto& prop : props.prop()) {
- // Skip check if there is no matched property.
- auto itr = types.find(prop.prop_name());
- if (itr == types.end()) continue;
-
- if (!IsCompatible(prop, itr->second)) {
- if (!err.empty()) err += "\n";
- err += "Type of prop '" + prop.prop_name() +
- "' is incompatible with property_contexts\n";
- err += "In sysprop_library: " + GetTypeName(prop) + "\n";
- err += "In property_contexts: " + itr->second + " (should be '" +
- SyspropTypeToContextType(prop) + "')\n";
+ std::vector<std::string> prop_names{prop.prop_name()};
+ std::string legacy_name = prop.legacy_prop_name();
+ if (!legacy_name.empty()) prop_names.push_back(legacy_name);
+
+ for (auto& prop_name : prop_names) {
+ // Skip check if there is no exactly matched property.
+ auto itr = types.find(prop_name);
+ if (itr == types.end()) continue;
+
+ if (!IsCompatible(prop, itr->second)) {
+ if (!err.empty()) err += "\n";
+ err += "Type of prop '" + prop_name +
+ "' is incompatible with property_contexts\n";
+ err += "In sysprop_library: " + GetTypeName(prop) + "\n";
+ err += "In property_contexts: " + itr->second + " (should be '" +
+ SyspropTypeToContextType(prop) + "')\n";
+ }
}
}
}
diff --git a/tests/TypeCheckerTest.cpp b/tests/TypeCheckerTest.cpp
index 21d9089..ddf66a1 100644
--- a/tests/TypeCheckerTest.cpp
+++ b/tests/TypeCheckerTest.cpp
@@ -60,6 +60,7 @@ props {
scope: Public
access: Readonly
prop_name: "ro.prop4"
+ legacy_prop_name: "ro.legacy.prop4"
deprecated: true
}
@@ -72,6 +73,7 @@ prop1 u:object_r:default_prop:s0 exact int
ro.public.prop2 u:object_r:foo_prop:s0 exact enum c b a
ctl.start$prop3 u:object_r:ctl_prop:s0 exact bool
ro.prop4 u:object_r:bar_prop:s0 exact string
+ro.legacy.prop4 u:object_r:baz_prop:s0 exact string
)";
constexpr const char* kBadContexts =
@@ -80,6 +82,7 @@ prop1 u:object_r:default_prop:s0 exact double
ro.public.prop2 u:object_r:foo_prop:s0 exact enum a c
ctl.start$prop3 u:object_r:ctl_prop:s0 exact string
ro.prop4 u:object_r:bar_prop:s0 exact int
+ro.legacy.prop4 u:object_r:baz_prop:s0 exact bool
)";
} // namespace
@@ -127,5 +130,9 @@ TEST(SyspropTest, TypeCheckerTest) {
"\n"
"Type of prop 'ro.prop4' is incompatible with property_contexts\n"
"In sysprop_library: String\n"
- "In property_contexts: int (should be 'string')\n");
+ "In property_contexts: int (should be 'string')\n"
+ "\n"
+ "Type of prop 'ro.legacy.prop4' is incompatible with property_contexts\n"
+ "In sysprop_library: String\n"
+ "In property_contexts: bool (should be 'string')\n");
}