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
diff --git a/cmds/idmap2/tests/TestHelpers.h b/cmds/idmap2/tests/TestHelpers.h
index a7c2f28..8868b53 100644
--- a/cmds/idmap2/tests/TestHelpers.h
+++ b/cmds/idmap2/tests/TestHelpers.h
@@ -30,7 +30,7 @@
0x49, 0x44, 0x4d, 0x50,
// 0x4: version
- 0x01, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00,
// 0x8: target crc
0x34, 0x12, 0x00, 0x00,
@@ -38,8 +38,8 @@
// 0xc: overlay crc
0x78, 0x56, 0x00, 0x00,
- // 0x10: target path "target.apk"
- 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // 0x10: target path "targetX.apk"
+ 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -56,8 +56,8 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x110: overlay path "overlay.apk"
- 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // 0x110: overlay path "overlayX.apk"
+ 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x58, 0x2e, 0x61, 0x70, 0x6b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -75,49 +75,63 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// DATA HEADER
- // 0x210: target package id
- 0x7f, 0x00,
+ // 0x210: target_package_id
+ 0x7f,
- // 0x212: types count
- 0x02, 0x00,
+ // 0x211: overlay_package_id
+ 0x7f,
- // DATA BLOCK
- // 0x214: target type
- 0x02, 0x00,
+ // 0x212: target_entry_count
+ 0x03, 0x00, 0x00, 0x00,
- // 0x216: overlay type
- 0x02, 0x00,
+ // 0x216: overlay_entry_count
+ 0x03, 0x00, 0x00, 0x00,
- // 0x218: entry count
- 0x01, 0x00,
-
- // 0x21a: entry offset
- 0x00, 0x00,
-
- // 0x21c: entries
+ // 0x21a: string_pool_offset
0x00, 0x00, 0x00, 0x00,
- // DATA BLOCK
- // 0x220: target type
- 0x03, 0x00,
-
- // 0x222: overlay type
- 0x03, 0x00,
-
- // 0x224: entry count
- 0x03, 0x00,
-
- // 0x226: entry offset
- 0x03, 0x00,
-
- // 0x228, 0x22c, 0x230: entries
+ // 0x21e: string_pool_byte_length
0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff,
+ // TARGET ENTRIES
+ // 0x222: 0x7f020000
+ 0x00, 0x00, 0x02, 0x7f,
- 0x01, 0x00, 0x00, 0x00};
+ // 0x226: TYPE_REFERENCE
+ 0x01,
-const unsigned int idmap_raw_data_len = 565;
+ // 0x227: 0x7f020000
+ 0x00, 0x00, 0x02, 0x7f,
+
+ // 0x22b: 0x7f030000
+ 0x00, 0x00, 0x03, 0x7f,
+
+ // 0x22f: TYPE_REFERENCE
+ 0x01,
+
+ // 0x230: 0x7f030000
+ 0x00, 0x00, 0x03, 0x7f,
+
+ // 0x234: 0x7f030002
+ 0x02, 0x00, 0x03, 0x7f,
+
+ // 0x238: TYPE_REFERENCE
+ 0x01,
+
+ // 0x239: 0x7f030001
+ 0x01, 0x00, 0x03, 0x7f,
+
+ // OVERLAY ENTRIES
+ // 0x23d: 0x7f020000 -> 0x7f020000
+ 0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
+
+ // 0x245: 0x7f030000 -> 0x7f030000
+ 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
+
+ // 0x24d: 0x7f030001 -> 0x7f030002
+ 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f};
+
+const unsigned int idmap_raw_data_len = 0x255;
std::string GetTestDataPath();