summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeremy Meyer <jakmcbane@google.com> 2024-07-17 14:57:33 -0700
committer Jeremy Meyer <jakmcbane@google.com> 2024-07-22 09:59:50 -0700
commitefa42b1e27efc2ff8cb39cf47141f9d59ca6d375 (patch)
treef8f1bae2acac7e3173d5f69dbca939965bebc1a3
parentd659822b0642f0994bcdd517ca900c4202050b8b (diff)
Dont parse resource values behind disabled flags
This change makes it so that when we are parsing resources and there is one behind a disabled flag we don't parse the value. This is primarily to prevent disabled strings from ending up in the string pool. Test: automated Bug: 329436914 Flag: EXEMPT Aconfig not supported on host tools Change-Id: I4d8683ac820a3fd20cd92c223464f912b0ac422d
-rw-r--r--tools/aapt2/ResourceParser.cpp4
-rw-r--r--tools/aapt2/ResourceParser_test.cpp22
2 files changed, 23 insertions, 3 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index 2df941834063..45bf8e38c5ce 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -690,7 +690,9 @@ bool ResourceParser::ParseResource(xml::XmlPullParser* parser,
resource_format = item_iter->second.format;
}
- if (!ParseItem(parser, out_resource, resource_format)) {
+ // Don't bother parsing the item if it is behind a disabled flag
+ if (out_resource->flag_status != FlagStatus::Disabled &&
+ !ParseItem(parser, out_resource, resource_format)) {
return false;
}
return true;
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index b59b16574c42..2e6ad13d99de 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -69,8 +69,13 @@ class ResourceParserTest : public ::testing::Test {
return TestParse(str, ConfigDescription{});
}
- ::testing::AssertionResult TestParse(StringPiece str, const ConfigDescription& config) {
- ResourceParserOptions parserOptions;
+ ::testing::AssertionResult TestParse(StringPiece str, ResourceParserOptions parserOptions) {
+ return TestParse(str, ConfigDescription{}, parserOptions);
+ }
+
+ ::testing::AssertionResult TestParse(
+ StringPiece str, const ConfigDescription& config,
+ ResourceParserOptions parserOptions = ResourceParserOptions()) {
ResourceParser parser(context_->GetDiagnostics(), &table_, android::Source{"test"}, config,
parserOptions);
@@ -242,6 +247,19 @@ TEST_F(ResourceParserTest, ParseStringTranslatableAttribute) {
EXPECT_FALSE(TestParse(R"(<string name="foo4" translatable="yes">Translate</string>)"));
}
+TEST_F(ResourceParserTest, ParseStringBehindDisabledFlag) {
+ FeatureFlagProperties flag_properties(true, false);
+ ResourceParserOptions options;
+ options.feature_flag_values = {{"falseFlag", flag_properties}};
+ ASSERT_TRUE(TestParse(
+ R"(<string name="foo" android:featureFlag="falseFlag"
+ xmlns:android="http://schemas.android.com/apk/res/android">foo</string>)",
+ options));
+
+ String* str = test::GetValue<String>(&table_, "string/foo");
+ ASSERT_THAT(str, IsNull());
+}
+
TEST_F(ResourceParserTest, IgnoreXliffTagsOtherThanG) {
std::string input = R"(
<string name="foo" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">