Loading tools/aapt/AaptXml.cpp +29 −13 Original line number Diff line number Diff line Loading @@ -99,24 +99,40 @@ String8 getResolvedAttribute(const ResTable& resTable, const ResXMLTree& tree, if (idx < 0) { return String8(); } Res_value value; if (tree.getAttributeValue(idx, &value) != NO_ERROR) { if (tree.getAttributeValue(idx, &value) == BAD_TYPE) { if (outError != NULL) { *outError = "attribute value is corrupt"; } return String8(); } // Check if the string is inline in the XML. if (value.dataType == Res_value::TYPE_STRING) { size_t len; const char16_t* str = tree.getAttributeStringValue(idx, &len); return str ? String8(str, len) : String8(); } resTable.resolveReference(&value, 0); // Resolve the reference if there is one. ssize_t block = resTable.resolveReference(&value, 0); if (block < 0) { if (outError != NULL) { *outError = "attribute value reference does not exist"; } return String8(); } if (value.dataType != Res_value::TYPE_STRING) { if (outError != NULL) { *outError = "attribute is not a string value"; } return String8(); } } size_t len; const Res_value* value2 = &value; const char16_t* str = resTable.valueToString(value2, 0, NULL, &len); const char16_t* str = resTable.valueToString(&value, static_cast<size_t>(block), NULL, &len); return str ? String8(str, len) : String8(); } Loading tools/aapt2/Android.bp +5 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,9 @@ cc_library_host_static { "flatten/XmlFlattener.cpp", "io/BigBufferStreams.cpp", "io/File.cpp", "io/FileInputStream.cpp", "io/FileSystem.cpp", "io/StringInputStream.cpp", "io/Util.cpp", "io/ZipArchive.cpp", "link/AutoVersioner.cpp", Loading Loading @@ -136,7 +138,8 @@ cc_library_host_static { "xml/XmlDom.cpp", "xml/XmlPullParser.cpp", "xml/XmlUtil.cpp", "Format.proto", "Resources.proto", "ResourcesInternal.proto", ], proto: { export_proto_headers: true, Loading @@ -160,6 +163,7 @@ cc_library_host_shared { cc_test_host { name: "aapt2_tests", srcs: [ "test/Builders.cpp", "test/Common.cpp", "**/*_test.cpp", ], Loading tools/aapt2/ConfigDescription.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ static bool parseMcc(const char* name, ResTable_config* out) { static bool parseMnc(const char* name, ResTable_config* out) { if (strcmp(name, kWildcardName) == 0) { if (out) out->mcc = 0; if (out) out->mnc = 0; return true; } const char* c = name; Loading Loading @@ -967,8 +967,6 @@ bool ConfigDescription::ConflictsWith(const ConfigDescription& o) const { o.screenLayout & MASK_LAYOUTDIR) || !pred(screenLayout & MASK_SCREENLONG, o.screenLayout & MASK_SCREENLONG) || !pred(screenLayout & MASK_UI_MODE_TYPE, o.screenLayout & MASK_UI_MODE_TYPE) || !pred(uiMode & MASK_UI_MODE_TYPE, o.uiMode & MASK_UI_MODE_TYPE) || !pred(uiMode & MASK_UI_MODE_NIGHT, o.uiMode & MASK_UI_MODE_NIGHT) || !pred(screenLayout2 & MASK_SCREENROUND, Loading tools/aapt2/ConfigDescription_test.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -140,4 +140,16 @@ TEST(ConfigDescriptionTest, ParseVrAttribute) { EXPECT_EQ(std::string("vrheadset-v26"), config.toString().string()); } TEST(ConfigDescriptionTest, RangeQualifiersDoNotConflict) { using test::ParseConfigOrDie; EXPECT_FALSE(ParseConfigOrDie("large").ConflictsWith(ParseConfigOrDie("normal-land"))); EXPECT_FALSE(ParseConfigOrDie("long-hdpi").ConflictsWith(ParseConfigOrDie("xhdpi"))); EXPECT_FALSE(ParseConfigOrDie("sw600dp").ConflictsWith(ParseConfigOrDie("sw700dp"))); EXPECT_FALSE(ParseConfigOrDie("v11").ConflictsWith(ParseConfigOrDie("v21"))); EXPECT_FALSE(ParseConfigOrDie("h600dp").ConflictsWith(ParseConfigOrDie("h300dp"))); EXPECT_FALSE(ParseConfigOrDie("w400dp").ConflictsWith(ParseConfigOrDie("w300dp"))); EXPECT_FALSE(ParseConfigOrDie("600x400").ConflictsWith(ParseConfigOrDie("300x200"))); } } // namespace aapt tools/aapt2/Debug.cpp +31 −33 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ namespace aapt { namespace { class PrintVisitor : public ValueVisitor { public: using ValueVisitor::Visit; Loading Loading @@ -88,9 +90,13 @@ class PrintVisitor : public ValueVisitor { } } void Visit(Array* array) override { array->Print(&std::cout); } void Visit(Array* array) override { array->Print(&std::cout); } void Visit(Plural* plural) override { plural->Print(&std::cout); } void Visit(Plural* plural) override { plural->Print(&std::cout); } void Visit(Styleable* styleable) override { std::cout << "(styleable)"; Loading @@ -110,11 +116,14 @@ class PrintVisitor : public ValueVisitor { } } void VisitItem(Item* item) override { item->Print(&std::cout); } void VisitItem(Item* item) override { item->Print(&std::cout); } }; void Debug::PrintTable(ResourceTable* table, const DebugPrintTableOptions& options) { } // namespace void Debug::PrintTable(ResourceTable* table, const DebugPrintTableOptions& options) { PrintVisitor visitor; for (auto& package : table->packages) { Loading Loading @@ -148,10 +157,9 @@ void Debug::PrintTable(ResourceTable* table, } for (const ResourceEntry* entry : sorted_entries) { ResourceId id(package->id ? package->id.value() : uint8_t(0), type->id ? type->id.value() : uint8_t(0), entry->id ? entry->id.value() : uint16_t(0)); ResourceName name(package->name, type->type, entry->name); const ResourceId id(package->id.value_or_default(0), type->id.value_or_default(0), entry->id.value_or_default(0)); const ResourceName name(package->name, type->type, entry->name); std::cout << " spec resource " << id << " " << name; switch (entry->symbol_status.state) { Loading Loading @@ -180,16 +188,14 @@ void Debug::PrintTable(ResourceTable* table, } } static size_t GetNodeIndex(const std::vector<ResourceName>& names, const ResourceName& name) { static size_t GetNodeIndex(const std::vector<ResourceName>& names, const ResourceName& name) { auto iter = std::lower_bound(names.begin(), names.end(), name); CHECK(iter != names.end()); CHECK(*iter == name); return std::distance(names.begin(), iter); } void Debug::PrintStyleGraph(ResourceTable* table, const ResourceName& target_style) { void Debug::PrintStyleGraph(ResourceTable* table, const ResourceName& target_style) { std::map<ResourceName, std::set<ResourceName>> graph; std::queue<ResourceName> styles_to_visit; Loading Loading @@ -223,8 +229,7 @@ void Debug::PrintStyleGraph(ResourceTable* table, std::cout << "digraph styles {\n"; for (const auto& name : names) { std::cout << " node_" << GetNodeIndex(names, name) << " [label=\"" << name << "\"];\n"; std::cout << " node_" << GetNodeIndex(names, name) << " [label=\"" << name << "\"];\n"; } for (const auto& entry : graph) { Loading @@ -243,8 +248,7 @@ void Debug::PrintStyleGraph(ResourceTable* table, void Debug::DumpHex(const void* data, size_t len) { const uint8_t* d = (const uint8_t*)data; for (size_t i = 0; i < len; i++) { std::cerr << std::hex << std::setfill('0') << std::setw(2) << (uint32_t)d[i] << " "; std::cerr << std::hex << std::setfill('0') << std::setw(2) << (uint32_t)d[i] << " "; if (i % 8 == 7) { std::cerr << "\n"; } Loading @@ -262,8 +266,15 @@ class XmlPrinter : public xml::Visitor { using xml::Visitor::Visit; void Visit(xml::Element* el) override { std::cerr << prefix_; std::cerr << "E: "; const size_t previous_size = prefix_.size(); for (const xml::NamespaceDecl& decl : el->namespace_decls) { std::cerr << prefix_ << "N: " << decl.prefix << "=" << decl.uri << " (line=" << decl.line_number << ")\n"; prefix_ += " "; } std::cerr << prefix_ << "E: "; if (!el->namespace_uri.empty()) { std::cerr << el->namespace_uri << ":"; } Loading @@ -283,26 +294,13 @@ class XmlPrinter : public xml::Visitor { std::cerr << "=" << attr.value << "\n"; } const size_t previous_size = prefix_.size(); prefix_ += " "; xml::Visitor::Visit(el); prefix_.resize(previous_size); } void Visit(xml::Namespace* ns) override { std::cerr << prefix_; std::cerr << "N: " << ns->namespace_prefix << "=" << ns->namespace_uri << " (line=" << ns->line_number << ")\n"; const size_t previous_size = prefix_.size(); prefix_ += " "; xml::Visitor::Visit(ns); prefix_.resize(previous_size); } void Visit(xml::Text* text) override { std::cerr << prefix_; std::cerr << "T: '" << text->text << "'\n"; std::cerr << prefix_ << "T: '" << text->text << "'\n"; } private: Loading Loading
tools/aapt/AaptXml.cpp +29 −13 Original line number Diff line number Diff line Loading @@ -99,24 +99,40 @@ String8 getResolvedAttribute(const ResTable& resTable, const ResXMLTree& tree, if (idx < 0) { return String8(); } Res_value value; if (tree.getAttributeValue(idx, &value) != NO_ERROR) { if (tree.getAttributeValue(idx, &value) == BAD_TYPE) { if (outError != NULL) { *outError = "attribute value is corrupt"; } return String8(); } // Check if the string is inline in the XML. if (value.dataType == Res_value::TYPE_STRING) { size_t len; const char16_t* str = tree.getAttributeStringValue(idx, &len); return str ? String8(str, len) : String8(); } resTable.resolveReference(&value, 0); // Resolve the reference if there is one. ssize_t block = resTable.resolveReference(&value, 0); if (block < 0) { if (outError != NULL) { *outError = "attribute value reference does not exist"; } return String8(); } if (value.dataType != Res_value::TYPE_STRING) { if (outError != NULL) { *outError = "attribute is not a string value"; } return String8(); } } size_t len; const Res_value* value2 = &value; const char16_t* str = resTable.valueToString(value2, 0, NULL, &len); const char16_t* str = resTable.valueToString(&value, static_cast<size_t>(block), NULL, &len); return str ? String8(str, len) : String8(); } Loading
tools/aapt2/Android.bp +5 −1 Original line number Diff line number Diff line Loading @@ -88,7 +88,9 @@ cc_library_host_static { "flatten/XmlFlattener.cpp", "io/BigBufferStreams.cpp", "io/File.cpp", "io/FileInputStream.cpp", "io/FileSystem.cpp", "io/StringInputStream.cpp", "io/Util.cpp", "io/ZipArchive.cpp", "link/AutoVersioner.cpp", Loading Loading @@ -136,7 +138,8 @@ cc_library_host_static { "xml/XmlDom.cpp", "xml/XmlPullParser.cpp", "xml/XmlUtil.cpp", "Format.proto", "Resources.proto", "ResourcesInternal.proto", ], proto: { export_proto_headers: true, Loading @@ -160,6 +163,7 @@ cc_library_host_shared { cc_test_host { name: "aapt2_tests", srcs: [ "test/Builders.cpp", "test/Common.cpp", "**/*_test.cpp", ], Loading
tools/aapt2/ConfigDescription.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ static bool parseMcc(const char* name, ResTable_config* out) { static bool parseMnc(const char* name, ResTable_config* out) { if (strcmp(name, kWildcardName) == 0) { if (out) out->mcc = 0; if (out) out->mnc = 0; return true; } const char* c = name; Loading Loading @@ -967,8 +967,6 @@ bool ConfigDescription::ConflictsWith(const ConfigDescription& o) const { o.screenLayout & MASK_LAYOUTDIR) || !pred(screenLayout & MASK_SCREENLONG, o.screenLayout & MASK_SCREENLONG) || !pred(screenLayout & MASK_UI_MODE_TYPE, o.screenLayout & MASK_UI_MODE_TYPE) || !pred(uiMode & MASK_UI_MODE_TYPE, o.uiMode & MASK_UI_MODE_TYPE) || !pred(uiMode & MASK_UI_MODE_NIGHT, o.uiMode & MASK_UI_MODE_NIGHT) || !pred(screenLayout2 & MASK_SCREENROUND, Loading
tools/aapt2/ConfigDescription_test.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -140,4 +140,16 @@ TEST(ConfigDescriptionTest, ParseVrAttribute) { EXPECT_EQ(std::string("vrheadset-v26"), config.toString().string()); } TEST(ConfigDescriptionTest, RangeQualifiersDoNotConflict) { using test::ParseConfigOrDie; EXPECT_FALSE(ParseConfigOrDie("large").ConflictsWith(ParseConfigOrDie("normal-land"))); EXPECT_FALSE(ParseConfigOrDie("long-hdpi").ConflictsWith(ParseConfigOrDie("xhdpi"))); EXPECT_FALSE(ParseConfigOrDie("sw600dp").ConflictsWith(ParseConfigOrDie("sw700dp"))); EXPECT_FALSE(ParseConfigOrDie("v11").ConflictsWith(ParseConfigOrDie("v21"))); EXPECT_FALSE(ParseConfigOrDie("h600dp").ConflictsWith(ParseConfigOrDie("h300dp"))); EXPECT_FALSE(ParseConfigOrDie("w400dp").ConflictsWith(ParseConfigOrDie("w300dp"))); EXPECT_FALSE(ParseConfigOrDie("600x400").ConflictsWith(ParseConfigOrDie("300x200"))); } } // namespace aapt
tools/aapt2/Debug.cpp +31 −33 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ namespace aapt { namespace { class PrintVisitor : public ValueVisitor { public: using ValueVisitor::Visit; Loading Loading @@ -88,9 +90,13 @@ class PrintVisitor : public ValueVisitor { } } void Visit(Array* array) override { array->Print(&std::cout); } void Visit(Array* array) override { array->Print(&std::cout); } void Visit(Plural* plural) override { plural->Print(&std::cout); } void Visit(Plural* plural) override { plural->Print(&std::cout); } void Visit(Styleable* styleable) override { std::cout << "(styleable)"; Loading @@ -110,11 +116,14 @@ class PrintVisitor : public ValueVisitor { } } void VisitItem(Item* item) override { item->Print(&std::cout); } void VisitItem(Item* item) override { item->Print(&std::cout); } }; void Debug::PrintTable(ResourceTable* table, const DebugPrintTableOptions& options) { } // namespace void Debug::PrintTable(ResourceTable* table, const DebugPrintTableOptions& options) { PrintVisitor visitor; for (auto& package : table->packages) { Loading Loading @@ -148,10 +157,9 @@ void Debug::PrintTable(ResourceTable* table, } for (const ResourceEntry* entry : sorted_entries) { ResourceId id(package->id ? package->id.value() : uint8_t(0), type->id ? type->id.value() : uint8_t(0), entry->id ? entry->id.value() : uint16_t(0)); ResourceName name(package->name, type->type, entry->name); const ResourceId id(package->id.value_or_default(0), type->id.value_or_default(0), entry->id.value_or_default(0)); const ResourceName name(package->name, type->type, entry->name); std::cout << " spec resource " << id << " " << name; switch (entry->symbol_status.state) { Loading Loading @@ -180,16 +188,14 @@ void Debug::PrintTable(ResourceTable* table, } } static size_t GetNodeIndex(const std::vector<ResourceName>& names, const ResourceName& name) { static size_t GetNodeIndex(const std::vector<ResourceName>& names, const ResourceName& name) { auto iter = std::lower_bound(names.begin(), names.end(), name); CHECK(iter != names.end()); CHECK(*iter == name); return std::distance(names.begin(), iter); } void Debug::PrintStyleGraph(ResourceTable* table, const ResourceName& target_style) { void Debug::PrintStyleGraph(ResourceTable* table, const ResourceName& target_style) { std::map<ResourceName, std::set<ResourceName>> graph; std::queue<ResourceName> styles_to_visit; Loading Loading @@ -223,8 +229,7 @@ void Debug::PrintStyleGraph(ResourceTable* table, std::cout << "digraph styles {\n"; for (const auto& name : names) { std::cout << " node_" << GetNodeIndex(names, name) << " [label=\"" << name << "\"];\n"; std::cout << " node_" << GetNodeIndex(names, name) << " [label=\"" << name << "\"];\n"; } for (const auto& entry : graph) { Loading @@ -243,8 +248,7 @@ void Debug::PrintStyleGraph(ResourceTable* table, void Debug::DumpHex(const void* data, size_t len) { const uint8_t* d = (const uint8_t*)data; for (size_t i = 0; i < len; i++) { std::cerr << std::hex << std::setfill('0') << std::setw(2) << (uint32_t)d[i] << " "; std::cerr << std::hex << std::setfill('0') << std::setw(2) << (uint32_t)d[i] << " "; if (i % 8 == 7) { std::cerr << "\n"; } Loading @@ -262,8 +266,15 @@ class XmlPrinter : public xml::Visitor { using xml::Visitor::Visit; void Visit(xml::Element* el) override { std::cerr << prefix_; std::cerr << "E: "; const size_t previous_size = prefix_.size(); for (const xml::NamespaceDecl& decl : el->namespace_decls) { std::cerr << prefix_ << "N: " << decl.prefix << "=" << decl.uri << " (line=" << decl.line_number << ")\n"; prefix_ += " "; } std::cerr << prefix_ << "E: "; if (!el->namespace_uri.empty()) { std::cerr << el->namespace_uri << ":"; } Loading @@ -283,26 +294,13 @@ class XmlPrinter : public xml::Visitor { std::cerr << "=" << attr.value << "\n"; } const size_t previous_size = prefix_.size(); prefix_ += " "; xml::Visitor::Visit(el); prefix_.resize(previous_size); } void Visit(xml::Namespace* ns) override { std::cerr << prefix_; std::cerr << "N: " << ns->namespace_prefix << "=" << ns->namespace_uri << " (line=" << ns->line_number << ")\n"; const size_t previous_size = prefix_.size(); prefix_ += " "; xml::Visitor::Visit(ns); prefix_.resize(previous_size); } void Visit(xml::Text* text) override { std::cerr << prefix_; std::cerr << "T: '" << text->text << "'\n"; std::cerr << prefix_ << "T: '" << text->text << "'\n"; } private: Loading