diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2020-09-29 17:22:52 -0700 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2020-10-14 14:52:52 -0700 |
commit | bf1f45b071bd2fb28cbea7e7cea86cd2e4944a7c (patch) | |
tree | 81521006b59c4e16a7b593f0fe123be5f2f54c0c /cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp | |
parent | 0f942f99cac4f5f61b40847d20ecb3a94c96c843 (diff) |
Remove malloc/free for inline overlay values
Remove malloc/free of android::ResTable_entry for inline overlay
values.
Add `target_entry_inline` to the idmap format to encode inline overlay
values separate from direct mapping of target resource to overlay
resource. This reduces the number of bytes needed to represent a direct
mapping of target resource to overlay resource from 9 bytes to 8 bytes
per entry.
Fixed all idmap alignment issues that required the framework to use
"#pragma pack(push, 1)" when loading idmaps.
Bug: 170341022
Test: idmap2_tests and libandroidfw_tests
Change-Id: Iab4d3902508f02773464724913e0ee966e3689e4
Diffstat (limited to 'cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp')
-rw-r--r-- | cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp b/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp index 63ee8a648352..a93202a64d31 100644 --- a/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp +++ b/cmds/idmap2/libidmap2/PrettyPrintVisitor.cpp @@ -38,6 +38,7 @@ void PrettyPrintVisitor::visit(const IdmapHeader& header) { 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); @@ -48,10 +49,16 @@ void PrettyPrintVisitor::visit(const IdmapHeader& header) { } } - target_apk_ = ApkAssets::Load(header.GetTargetPath().to_string()); - if (target_apk_) { + if (auto target_apk_ = ApkAssets::Load(header.GetTargetPath().to_string())) { target_am_.SetApkAssets({target_apk_.get()}); + apk_assets_.push_back(std::move(target_apk_)); + } + + if (auto overlay_apk = ApkAssets::Load(header.GetOverlayPath().to_string())) { + overlay_am_.SetApkAssets({overlay_apk.get()}); + apk_assets_.push_back(std::move(overlay_apk)); } + stream_ << "Mapping:" << std::endl; } @@ -59,34 +66,56 @@ void PrettyPrintVisitor::visit(const IdmapData::Header& header ATTRIBUTE_UNUSED) } void PrettyPrintVisitor::visit(const IdmapData& data) { + static constexpr const char* kUnknownResourceName = "???"; + const bool target_package_loaded = !target_am_.GetApkAssets().empty(); - const ResStringPool string_pool(data.GetStringPoolData(), - data.GetHeader()->GetStringPoolLength()); + const bool overlay_package_loaded = !overlay_am_.GetApkAssets().empty(); + + const ResStringPool string_pool(data.GetStringPoolData().data(), data.GetStringPoolData().size()); 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); + for (const auto& target_entry : data.GetTargetEntries()) { + std::string target_name = kUnknownResourceName; + if (target_package_loaded) { + if (auto name = utils::ResToTypeEntryName(target_am_, target_entry.target_id)) { + target_name = *name; + } + } - 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); + std::string overlay_name = kUnknownResourceName; + if (overlay_package_loaded) { + if (auto name = utils::ResToTypeEntryName(overlay_am_, target_entry.overlay_id)) { + overlay_name = *name; + } } - if (target_entry.data_type == Res_value::TYPE_STRING) { - stream_ << " \"" - << string_pool.string8ObjectAt(target_entry.data_value - string_pool_offset).c_str() - << "\""; + stream_ << TAB + << base::StringPrintf("0x%08x -> 0x%08x (%s -> %s)", target_entry.target_id, + target_entry.overlay_id, target_name.c_str(), + overlay_name.c_str()) + << std::endl; + } + + for (auto& target_entry : data.GetTargetInlineEntries()) { + stream_ << TAB << base::StringPrintf("0x%08x -> ", target_entry.target_id) + << utils::DataTypeToString(target_entry.value.data_type); + + size_t unused; + if (target_entry.value.data_type == Res_value::TYPE_STRING) { + auto str = string_pool.stringAt(target_entry.value.data_value - string_pool_offset, &unused); + stream_ << " \"" << StringPiece16(str) << "\""; } else { - stream_ << " " << base::StringPrintf("0x%08x", target_entry.data_value); + stream_ << " " << base::StringPrintf("0x%08x", target_entry.value.data_value); } + std::string target_name = kUnknownResourceName; if (target_package_loaded) { - Result<std::string> name = utils::ResToTypeEntryName(target_am_, target_entry.target_id); - if (name) { - stream_ << " " << *name; + if (auto name = utils::ResToTypeEntryName(target_am_, target_entry.target_id)) { + target_name = *name; } } - stream_ << std::endl; + + stream_ << " (" << target_name << ")" << std::endl; } } |