From d7e8a534d0fbf0b0f8f27f59f90dbbeb0b5641db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Fri, 11 Oct 2019 08:32:04 +0200 Subject: 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 header is OK to use. Bug: 140790707 Test: idmap2_tests Change-Id: Ib94684a3b4001240321801e21af8e132fbcf6609 --- libs/androidfw/Idmap.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'libs/androidfw/Idmap.cpp') diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp index 773353d32d51..ce3bffff0aa5 100644 --- a/libs/androidfw/Idmap.cpp +++ b/libs/androidfw/Idmap.cpp @@ -43,6 +43,10 @@ static bool compare_overlay_entries(const Idmap_overlay_entry& e1, const uint32_ return dtohl(e1.overlay_id) < overlay_id; } +size_t Idmap_header::Size() const { + return sizeof(Idmap_header) + sizeof(uint8_t) * dtohl(debug_info_size); +} + OverlayStringPool::OverlayStringPool(const LoadedIdmap* loaded_idmap) : data_header_(loaded_idmap->data_header_), idmap_string_pool_(loaded_idmap->string_pool_.get()) { }; @@ -211,8 +215,8 @@ std::unique_ptr LoadedIdmap::Load(const StringPiece& idmap_da } auto header = reinterpret_cast(idmap_data.data()); - const uint8_t* data_ptr = reinterpret_cast(idmap_data.data()) + sizeof(*header); - size_t data_size = idmap_data.size() - sizeof(*header); + const uint8_t* data_ptr = reinterpret_cast(idmap_data.data()) + header->Size(); + size_t data_size = idmap_data.size() - header->Size(); // Currently idmap2 can only generate one data block. auto data_header = reinterpret_cast(data_ptr); -- cgit v1.2.3