Loading tools/aapt2/BinaryResourceParser.cpp +22 −2 Original line number Diff line number Diff line Loading @@ -116,9 +116,11 @@ private: BinaryResourceParser::BinaryResourceParser(const std::shared_ptr<ResourceTable>& table, const std::shared_ptr<IResolver>& resolver, const Source& source, const std::u16string& defaultPackage, const void* data, size_t len) : mTable(table), mResolver(resolver), mSource(source), mData(data), mDataLen(len) { mTable(table), mResolver(resolver), mSource(source), mDefaultPackage(defaultPackage), mData(data), mDataLen(len) { } bool BinaryResourceParser::parse() { Loading Loading @@ -177,6 +179,9 @@ bool BinaryResourceParser::getSymbol(const void* data, ResourceNameRef* outSymbo if (!type) { return false; } if (outSymbol->package.empty()) { outSymbol->package = mTable->getPackage(); } outSymbol->type = *type; // Since we scan the symbol table in order, we can start looking for the Loading Loading @@ -350,7 +355,22 @@ bool BinaryResourceParser::parsePackage(const ResChunk_header* chunk) { size_t len = strnlen16(reinterpret_cast<const char16_t*>(packageHeader->name), sizeof(packageHeader->name) / sizeof(packageHeader->name[0])); mTable->setPackage(StringPiece16(reinterpret_cast<const char16_t*>(packageHeader->name), len)); if (mTable->getPackage().empty() && len == 0) { mTable->setPackage(mDefaultPackage); } else if (len > 0) { StringPiece16 thisPackage(reinterpret_cast<const char16_t*>(packageHeader->name), len); if (mTable->getPackage().empty()) { mTable->setPackage(thisPackage); } else if (thisPackage != mTable->getPackage()) { Logger::error(mSource) << "incompatible packages: " << mTable->getPackage() << " vs. " << thisPackage << std::endl; return false; } } ResChunkPullParser parser(getChunkData(packageHeader->header), getChunkDataLen(packageHeader->header)); Loading tools/aapt2/BinaryResourceParser.h +4 −3 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public: BinaryResourceParser(const std::shared_ptr<ResourceTable>& table, const std::shared_ptr<IResolver>& resolver, const Source& source, const std::u16string& defaultPackage, const void* data, size_t len); BinaryResourceParser(const BinaryResourceParser&) = delete; // No copy. Loading Loading @@ -97,12 +98,12 @@ private: const Source mSource; // The package name of the resource table. std::u16string mDefaultPackage; const void* mData; const size_t mDataLen; // The package name of the resource table. std::u16string mPackage; // The array of symbol entries. Each element points to an offset // in the table and an index into the symbol table string pool. const SymbolTable_entry* mSymbolEntries = nullptr; Loading tools/aapt2/Linker.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ const Attribute* Linker::doResolveAttribute(Reference& attribute, const SourceLi void Linker::visit(Reference& reference, ValueVisitorArgs& a) { Args& args = static_cast<Args&>(a); if (!reference.name.isValid()) { if (reference.name.entry.empty()) { // We can't have a completely bad reference. if (!reference.id.isValid()) { Logger::error() << "srsly? " << args.referrer << std::endl; Loading tools/aapt2/Main.cpp +44 −46 Original line number Diff line number Diff line Loading @@ -756,8 +756,8 @@ bool link(const AaptOptions& options, const std::shared_ptr<ResourceTable>& outT zipFile->uncompress(entry)); assert(uncompressedData); BinaryResourceParser parser(table, resolver, source, uncompressedData.get(), entry->getUncompressedLen()); BinaryResourceParser parser(table, resolver, source, options.appInfo.package, uncompressedData.get(), entry->getUncompressedLen()); if (!parser.parse()) { return false; } Loading Loading @@ -1085,14 +1085,7 @@ static AaptOptions prepareArgs(int argc, char** argv) { } bool isStaticLib = false; if (options.phase == AaptOptions::Phase::Compile || options.phase == AaptOptions::Phase::Link) { if (options.phase == AaptOptions::Phase::Compile) { flag::requiredFlag("--package", "Android package name", [&options](const StringPiece& arg) { options.appInfo.package = util::utf8ToUtf16(arg); }); } else if (options.phase == AaptOptions::Phase::Link) { if (options.phase == AaptOptions::Phase::Link) { flag::requiredFlag("--manifest", "AndroidManifest.xml of your app", [&options](const StringPiece& arg) { options.manifest = Source{ arg.toString() }; Loading Loading @@ -1124,11 +1117,15 @@ static AaptOptions prepareArgs(int argc, char** argv) { false, &options.versionStylesAndLayouts); } if (options.phase == AaptOptions::Phase::Compile || options.phase == AaptOptions::Phase::Link) { // Common flags for all steps. flag::requiredFlag("-o", "Output path", [&options](const StringPiece& arg) { options.output = Source{ arg.toString() }; }); } else if (options.phase == AaptOptions::Phase::DumpStyleGraph) { } if (options.phase == AaptOptions::Phase::DumpStyleGraph) { flag::requiredFlag("--style", "Name of the style to dump", [&options](const StringPiece& arg, std::string* outError) -> bool { Reference styleReference; Loading Loading @@ -1191,7 +1188,7 @@ static bool doDump(const AaptOptions& options) { zipFile->uncompress(entry)); assert(uncompressedData); BinaryResourceParser parser(table, resolver, source, uncompressedData.get(), BinaryResourceParser parser(table, resolver, source, {}, uncompressedData.get(), entry->getUncompressedLen()); if (!parser.parse()) { return false; Loading Loading @@ -1223,16 +1220,17 @@ int main(int argc, char** argv) { if (!loadAppInfo(options.manifest, &options.appInfo)) { return false; } } // Verify we have some common options set. if (options.appInfo.package.empty()) { Logger::error() << "no package name specified." << std::endl; return false; } } // Every phase needs a resource table. std::shared_ptr<ResourceTable> table = std::make_shared<ResourceTable>(); // The package name is empty when in the compile phase. table->setPackage(options.appInfo.package); if (options.appInfo.package == u"android") { table->setPackageId(0x01); Loading tools/aapt2/TableFlattener.cpp +1 −8 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ public: // Write the key. if (!Res_INTERNALID(key.id.id) && !key.id.isValid()) { assert(key.name.isValid()); assert(!key.name.entry.empty()); mSymbols->push_back(std::make_pair(ResourceNameRef(key.name), mOut->size() - sizeof(*outMapEntry))); } Loading Loading @@ -284,13 +284,6 @@ bool TableFlattener::flattenValue(BigBuffer* out, const FlatEntry& flatEntry, bool TableFlattener::flatten(BigBuffer* out, const ResourceTable& table) { const size_t beginning = out->size(); if (table.getPackage().size() == 0) { Logger::error() << "ResourceTable has no package name." << std::endl; return false; } if (table.getPackageId() == ResourceTable::kUnsetPackageId) { Logger::error() << "ResourceTable has no package ID set." Loading Loading
tools/aapt2/BinaryResourceParser.cpp +22 −2 Original line number Diff line number Diff line Loading @@ -116,9 +116,11 @@ private: BinaryResourceParser::BinaryResourceParser(const std::shared_ptr<ResourceTable>& table, const std::shared_ptr<IResolver>& resolver, const Source& source, const std::u16string& defaultPackage, const void* data, size_t len) : mTable(table), mResolver(resolver), mSource(source), mData(data), mDataLen(len) { mTable(table), mResolver(resolver), mSource(source), mDefaultPackage(defaultPackage), mData(data), mDataLen(len) { } bool BinaryResourceParser::parse() { Loading Loading @@ -177,6 +179,9 @@ bool BinaryResourceParser::getSymbol(const void* data, ResourceNameRef* outSymbo if (!type) { return false; } if (outSymbol->package.empty()) { outSymbol->package = mTable->getPackage(); } outSymbol->type = *type; // Since we scan the symbol table in order, we can start looking for the Loading Loading @@ -350,7 +355,22 @@ bool BinaryResourceParser::parsePackage(const ResChunk_header* chunk) { size_t len = strnlen16(reinterpret_cast<const char16_t*>(packageHeader->name), sizeof(packageHeader->name) / sizeof(packageHeader->name[0])); mTable->setPackage(StringPiece16(reinterpret_cast<const char16_t*>(packageHeader->name), len)); if (mTable->getPackage().empty() && len == 0) { mTable->setPackage(mDefaultPackage); } else if (len > 0) { StringPiece16 thisPackage(reinterpret_cast<const char16_t*>(packageHeader->name), len); if (mTable->getPackage().empty()) { mTable->setPackage(thisPackage); } else if (thisPackage != mTable->getPackage()) { Logger::error(mSource) << "incompatible packages: " << mTable->getPackage() << " vs. " << thisPackage << std::endl; return false; } } ResChunkPullParser parser(getChunkData(packageHeader->header), getChunkDataLen(packageHeader->header)); Loading
tools/aapt2/BinaryResourceParser.h +4 −3 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public: BinaryResourceParser(const std::shared_ptr<ResourceTable>& table, const std::shared_ptr<IResolver>& resolver, const Source& source, const std::u16string& defaultPackage, const void* data, size_t len); BinaryResourceParser(const BinaryResourceParser&) = delete; // No copy. Loading Loading @@ -97,12 +98,12 @@ private: const Source mSource; // The package name of the resource table. std::u16string mDefaultPackage; const void* mData; const size_t mDataLen; // The package name of the resource table. std::u16string mPackage; // The array of symbol entries. Each element points to an offset // in the table and an index into the symbol table string pool. const SymbolTable_entry* mSymbolEntries = nullptr; Loading
tools/aapt2/Linker.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ const Attribute* Linker::doResolveAttribute(Reference& attribute, const SourceLi void Linker::visit(Reference& reference, ValueVisitorArgs& a) { Args& args = static_cast<Args&>(a); if (!reference.name.isValid()) { if (reference.name.entry.empty()) { // We can't have a completely bad reference. if (!reference.id.isValid()) { Logger::error() << "srsly? " << args.referrer << std::endl; Loading
tools/aapt2/Main.cpp +44 −46 Original line number Diff line number Diff line Loading @@ -756,8 +756,8 @@ bool link(const AaptOptions& options, const std::shared_ptr<ResourceTable>& outT zipFile->uncompress(entry)); assert(uncompressedData); BinaryResourceParser parser(table, resolver, source, uncompressedData.get(), entry->getUncompressedLen()); BinaryResourceParser parser(table, resolver, source, options.appInfo.package, uncompressedData.get(), entry->getUncompressedLen()); if (!parser.parse()) { return false; } Loading Loading @@ -1085,14 +1085,7 @@ static AaptOptions prepareArgs(int argc, char** argv) { } bool isStaticLib = false; if (options.phase == AaptOptions::Phase::Compile || options.phase == AaptOptions::Phase::Link) { if (options.phase == AaptOptions::Phase::Compile) { flag::requiredFlag("--package", "Android package name", [&options](const StringPiece& arg) { options.appInfo.package = util::utf8ToUtf16(arg); }); } else if (options.phase == AaptOptions::Phase::Link) { if (options.phase == AaptOptions::Phase::Link) { flag::requiredFlag("--manifest", "AndroidManifest.xml of your app", [&options](const StringPiece& arg) { options.manifest = Source{ arg.toString() }; Loading Loading @@ -1124,11 +1117,15 @@ static AaptOptions prepareArgs(int argc, char** argv) { false, &options.versionStylesAndLayouts); } if (options.phase == AaptOptions::Phase::Compile || options.phase == AaptOptions::Phase::Link) { // Common flags for all steps. flag::requiredFlag("-o", "Output path", [&options](const StringPiece& arg) { options.output = Source{ arg.toString() }; }); } else if (options.phase == AaptOptions::Phase::DumpStyleGraph) { } if (options.phase == AaptOptions::Phase::DumpStyleGraph) { flag::requiredFlag("--style", "Name of the style to dump", [&options](const StringPiece& arg, std::string* outError) -> bool { Reference styleReference; Loading Loading @@ -1191,7 +1188,7 @@ static bool doDump(const AaptOptions& options) { zipFile->uncompress(entry)); assert(uncompressedData); BinaryResourceParser parser(table, resolver, source, uncompressedData.get(), BinaryResourceParser parser(table, resolver, source, {}, uncompressedData.get(), entry->getUncompressedLen()); if (!parser.parse()) { return false; Loading Loading @@ -1223,16 +1220,17 @@ int main(int argc, char** argv) { if (!loadAppInfo(options.manifest, &options.appInfo)) { return false; } } // Verify we have some common options set. if (options.appInfo.package.empty()) { Logger::error() << "no package name specified." << std::endl; return false; } } // Every phase needs a resource table. std::shared_ptr<ResourceTable> table = std::make_shared<ResourceTable>(); // The package name is empty when in the compile phase. table->setPackage(options.appInfo.package); if (options.appInfo.package == u"android") { table->setPackageId(0x01); Loading
tools/aapt2/TableFlattener.cpp +1 −8 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ public: // Write the key. if (!Res_INTERNALID(key.id.id) && !key.id.isValid()) { assert(key.name.isValid()); assert(!key.name.entry.empty()); mSymbols->push_back(std::make_pair(ResourceNameRef(key.name), mOut->size() - sizeof(*outMapEntry))); } Loading Loading @@ -284,13 +284,6 @@ bool TableFlattener::flattenValue(BigBuffer* out, const FlatEntry& flatEntry, bool TableFlattener::flatten(BigBuffer* out, const ResourceTable& table) { const size_t beginning = out->size(); if (table.getPackage().size() == 0) { Logger::error() << "ResourceTable has no package name." << std::endl; return false; } if (table.getPackageId() == ResourceTable::kUnsetPackageId) { Logger::error() << "ResourceTable has no package ID set." Loading