From acde95c3fc7739ef7b7447be7fd4c087d1575039 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 23 Apr 2019 05:44:21 -0700 Subject: [PATCH] No new attributes in declare-styleables when format is not provided AAPT does not allow for attributes declared in declare-styleables that do not have a format to create new attribute resources. AAPT2 does and should not. Bug: 131100106 Test: aapt2_tests Change-Id: Id00884dc9ed939672df90f670a7915d4b6d232c1 --- tools/aapt2/ResourceParser.cpp | 9 ++++++++- tools/aapt2/ResourceParser_test.cpp | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index fe401e22c50e1..c291b395d94b6 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -1712,7 +1712,14 @@ bool ResourceParser::ParseDeclareStyleable(xml::XmlPullParser* parser, child_ref.SetSource(item_source); styleable->entries.push_back(std::move(child_ref)); - out_resource->child_resources.push_back(std::move(child_resource)); + // Do not add referenced attributes that do not define a format to the table. + CHECK(child_resource.value != nullptr); + Attribute* attr = ValueCast(child_resource.value.get()); + + CHECK(attr != nullptr); + if (attr->type_mask != android::ResTable_map::TYPE_ANY) { + out_resource->child_resources.push_back(std::move(child_resource)); + } } else if (!ShouldIgnoreElement(element_namespace, element_name)) { diag_->Error(DiagMessage(item_source) << "unknown tag <" diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp index 7c8b6d054cd52..464225fefb857 100644 --- a/tools/aapt2/ResourceParser_test.cpp +++ b/tools/aapt2/ResourceParser_test.cpp @@ -341,7 +341,7 @@ TEST_F(ResourceParserTest, ParseAttrAndDeclareStyleableUnderConfigButRecordAsNoC std::string input = R"( - + )"; ASSERT_TRUE(TestParse(input, watch_config)); @@ -589,8 +589,7 @@ TEST_F(ResourceParserTest, ParseAttributesDeclareStyleable) { EXPECT_THAT(result.value().entry->visibility.level, Eq(Visibility::Level::kPublic)); Attribute* attr = test::GetValue(&table_, "attr/bar"); - ASSERT_THAT(attr, NotNull()); - EXPECT_TRUE(attr->IsWeak()); + ASSERT_THAT(attr, IsNull()); attr = test::GetValue(&table_, "attr/bat"); ASSERT_THAT(attr, NotNull());