summaryrefslogtreecommitdiff
path: root/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2020-08-31 21:21:38 -0700
committerXin Li <delphij@google.com>2020-08-31 21:21:38 -0700
commit628590d7ec80e10a3fc24b1c18a1afb55cca10a8 (patch)
tree4b1c3f52d86d7fb53afbe9e9438468588fa489f8 /cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp
parentb11b8ec3aec8bb42f2c07e1c5ac7942da293baa8 (diff)
parentd2d3a20624d968199353ccf6ddbae6f3ac39c9af (diff)
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507 Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27 Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
Diffstat (limited to 'cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp')
-rw-r--r--cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp b/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp
index fbf2c777be9a..63ee8a648352 100644
--- a/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp
+++ b/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp
@@ -16,6 +16,7 @@
#include "idmap2/PrettyPrintVisitor.h"
+#include <istream>
#include <string>
#include "android-base/macros.h"
@@ -28,42 +29,59 @@ namespace android::idmap2 {
#define RESID(pkg, type, entry) (((pkg) << 24) | ((type) << 16) | (entry))
+#define TAB " "
+
void PrettyPrintVisitor::visit(const Idmap& idmap ATTRIBUTE_UNUSED) {
}
void PrettyPrintVisitor::visit(const IdmapHeader& header) {
- stream_ << "target apk path : " << header.GetTargetPath() << std::endl
- << "overlay apk path : " << header.GetOverlayPath() << std::endl;
+ stream_ << "Paths:" << std::endl
+ << TAB "target apk path : " << header.GetTargetPath() << std::endl
+ << TAB "overlay apk path : " << header.GetOverlayPath() << std::endl;
+ const std::string& debug = header.GetDebugInfo();
+ if (!debug.empty()) {
+ 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());
if (target_apk_) {
target_am_.SetApkAssets({target_apk_.get()});
}
-}
-
-void PrettyPrintVisitor::visit(const IdmapData& data ATTRIBUTE_UNUSED) {
+ stream_ << "Mapping:" << std::endl;
}
void PrettyPrintVisitor::visit(const IdmapData::Header& header ATTRIBUTE_UNUSED) {
- last_seen_package_id_ = header.GetTargetPackageId();
}
-void PrettyPrintVisitor::visit(const IdmapData::TypeEntry& type_entry) {
+void PrettyPrintVisitor::visit(const IdmapData& data) {
const bool target_package_loaded = !target_am_.GetApkAssets().empty();
- for (uint16_t i = 0; i < type_entry.GetEntryCount(); i++) {
- const EntryId entry = type_entry.GetEntry(i);
- if (entry == kNoEntry) {
- continue;
+ const ResStringPool string_pool(data.GetStringPoolData(),
+ data.GetHeader()->GetStringPoolLength());
+ const size_t string_pool_offset = data.GetHeader()->GetStringPoolIndexOffset();
+
+ for (auto& target_entry : data.GetTargetEntries()) {
+ stream_ << TAB << base::StringPrintf("0x%08x ->", target_entry.target_id);
+
+ if (target_entry.data_type != Res_value::TYPE_REFERENCE &&
+ target_entry.data_type != Res_value::TYPE_DYNAMIC_REFERENCE) {
+ stream_ << " " << utils::DataTypeToString(target_entry.data_type);
}
- const ResourceId target_resid =
- RESID(last_seen_package_id_, type_entry.GetTargetTypeId(), type_entry.GetEntryOffset() + i);
- const ResourceId overlay_resid =
- RESID(last_seen_package_id_, type_entry.GetOverlayTypeId(), entry);
+ if (target_entry.data_type == Res_value::TYPE_STRING) {
+ stream_ << " \""
+ << string_pool.string8ObjectAt(target_entry.data_value - string_pool_offset).c_str()
+ << "\"";
+ } else {
+ stream_ << " " << base::StringPrintf("0x%08x", target_entry.data_value);
+ }
- stream_ << base::StringPrintf("0x%08x -> 0x%08x", target_resid, overlay_resid);
if (target_package_loaded) {
- Result<std::string> name = utils::ResToTypeEntryName(target_am_, target_resid);
+ Result<std::string> name = utils::ResToTypeEntryName(target_am_, target_entry.target_id);
if (name) {
stream_ << " " << *name;
}