Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35cb783a authored by Mårten Kongstad's avatar Mårten Kongstad Committed by Todd Kennedy
Browse files

idmap2: add sections to 'idmap2 dump' output

With the introduction of the debug info, the output of 'idmap2 dump' is
becoming messy. Add sections to combat this.

Example output:

  $ idmap2 create \
        --target-apk-path frameworks/base/cmds/idmap2/tests/data/target/target.apk \
        --overlay-apk-path frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk \
        --idmap-path /tmp/a.idmap \
        --policy public \
        --policy oem

  $ idmap2 dump --idmap-path /tmp/a.idmap
  Paths:
      target apk path  : frameworks/base/cmds/idmap2/tests/data/target/target.apk
      overlay apk path : frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
  Debug info:
      I fulfilled_policies=oem|public enforce_overlayable=true
      W failed to find resource "integer/not_in_target" in target resources
  Mapping:
      0x7f010000 -> 0x7f010000 integer/int1
      0x7f02000c -> 0x7f020000 string/str1
  [...]

Test: idmap2_tests
Change-Id: Ie42f97484b31af0c0b34f1856d321533904dbf7a
parent 548d6dcf
Loading
Loading
Loading
Loading
+14 −4
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


#include "idmap2/PrettyPrintVisitor.h"
#include "idmap2/PrettyPrintVisitor.h"


#include <istream>
#include <string>
#include <string>


#include "android-base/macros.h"
#include "android-base/macros.h"
@@ -28,21 +29,30 @@ namespace android::idmap2 {


#define RESID(pkg, type, entry) (((pkg) << 24) | ((type) << 16) | (entry))
#define RESID(pkg, type, entry) (((pkg) << 24) | ((type) << 16) | (entry))


#define TAB "    "

void PrettyPrintVisitor::visit(const Idmap& idmap ATTRIBUTE_UNUSED) {
void PrettyPrintVisitor::visit(const Idmap& idmap ATTRIBUTE_UNUSED) {
}
}


void PrettyPrintVisitor::visit(const IdmapHeader& header) {
void PrettyPrintVisitor::visit(const IdmapHeader& header) {
  stream_ << "target apk path  : " << header.GetTargetPath() << std::endl
  stream_ << "Paths:" << std::endl
          << "overlay apk path : " << header.GetOverlayPath() << std::endl;
          << TAB "target apk path  : " << header.GetTargetPath() << std::endl
          << TAB "overlay apk path : " << header.GetOverlayPath() << std::endl;
  const std::string& debug = header.GetDebugInfo();
  const std::string& debug = header.GetDebugInfo();
  if (!debug.empty()) {
  if (!debug.empty()) {
    stream_ << debug;  // assume newline terminated
    std::istringstream debug_stream(debug);
    std::string line;
    stream_ << "Debug info:" << std::endl;
    while (std::getline(debug_stream, line)) {
      stream_ << TAB << line << std::endl;
    }
  }
  }


  target_apk_ = ApkAssets::Load(header.GetTargetPath().to_string());
  target_apk_ = ApkAssets::Load(header.GetTargetPath().to_string());
  if (target_apk_) {
  if (target_apk_) {
    target_am_.SetApkAssets({target_apk_.get()});
    target_am_.SetApkAssets({target_apk_.get()});
  }
  }
  stream_ << "Mapping:" << std::endl;
}
}


void PrettyPrintVisitor::visit(const IdmapData::Header& header ATTRIBUTE_UNUSED) {
void PrettyPrintVisitor::visit(const IdmapData::Header& header ATTRIBUTE_UNUSED) {
@@ -55,7 +65,7 @@ void PrettyPrintVisitor::visit(const IdmapData& data) {
  const size_t string_pool_offset = data.GetHeader()->GetStringPoolIndexOffset();
  const size_t string_pool_offset = data.GetHeader()->GetStringPoolIndexOffset();


  for (auto& target_entry : data.GetTargetEntries()) {
  for (auto& target_entry : data.GetTargetEntries()) {
    stream_ << base::StringPrintf("0x%08x ->", target_entry.target_id);
    stream_ << TAB << base::StringPrintf("0x%08x ->", target_entry.target_id);


    if (target_entry.data_type != Res_value::TYPE_REFERENCE &&
    if (target_entry.data_type != Res_value::TYPE_REFERENCE &&
        target_entry.data_type != Res_value::TYPE_DYNAMIC_REFERENCE) {
        target_entry.data_type != Res_value::TYPE_DYNAMIC_REFERENCE) {