idmap2: add debug information to idmap file format

Add a new variable length string to the idmap file format. This string will
hold debug information like fulfilled policies and any warnings triggered while
generating the file.

Bump the idmap version to 3.

Adjust the idmap header definition in ResourceType.h to take the new string
into account.

Example debug info:

  $ idmap2 create \
        --target-apk-path frameworks/base/cmds/idmap2/tests/data/target/target.apk \
        --overlay-apk-path frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk \
        --idmap-path /tmp/a.idmap \
        --policy public \
        --policy oem

  $ idmap2 dump --idmap-path /tmp/a.idmap
  target apk path  : frameworks/base/cmds/idmap2/tests/data/target/target.apk
  overlay apk path : frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
  I fulfilled_policies=oem|public enforce_overlayable=true
  W failed to find resource "integer/not_in_target" in target resources
  0x7f010000 -> 0x7f010000 integer/int1
  0x7f02000c -> 0x7f020000 string/str1
  [...]

  $ idmap2 dump --idmap-path /tmp/a.idmap --verbose
  00000000: 504d4449  magic
  00000004: 00000003  version
  00000008: 76a20829  target crc
  0000000c: c054fb26  overlay crc
  00000010: ........  target path: frameworks/base/cmds/idmap2/tests/data/target/target.apk
  00000110: ........  overlay path: frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
  00000210: ........  debug info: ...
  00000294:       7f  target package id
  00000295:       7f  overlay package id
  [...]

Also, tell cpplint to accept non-const references as function parameters:
they make more sense as out-parameters than pointers that are assumed to
be non-null.

Also, switch to regular expressions in the RawPrintVisitorTests: no more
manual fixups of the stream offsets! Tell cpplint that the <regex>
header is OK to use.

Bug: 140790707
Test: idmap2_tests
Change-Id: Ib94684a3b4001240321801e21af8e132fbcf6609
diff --git a/cmds/idmap2/tests/TestHelpers.h b/cmds/idmap2/tests/TestHelpers.h
index 8868b53..e899589 100644
--- a/cmds/idmap2/tests/TestHelpers.h
+++ b/cmds/idmap2/tests/TestHelpers.h
@@ -30,7 +30,7 @@
     0x49, 0x44, 0x4d, 0x50,
 
     // 0x4: version
-    0x02, 0x00, 0x00, 0x00,
+    0x03, 0x00, 0x00, 0x00,
 
     // 0x8: target crc
     0x34, 0x12, 0x00, 0x00,
@@ -74,64 +74,71 @@
     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,
 
+    // 0x210: debug string
+    // string length, including terminating null
+    0x08, 0x00, 0x00, 0x00,
+
+    // string contents "debug\0\0\0" (padded to word alignment)
+    0x64, 0x65, 0x62, 0x75, 0x67, 0x00, 0x00, 0x00,
+
     // DATA HEADER
-    // 0x210: target_package_id
+    // 0x21c: target_package_id
     0x7f,
 
-    // 0x211: overlay_package_id
+    // 0x21d: overlay_package_id
     0x7f,
 
-    // 0x212: target_entry_count
+    // 0x21e: target_entry_count
     0x03, 0x00, 0x00, 0x00,
 
-    // 0x216: overlay_entry_count
+    // 0x222: overlay_entry_count
     0x03, 0x00, 0x00, 0x00,
 
-    // 0x21a: string_pool_offset
+    // 0x226: string_pool_offset
     0x00, 0x00, 0x00, 0x00,
 
-    // 0x21e: string_pool_byte_length
+    // 0x22a: string_pool_byte_length
     0x00, 0x00, 0x00, 0x00,
 
     // TARGET ENTRIES
-    // 0x222: 0x7f020000
+    // 0x22e: 0x7f020000
     0x00, 0x00, 0x02, 0x7f,
 
-    // 0x226: TYPE_REFERENCE
+    // 0x232: TYPE_REFERENCE
     0x01,
 
-    // 0x227: 0x7f020000
+    // 0x233: 0x7f020000
     0x00, 0x00, 0x02, 0x7f,
 
-    // 0x22b: 0x7f030000
+    // 0x237: 0x7f030000
     0x00, 0x00, 0x03, 0x7f,
 
-    // 0x22f: TYPE_REFERENCE
+    // 0x23b: TYPE_REFERENCE
     0x01,
 
-    // 0x230: 0x7f030000
+    // 0x23c: 0x7f030000
     0x00, 0x00, 0x03, 0x7f,
 
-    // 0x234: 0x7f030002
+    // 0x240: 0x7f030002
     0x02, 0x00, 0x03, 0x7f,
 
-    // 0x238: TYPE_REFERENCE
+    // 0x244: TYPE_REFERENCE
     0x01,
 
-    // 0x239: 0x7f030001
+    // 0x245: 0x7f030001
     0x01, 0x00, 0x03, 0x7f,
 
     // OVERLAY ENTRIES
-    // 0x23d: 0x7f020000 -> 0x7f020000
+    // 0x249: 0x7f020000 -> 0x7f020000
     0x00, 0x00, 0x02, 0x7f, 0x00, 0x00, 0x02, 0x7f,
 
-    // 0x245: 0x7f030000 -> 0x7f030000
+    // 0x251: 0x7f030000 -> 0x7f030000
     0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x03, 0x7f,
 
-    // 0x24d: 0x7f030001 -> 0x7f030002
+    // 0x259: 0x7f030001 -> 0x7f030002
     0x01, 0x00, 0x03, 0x7f, 0x02, 0x00, 0x03, 0x7f};
 
-const unsigned int idmap_raw_data_len = 0x255;
+const unsigned int idmap_raw_data_len = 0x261;
 
 std::string GetTestDataPath();