summaryrefslogtreecommitdiff
path: root/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2019-09-23 09:47:02 -0700
committerRyan Mitchell <rtmitchell@google.com>2019-10-17 11:37:24 -0700
commite753ffef5499bc0150827a06d44b50abe78b36dd (patch)
tree0e32193d04435f3fd7d3c8d1cbe53581524c28d6 /cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
parent1ec87b3c86fcec770fbfce5d182219e3263236a8 (diff)
Idmap format changes for bidirectional lookup
This change modifies the idmap file format to allow for target resources to map to arbitrary type/value combinations and to allow overlay resources to be mapped back to target resource ids so references to overlay resources can appear as references to target resources at runtime. The mappings of target resources to overlay resources and vice-versa are both encoded as sparse arrays. Instead of looking up a resource by indexing into an array that maps to the overlay resource id, the runtime will binary search over the sparse array to find the type and value that overlays the target resource. Bug: 135943783 Test: idmap2_tests Change-Id: I5d5344cdb7fe35f4f2e8d6781016299dea5d1e20
Diffstat (limited to 'cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp')
-rw-r--r--cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp b/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
index dee2d219cbe1..3b0940ae06ef 100644
--- a/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
+++ b/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
@@ -24,6 +24,14 @@
namespace android::idmap2 {
+void BinaryStreamVisitor::Write(const void* value, size_t length) {
+ stream_.write(reinterpret_cast<const char*>(value), length);
+}
+
+void BinaryStreamVisitor::Write8(uint8_t value) {
+ stream_.write(reinterpret_cast<char*>(&value), sizeof(uint8_t));
+}
+
void BinaryStreamVisitor::Write16(uint16_t value) {
uint16_t x = htodl(value);
stream_.write(reinterpret_cast<char*>(&x), sizeof(uint16_t));
@@ -54,26 +62,28 @@ void BinaryStreamVisitor::visit(const IdmapHeader& header) {
WriteString(header.GetOverlayPath());
}
-void BinaryStreamVisitor::visit(const IdmapData& data ATTRIBUTE_UNUSED) {
- // nothing to do
-}
+void BinaryStreamVisitor::visit(const IdmapData& data) {
+ for (const auto& target_entry : data.GetTargetEntries()) {
+ Write32(target_entry.target_id);
+ Write8(target_entry.data_type);
+ Write32(target_entry.data_value);
+ }
-void BinaryStreamVisitor::visit(const IdmapData::Header& header) {
- Write16(header.GetTargetPackageId());
- Write16(header.GetTypeCount());
-}
+ for (const auto& overlay_entry : data.GetOverlayEntries()) {
+ Write32(overlay_entry.overlay_id);
+ Write32(overlay_entry.target_id);
+ }
-void BinaryStreamVisitor::visit(const IdmapData::TypeEntry& type_entry) {
- const uint16_t entryCount = type_entry.GetEntryCount();
+ Write(data.GetStringPoolData(), data.GetHeader()->GetStringPoolLength());
+}
- Write16(type_entry.GetTargetTypeId());
- Write16(type_entry.GetOverlayTypeId());
- Write16(entryCount);
- Write16(type_entry.GetEntryOffset());
- for (uint16_t i = 0; i < entryCount; i++) {
- EntryId entry_id = type_entry.GetEntry(i);
- Write32(entry_id != kNoEntry ? static_cast<uint32_t>(entry_id) : kPadding);
- }
+void BinaryStreamVisitor::visit(const IdmapData::Header& header) {
+ Write8(header.GetTargetPackageId());
+ Write8(header.GetOverlayPackageId());
+ Write32(header.GetTargetEntryCount());
+ Write32(header.GetOverlayEntryCount());
+ Write32(header.GetStringPoolIndexOffset());
+ Write32(header.GetStringPoolLength());
}
} // namespace android::idmap2