From f53a027bfa9820821be0fdd51faec51ddedf381f Mon Sep 17 00:00:00 2001 From: Jeremy Meyer Date: Thu, 19 Sep 2024 09:47:47 -0700 Subject: Add flag support to styles elements Test: Automated Bug: 329436914 Flag: EXEMPT Aconfig not supported on host tools Change-Id: I3041ebbaf98a90527809b541df8885edfc70d035 --- tools/aapt2/ResourceParser.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'tools/aapt2/ResourceParser.cpp') 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 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; } -- cgit v1.2.3-59-g8ed1b