Loading tools/aapt2/format/binary/TableFlattener.cpp +17 −1 Original line number Diff line number Diff line Loading @@ -641,8 +641,24 @@ class PackageFlattener { local_key_index = (uint32_t)key_pool_.MakeRef(entry.name).index(); } else { // resource isn't exempt from collapse, add it as obfuscated value if (entry.overlayable_item) { // if the resource name of the specific entry is obfuscated and this // entry is in the overlayable list, the overlay can't work on this // overlayable at runtime because the name has been obfuscated in // resources.arsc during flatten operation. const OverlayableItem& item = entry.overlayable_item.value(); context_->GetDiagnostics()->Warn(android::DiagMessage(item.overlayable->source) << "The resource name of overlayable entry " << resource_name.to_string() << "'" << " shouldn't be obfuscated in resources.arsc"); local_key_index = (uint32_t)key_pool_.MakeRef(entry.name).index(); } else { // TODO(b/228192695): output the entry.name and Resource id to make // de-obfuscated possible. local_key_index = (uint32_t)key_pool_.MakeRef(obfuscated_resource_name).index(); } } // Group values by configuration. for (auto& config_value : entry.values) { config_to_entry_list_map[config_value->config].push_back( Loading tools/aapt2/format/binary/TableFlattener_test.cpp +48 −0 Original line number Diff line number Diff line Loading @@ -878,4 +878,52 @@ TEST_F(TableFlattenerTest, FlattenCustomResourceTypes) { Res_value::TYPE_STRING, (uint32_t)*idx, 0u)); } TEST_F(TableFlattenerTest, FlattenTypeEntryWithNameCollapseNotInExemption) { OverlayableItem overlayable_item(std::make_shared<Overlayable>("TestName", "overlay://theme")); overlayable_item.policies |= PolicyFlags::PUBLIC; std::string name = "com.app.test:color/overlayable_color"; std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() .AddValue("com.app.test:color/overlayable_color", ResourceId(0x7f010000), util::make_unique<BinaryPrimitive>(uint8_t(Res_value::TYPE_INT_COLOR_ARGB8), 0xffaabbcc)) .SetOverlayable(name, overlayable_item) .Build(); TableFlattenerOptions options; options.collapse_key_stringpool = true; ResTable res_table; EXPECT_THAT(Flatten(context_.get(), options, table.get(), &res_table), testing::IsTrue()); EXPECT_THAT(Exists(&res_table, "com.app.test:color/overlayable_color", ResourceId(0x7f010000), {}, Res_value::TYPE_INT_COLOR_ARGB8, 0xffaabbcc, 0u), testing::IsTrue()); } TEST_F(TableFlattenerTest, FlattenTypeEntryWithNameCollapseInExemption) { OverlayableItem overlayable_item(std::make_shared<Overlayable>("TestName", "overlay://theme")); overlayable_item.policies |= PolicyFlags::PUBLIC; std::string name = "com.app.test:color/overlayable_color"; std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() .AddValue("com.app.test:color/overlayable_color", ResourceId(0x7f010000), util::make_unique<BinaryPrimitive>(uint8_t(Res_value::TYPE_INT_COLOR_ARGB8), 0xffaabbcc)) .SetOverlayable(name, overlayable_item) .Build(); TableFlattenerOptions options; options.collapse_key_stringpool = true; options.name_collapse_exemptions.insert( ResourceName({}, ResourceType::kColor, "overlayable_color")); ResTable res_table; EXPECT_THAT(Flatten(context_.get(), options, table.get(), &res_table), testing::IsTrue()); EXPECT_THAT(Exists(&res_table, "com.app.test:color/overlayable_color", ResourceId(0x7f010000), {}, Res_value::TYPE_INT_COLOR_ARGB8, 0xffaabbcc, 0u), testing::IsTrue()); } } // namespace aapt Loading
tools/aapt2/format/binary/TableFlattener.cpp +17 −1 Original line number Diff line number Diff line Loading @@ -641,8 +641,24 @@ class PackageFlattener { local_key_index = (uint32_t)key_pool_.MakeRef(entry.name).index(); } else { // resource isn't exempt from collapse, add it as obfuscated value if (entry.overlayable_item) { // if the resource name of the specific entry is obfuscated and this // entry is in the overlayable list, the overlay can't work on this // overlayable at runtime because the name has been obfuscated in // resources.arsc during flatten operation. const OverlayableItem& item = entry.overlayable_item.value(); context_->GetDiagnostics()->Warn(android::DiagMessage(item.overlayable->source) << "The resource name of overlayable entry " << resource_name.to_string() << "'" << " shouldn't be obfuscated in resources.arsc"); local_key_index = (uint32_t)key_pool_.MakeRef(entry.name).index(); } else { // TODO(b/228192695): output the entry.name and Resource id to make // de-obfuscated possible. local_key_index = (uint32_t)key_pool_.MakeRef(obfuscated_resource_name).index(); } } // Group values by configuration. for (auto& config_value : entry.values) { config_to_entry_list_map[config_value->config].push_back( Loading
tools/aapt2/format/binary/TableFlattener_test.cpp +48 −0 Original line number Diff line number Diff line Loading @@ -878,4 +878,52 @@ TEST_F(TableFlattenerTest, FlattenCustomResourceTypes) { Res_value::TYPE_STRING, (uint32_t)*idx, 0u)); } TEST_F(TableFlattenerTest, FlattenTypeEntryWithNameCollapseNotInExemption) { OverlayableItem overlayable_item(std::make_shared<Overlayable>("TestName", "overlay://theme")); overlayable_item.policies |= PolicyFlags::PUBLIC; std::string name = "com.app.test:color/overlayable_color"; std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() .AddValue("com.app.test:color/overlayable_color", ResourceId(0x7f010000), util::make_unique<BinaryPrimitive>(uint8_t(Res_value::TYPE_INT_COLOR_ARGB8), 0xffaabbcc)) .SetOverlayable(name, overlayable_item) .Build(); TableFlattenerOptions options; options.collapse_key_stringpool = true; ResTable res_table; EXPECT_THAT(Flatten(context_.get(), options, table.get(), &res_table), testing::IsTrue()); EXPECT_THAT(Exists(&res_table, "com.app.test:color/overlayable_color", ResourceId(0x7f010000), {}, Res_value::TYPE_INT_COLOR_ARGB8, 0xffaabbcc, 0u), testing::IsTrue()); } TEST_F(TableFlattenerTest, FlattenTypeEntryWithNameCollapseInExemption) { OverlayableItem overlayable_item(std::make_shared<Overlayable>("TestName", "overlay://theme")); overlayable_item.policies |= PolicyFlags::PUBLIC; std::string name = "com.app.test:color/overlayable_color"; std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() .AddValue("com.app.test:color/overlayable_color", ResourceId(0x7f010000), util::make_unique<BinaryPrimitive>(uint8_t(Res_value::TYPE_INT_COLOR_ARGB8), 0xffaabbcc)) .SetOverlayable(name, overlayable_item) .Build(); TableFlattenerOptions options; options.collapse_key_stringpool = true; options.name_collapse_exemptions.insert( ResourceName({}, ResourceType::kColor, "overlayable_color")); ResTable res_table; EXPECT_THAT(Flatten(context_.get(), options, table.get(), &res_table), testing::IsTrue()); EXPECT_THAT(Exists(&res_table, "com.app.test:color/overlayable_color", ResourceId(0x7f010000), {}, Res_value::TYPE_INT_COLOR_ARGB8, 0xffaabbcc, 0u), testing::IsTrue()); } } // namespace aapt