Loading libs/androidfw/include/androidfw/StringPiece.h +8 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,14 @@ namespace android { // WARNING: When creating from std::basic_string<>, moving the original // std::basic_string<> will invalidate the data held in a BasicStringPiece<>. // BasicStringPiece<> should only be used transitively. // // NOTE: When creating an std::pair<StringPiece, T> using std::make_pair(), // passing an std::string will first copy the string, then create a StringPiece // on the copy, which is then immediately destroyed. // Instead, create a StringPiece explicitly: // // std::string my_string = "foo"; // std::make_pair<StringPiece, T>(StringPiece(my_string), ...); template <typename TChar> class BasicStringPiece { public: Loading tools/aapt2/java/JavaClassGenerator.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -347,7 +347,9 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res } // Add the Styleable array to the Styleable class. if (out_class_def != nullptr) { out_class_def->AddMember(std::move(array_def)); } // Now we emit the indices into the array. for (size_t i = 0; i < attr_count; i++) { Loading Loading @@ -578,7 +580,6 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, if (out_r_txt != nullptr) { r_txt_printer = util::make_unique<Printer>(out_r_txt); } // Generate an onResourcesLoaded() callback if requested. if (out != nullptr && options_.rewrite_callback_options) { rewrite_method = Loading tools/aapt2/java/JavaClassGenerator_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -438,4 +438,22 @@ TEST(JavaClassGeneratorTest, GenerateOnResourcesLoadedCallbackForSharedLibrary) EXPECT_THAT(output, HasSubstr("com.boo.R.onResourcesLoaded")); } TEST(JavaClassGeneratorTest, OnlyGenerateRText) { std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() .SetPackageId("android", 0x01) .AddValue("android:attr/foo", ResourceId(0x01010000), util::make_unique<Attribute>()) .AddValue("android:styleable/hey.dude", ResourceId(0x01020000), test::StyleableBuilder() .AddItem("android:attr/foo", ResourceId(0x01010000)) .Build()) .Build(); std::unique_ptr<IAaptContext> context = test::ContextBuilder().SetPackageId(0x01).SetCompilationPackage("android").Build(); JavaClassGenerator generator(context.get(), table.get(), {}); ASSERT_TRUE(generator.Generate("android", nullptr)); } } // namespace aapt Loading
libs/androidfw/include/androidfw/StringPiece.h +8 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,14 @@ namespace android { // WARNING: When creating from std::basic_string<>, moving the original // std::basic_string<> will invalidate the data held in a BasicStringPiece<>. // BasicStringPiece<> should only be used transitively. // // NOTE: When creating an std::pair<StringPiece, T> using std::make_pair(), // passing an std::string will first copy the string, then create a StringPiece // on the copy, which is then immediately destroyed. // Instead, create a StringPiece explicitly: // // std::string my_string = "foo"; // std::make_pair<StringPiece, T>(StringPiece(my_string), ...); template <typename TChar> class BasicStringPiece { public: Loading
tools/aapt2/java/JavaClassGenerator.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -347,7 +347,9 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res } // Add the Styleable array to the Styleable class. if (out_class_def != nullptr) { out_class_def->AddMember(std::move(array_def)); } // Now we emit the indices into the array. for (size_t i = 0; i < attr_count; i++) { Loading Loading @@ -578,7 +580,6 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate, if (out_r_txt != nullptr) { r_txt_printer = util::make_unique<Printer>(out_r_txt); } // Generate an onResourcesLoaded() callback if requested. if (out != nullptr && options_.rewrite_callback_options) { rewrite_method = Loading
tools/aapt2/java/JavaClassGenerator_test.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -438,4 +438,22 @@ TEST(JavaClassGeneratorTest, GenerateOnResourcesLoadedCallbackForSharedLibrary) EXPECT_THAT(output, HasSubstr("com.boo.R.onResourcesLoaded")); } TEST(JavaClassGeneratorTest, OnlyGenerateRText) { std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() .SetPackageId("android", 0x01) .AddValue("android:attr/foo", ResourceId(0x01010000), util::make_unique<Attribute>()) .AddValue("android:styleable/hey.dude", ResourceId(0x01020000), test::StyleableBuilder() .AddItem("android:attr/foo", ResourceId(0x01010000)) .Build()) .Build(); std::unique_ptr<IAaptContext> context = test::ContextBuilder().SetPackageId(0x01).SetCompilationPackage("android").Build(); JavaClassGenerator generator(context.get(), table.get(), {}); ASSERT_TRUE(generator.Generate("android", nullptr)); } } // namespace aapt