[aapt2] Add resource table chunk dumping

Add a dump command to aapt2 to examine the structure of the resource
table structure. This dump command will be kept up-to-date as changes to
the resource table structure are made.

Bug: 193144097
Test: manual run on APK
Change-Id: I75e47d363cace2b1bafe320085a6b38b7bdee5ae
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index 0a1e021..bcce3e5 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -560,4 +560,21 @@
     32,  32,  32,  32,  32,  32,  32,  32,  32,  46,  32,  32,  46,  32,  32,  32,  32,  32,  32,
     32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  10};
 
+int DumpChunks::Dump(LoadedApk* apk) {
+  auto file = apk->GetFileCollection()->FindFile("resources.arsc");
+  if (!file) {
+    GetDiagnostics()->Error(DiagMessage() << "Failed to find resources.arsc in APK");
+    return 1;
+  }
+
+  auto data = file->OpenAsData();
+  if (!data) {
+    GetDiagnostics()->Error(DiagMessage() << "Failed to open resources.arsc ");
+    return 1;
+  }
+
+  Debug::DumpChunks(data->data(), data->size(), GetPrinter(), GetDiagnostics());
+  return 0;
+}
+
 }  // namespace aapt
diff --git a/tools/aapt2/cmd/Dump.h b/tools/aapt2/cmd/Dump.h
index 52616fa..ec320ec 100644
--- a/tools/aapt2/cmd/Dump.h
+++ b/tools/aapt2/cmd/Dump.h
@@ -17,6 +17,9 @@
 #ifndef AAPT2_DUMP_H
 #define AAPT2_DUMP_H
 
+#include <io/FileStream.h>
+#include <io/ZipArchive.h>
+
 #include "Command.h"
 #include "Debug.h"
 #include "LoadedApk.h"
@@ -226,6 +229,16 @@
   std::vector<std::string> files_;
 };
 
+class DumpChunks : public DumpApkCommand {
+ public:
+  DumpChunks(text::Printer* printer, IDiagnostics* diag) : DumpApkCommand("chunks", printer, diag) {
+    SetDescription("Print the chunk information of the compiled resources.arsc in the APK.");
+  }
+
+  int Dump(LoadedApk* apk) override;
+};
+
+/** Prints the tree of a compiled xml in an APK. */
 class DumpXmlTreeCommand : public DumpApkCommand {
  public:
   explicit DumpXmlTreeCommand(text::Printer* printer, IDiagnostics* diag)
@@ -263,6 +276,7 @@
     AddOptionalSubcommand(util::make_unique<DumpStringsCommand>(printer, diag_));
     AddOptionalSubcommand(util::make_unique<DumpStyleParentCommand>(printer, diag_));
     AddOptionalSubcommand(util::make_unique<DumpTableCommand>(printer, diag_));
+    AddOptionalSubcommand(util::make_unique<DumpChunks>(printer, diag_));
     AddOptionalSubcommand(util::make_unique<DumpXmlStringsCommand>(printer, diag_));
     AddOptionalSubcommand(util::make_unique<DumpXmlTreeCommand>(printer, diag_));
     AddOptionalSubcommand(util::make_unique<DumpOverlayableCommand>(printer, diag_));