diff options
| author | 2018-08-24 20:50:44 +0000 | |
|---|---|---|
| committer | 2018-08-24 20:50:44 +0000 | |
| commit | 7113ec2cb47a2702ed3e2ec8b05e41d3deeef647 (patch) | |
| tree | 086645a510fe199f5ef2e4ae94ee858b94334ba6 | |
| parent | 62d0edc6ef5601b847d1bb82de4b24050dce398c (diff) | |
| parent | 895e19edf04f7a7ad2c2dc08401e1b7cb073bae6 (diff) | |
Merge "dump package name"
| -rw-r--r-- | tools/aapt2/cmd/Dump.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp index 8e7e5e59bc31..6bb762aafb3b 100644 --- a/tools/aapt2/cmd/Dump.cpp +++ b/tools/aapt2/cmd/Dump.cpp @@ -23,6 +23,7 @@ #include "Debug.h" #include "Diagnostics.h" #include "Flags.h" +#include "LoadedApk.h" #include "format/Container.h" #include "format/binary/BinaryResourceParser.h" #include "format/proto/ProtoDeserialize.h" @@ -254,6 +255,32 @@ static bool TryDumpFile(IAaptContext* context, const std::string& file_path, return true; } +static bool DumpPackageName(IAaptContext* context, const std::string& file_path) { + auto loaded_apk = LoadedApk::LoadApkFromPath(file_path, context->GetDiagnostics()); + if (!loaded_apk) { + return false; + } + + constexpr size_t kStdOutBufferSize = 1024u; + io::FileOutputStream fout(STDOUT_FILENO, kStdOutBufferSize); + Printer printer(&fout); + + xml::Element* manifest_el = loaded_apk->GetManifest()->root.get(); + if (!manifest_el) { + context->GetDiagnostics()->Error(DiagMessage() << "No AndroidManifest."); + return false; + } + + xml::Attribute* attr = manifest_el->FindAttribute({}, "package"); + if (!attr) { + context->GetDiagnostics()->Error(DiagMessage() << "No package name."); + return false; + } + printer.Println(StringPrintf("%s", attr->value.c_str())); + + return true; +} + namespace { class DumpContext : public IAaptContext { @@ -324,9 +351,20 @@ int Dump(const std::vector<StringPiece>& args) { DumpContext context; context.SetVerbose(verbose); + auto parsedArgs = flags.GetArgs(); + if (parsedArgs.size() > 1 && parsedArgs[0] == "packagename") { + parsedArgs.erase(parsedArgs.begin()); + for (const std::string& arg : parsedArgs) { + if (!DumpPackageName(&context, arg)) { + return 1; + } + } + return 0; + } + options.print_options.show_sources = true; options.print_options.show_values = !no_values; - for (const std::string& arg : flags.GetArgs()) { + for (const std::string& arg : parsedArgs) { if (!TryDumpFile(&context, arg, options)) { return 1; } |