summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser.cpp
diff options
context:
space:
mode:
author Jeremy Meyer <jakmcbane@google.com> 2024-09-30 21:35:59 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-09-30 21:35:59 +0000
commitdb6bcea4d6b8fbf4361bc83c6a0c433ddc6ac095 (patch)
tree9c69eaaf744df9da30892f31e9bd8a4978c597d0 /tools/aapt2/ResourceParser.cpp
parent173284d5abbfeb42d8ba51f883c7e66076a3f06b (diff)
parentf53a027bfa9820821be0fdd51faec51ddedf381f (diff)
Merge "Add flag support to styles elements" into main
Diffstat (limited to 'tools/aapt2/ResourceParser.cpp')
-rw-r--r--tools/aapt2/ResourceParser.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index fce6aa7c80d9..da092f43caa4 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -1529,13 +1529,34 @@ bool ResourceParser::ParseStyleItem(xml::XmlPullParser* parser, Style* style) {
ResolvePackage(parser, &maybe_key.value());
maybe_key.value().SetSource(source);
+ auto flag = ParseFlag(xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag"));
+
std::unique_ptr<Item> value = ParseXml(parser, 0, kAllowRawString);
if (!value) {
diag_->Error(android::DiagMessage(source) << "could not parse style item");
return false;
}
- style->entries.push_back(Style::Entry{std::move(maybe_key.value()), std::move(value)});
+ if (flag) {
+ if (options_.flag) {
+ diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number()))
+ << "Resource flag are not allowed both in the path and in the file");
+ return false;
+ }
+ std::string error;
+ auto flag_status = GetFlagStatus(flag, options_.feature_flag_values, &error);
+ if (flag_status) {
+ value->SetFlagStatus(flag_status.value());
+ value->SetFlag(std::move(flag));
+ } else {
+ diag_->Error(android::DiagMessage(source_.WithLine(parser->line_number())) << error);
+ return false;
+ }
+ }
+
+ if (value->GetFlagStatus() != FlagStatus::Disabled) {
+ style->entries.push_back(Style::Entry{std::move(maybe_key.value()), std::move(value)});
+ }
return true;
}