From 71be70507de9cb619b644e55eda1cc181e3f7e90 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 12 Dec 2017 16:48:07 -0800 Subject: AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK Resources can be marked as overlayable, which means they can be overlaid by runtime resource overlays. This change propagates this state to the final resource table that is installed on device. Future work: - Have the idmap tool respect the overlayable state and ignore entries that overlay anything else. Bug: 64980941 Test: make aapt2_tests Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b --- tools/aapt2/ResourceParser_test.cpp | 45 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'tools/aapt2/ResourceParser_test.cpp') diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp index 9a5cd3edb47f..618c8ed4afd1 100644 --- a/tools/aapt2/ResourceParser_test.cpp +++ b/tools/aapt2/ResourceParser_test.cpp @@ -29,8 +29,8 @@ using ::aapt::io::StringInputStream; using ::aapt::test::StrValueEq; using ::aapt::test::ValueEq; -using ::android::ResTable_map; using ::android::Res_value; +using ::android::ResTable_map; using ::android::StringPiece; using ::testing::Eq; using ::testing::IsEmpty; @@ -38,6 +38,7 @@ using ::testing::IsNull; using ::testing::NotNull; using ::testing::Pointee; using ::testing::SizeIs; +using ::testing::StrEq; namespace aapt { @@ -482,7 +483,7 @@ TEST_F(ResourceParserTest, ParseAttributesDeclareStyleable) { Maybe result = table_.FindResource(test::ParseNameOrDie("styleable/foo")); ASSERT_TRUE(result); - EXPECT_THAT(result.value().entry->symbol_status.state, Eq(SymbolState::kPublic)); + EXPECT_THAT(result.value().entry->visibility.level, Eq(Visibility::Level::kPublic)); Attribute* attr = test::GetValue(&table_, "attr/bar"); ASSERT_THAT(attr, NotNull()); @@ -718,6 +719,26 @@ TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) { EXPECT_THAT(actual_id, Eq(ResourceId(0x01010041))); } +TEST_F(ResourceParserTest, StrongestSymbolVisibilityWins) { + std::string input = R"( + + + + + + )"; + ASSERT_TRUE(TestParse(input)); + + Maybe result = + table_.FindResource(test::ParseNameOrDie("string/foo")); + ASSERT_TRUE(result); + + ResourceEntry* entry = result.value().entry; + ASSERT_THAT(entry, NotNull()); + EXPECT_THAT(entry->visibility.level, Eq(Visibility::Level::kPublic)); + EXPECT_THAT(entry->visibility.comment, StrEq("public")); +} + TEST_F(ResourceParserTest, ExternalTypesShouldOnlyBeReferences) { ASSERT_TRUE(TestParse(R"(@layout/bar)")); ASSERT_FALSE(TestParse(R"("this is a string")")); @@ -731,8 +752,8 @@ TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) ASSERT_TRUE(result); const ResourceEntry* entry = result.value().entry; ASSERT_THAT(entry, NotNull()); - EXPECT_THAT(entry->symbol_status.state, Eq(SymbolState::kUndefined)); - EXPECT_TRUE(entry->symbol_status.allow_new); + EXPECT_THAT(entry->visibility.level, Eq(Visibility::Level::kUndefined)); + EXPECT_TRUE(entry->allow_new); } TEST_F(ResourceParserTest, ParseItemElementWithFormat) { @@ -833,6 +854,22 @@ TEST_F(ResourceParserTest, ParseOverlayableTagWithSystemPolicy) { )"; ASSERT_TRUE(TestParse(input)); + + Maybe search_result = + table_.FindResource(test::ParseNameOrDie("string/bar")); + ASSERT_TRUE(search_result); + ASSERT_THAT(search_result.value().entry, NotNull()); + EXPECT_THAT(search_result.value().entry->visibility.level, Eq(Visibility::Level::kUndefined)); + EXPECT_TRUE(search_result.value().entry->overlayable); +} + +TEST_F(ResourceParserTest, DuplicateOverlayableIsError) { + std::string input = R"( + + + + )"; + EXPECT_FALSE(TestParse(input)); } } // namespace aapt -- cgit v1.2.3