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
diff --git a/cmds/idmap2/tests/TestHelpers.h b/cmds/idmap2/tests/TestHelpers.h
index b599dcb..d0a8e3d 100644
--- a/cmds/idmap2/tests/TestHelpers.h
+++ b/cmds/idmap2/tests/TestHelpers.h
@@ -30,7 +30,7 @@
0x49, 0x44, 0x4d, 0x50,
// 0x4: version
- 0x04, 0x00, 0x00, 0x00,
+ 0x05, 0x00, 0x00, 0x00,
// 0x8: target crc
0x34, 0x12, 0x00, 0x00,
@@ -42,9 +42,9 @@
0x11, 0x00, 0x00, 0x00,
// 0x14: enforce overlayable
- 0x01,
+ 0x01, 0x00, 0x00, 0x00,
- // 0x15: target path "targetX.apk"
+ // 0x18: 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,
@@ -62,7 +62,7 @@
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,
- // 0x115: overlay path "overlayX.apk"
+ // 0x118: 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,
@@ -80,71 +80,89 @@
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,
- // 0x215: debug string
- // string length, including terminating null
- 0x08, 0x00, 0x00, 0x00,
+ // 0x218: debug string
+ // string length,
+ 0x05, 0x00, 0x00, 0x00,
- // string contents "debug\0\0\0" (padded to word alignment)
+ // 0x21c string contents "debug\0\0\0" (padded to word alignment)
0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00,
// DATA HEADER
- // 0x221: target_package_id
+ // 0x224: target_package_id
0x7f,
- // 0x222: overlay_package_id
+ // 0x225: overlay_package_id
0x7f,
- // 0x223: target_entry_count
+ // 0x226: padding
+ 0x00, 0x00,
+
+ // 0x228: target_entry_count
0x03, 0x00, 0x00, 0x00,
- // 0x227: overlay_entry_count
+ // 0x22c: target_inline_entry_count
+ 0x01, 0x00, 0x00, 0x00,
+
+ // 0x230: overlay_entry_count
0x03, 0x00, 0x00, 0x00,
- // 0x22b: string_pool_offset
- 0x00, 0x00, 0x00, 0x00,
-
- // 0x22f: string_pool_byte_length
+ // 0x234: string_pool_offset
0x00, 0x00, 0x00, 0x00,
// TARGET ENTRIES
- // 0x233: 0x7f020000
+ // 0x238: target id (0x7f020000)
0x00, 0x00, 0x02, 0x7f,
- // 0x237: TYPE_REFERENCE
- 0x01,
-
- // 0x238: 0x7f020000
+ // 0x23c: overlay_id (0x7f020000)
0x00, 0x00, 0x02, 0x7f,
- // 0x23c: 0x7f030000
+ // 0x240: target id (0x7f030000)
0x00, 0x00, 0x03, 0x7f,
- // 0x240: TYPE_REFERENCE
- 0x01,
-
- // 0x241: 0x7f030000
+ // 0x244: overlay_id (0x7f030000)
0x00, 0x00, 0x03, 0x7f,
- // 0x245: 0x7f030002
+ // 0x248: target id (0x7f030002)
0x02, 0x00, 0x03, 0x7f,
- // 0x249: TYPE_REFERENCE
- 0x01,
-
- // 0x24a: 0x7f030001
+ // 0x24c: overlay_id (0x7f030001)
0x01, 0x00, 0x03, 0x7f,
+ // INLINE TARGET ENTRIES
+
+ // 0x250: target_id
+ 0x00, 0x00, 0x04, 0x7f,
+
+ // 0x254: Res_value::size (value ignored by idmap)
+ 0x08, 0x00,
+
+ // 0x256: Res_value::res0 (value ignored by idmap)
+ 0x00,
+
+ // 0x257: Res_value::dataType (TYPE_INT_HEX)
+ 0x11,
+
+ // 0x258: Res_value::data
+ 0x78, 0x56, 0x34, 0x12,
+
// OVERLAY ENTRIES
- // 0x24e: 0x7f020000 -> 0x7f020000
+ // 0x25c: 0x7f020000 -> 0x7f020000
0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
- // 0x256: 0x7f030000 -> 0x7f030000
+ // 0x264: 0x7f030000 -> 0x7f030000
0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
- // 0x25e: 0x7f030001 -> 0x7f030002
- 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f};
+ // 0x26c: 0x7f030001 -> 0x7f030002
+ 0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f,
-const unsigned int idmap_raw_data_len = 0x266;
+ // 0x274: string pool
+ // string length,
+ 0x04, 0x00, 0x00, 0x00,
+
+ // 0x278 string contents "test" (padded to word alignment)
+ 0x74, 0x65, 0x73, 0x74};
+
+const unsigned int idmap_raw_data_len = 0x27c;
std::string GetTestDataPath();