AAPT2: Added badging and permission

Added the remaining dump commands to aapt2.
aapt2 dump badging [apk]
aapt2 dump permissions [apk]

Bug: 73351292
Test: Diffing aapt and aapt2 output across apps from the Android tree
Change-Id: Idee820db410ad8d777d0d250c2657e7b83112a00
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index 5cb30b6..91e3977 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -223,6 +223,12 @@
     return 1;
   }
 
+  ResourceTable* table = loaded_apk->GetResourceTable();
+  if (!table) {
+    diag_->Error(DiagMessage() << "Failed to retrieve resource table.");
+    return 1;
+  }
+
   io::FileOutputStream fout(STDOUT_FILENO, kStdOutBufferSize);
   Printer printer(&fout);
 
@@ -233,7 +239,7 @@
 
   // Insert the configurations into a set in order to keep every configuarion seen
   std::set<ConfigDescription, decltype(compare)> configs(compare);
-  for (auto& package : loaded_apk->GetResourceTable()->packages) {
+  for (auto& package : table->packages) {
     for (auto& type : package->types) {
       for (auto& entry : type->entries) {
         for (auto& value : entry->values) {
@@ -267,10 +273,15 @@
       return 1;
     }
 
+    ResourceTable* table = loaded_apk->GetResourceTable();
+    if (!table) {
+      diag_->Error(DiagMessage() << "Failed to retrieve resource table.");
+      return 1;
+    }
+
     // Load the run-time xml string pool using the flattened data
     BigBuffer buffer(4096);
-    StringPool::FlattenUtf8(&buffer, loaded_apk->GetResourceTable()->string_pool,
-                            context.GetDiagnostics());
+    StringPool::FlattenUtf8(&buffer, table->string_pool, context.GetDiagnostics());
     auto data = buffer.to_string();
     android::ResStringPool pool(data.data(), data.size(), false);
     Debug::DumpResStringPool(&pool, &printer);
@@ -304,7 +315,13 @@
       printer.Println("Binary APK");
     }
 
-    Debug::PrintTable(*loaded_apk->GetResourceTable(), print_options, &printer);
+    ResourceTable* table = loaded_apk->GetResourceTable();
+    if (!table) {
+      diag_->Error(DiagMessage() << "Failed to retrieve resource table.");
+      return 1;
+    }
+
+    Debug::PrintTable(*table, print_options, &printer);
   }
 
   return 0;