Add support for flagging xml and png files
This extends the previous change that added the ability to flag resource
directories so that xml and png files are now supported.
Test: Automated
Bug: 329436914
Flag: EXEMPT Aconfig not supported on host tools
Change-Id: I9f2b6b15ba0078ea33188f1a554377784cff9786
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index a2383ac..fce6aa7 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -547,7 +547,7 @@
});
std::string_view resource_type = parser->element_name();
- if (auto flag = GetFlag(parser)) {
+ if (auto flag = ParseFlag(xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag"))) {
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");
@@ -747,22 +747,6 @@
return false;
}
-std::optional<FeatureFlagAttribute> ResourceParser::GetFlag(xml::XmlPullParser* parser) {
- auto name = xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag");
- if (name) {
- FeatureFlagAttribute flag;
- if (name->starts_with('!')) {
- flag.negated = true;
- flag.name = name->substr(1);
- } else {
- flag.name = name.value();
- }
- return flag;
- } else {
- return {};
- }
-}
-
bool ResourceParser::ParseItem(xml::XmlPullParser* parser,
ParsedResource* out_resource,
const uint32_t format) {
@@ -1669,7 +1653,7 @@
const std::string& element_namespace = parser->element_namespace();
const std::string& element_name = parser->element_name();
if (element_namespace.empty() && element_name == "item") {
- auto flag = GetFlag(parser);
+ auto flag = ParseFlag(xml::FindAttribute(parser, xml::kSchemaAndroid, "featureFlag"));
std::unique_ptr<Item> item = ParseXml(parser, typeMask, kNoRawString);
if (!item) {
diag_->Error(android::DiagMessage(item_source) << "could not parse array item");