diff options
Diffstat (limited to 'libs/androidfw')
| -rw-r--r-- | libs/androidfw/Idmap.cpp | 38 | ||||
| -rw-r--r-- | libs/androidfw/ResourceTypes.cpp | 17 | ||||
| -rw-r--r-- | libs/androidfw/include/androidfw/Idmap.h | 8 | ||||
| -rw-r--r-- | libs/androidfw/include/androidfw/ResourceTypes.h | 4 | ||||
| -rw-r--r-- | libs/androidfw/tests/data/overlay/overlay.idmap | bin | 732 -> 736 bytes |
5 files changed, 52 insertions, 15 deletions
diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp index 3ecd82b074a1..095be57a5dc8 100644 --- a/libs/androidfw/Idmap.cpp +++ b/libs/androidfw/Idmap.cpp @@ -55,6 +55,13 @@ struct Idmap_header { // without having to read/store each header entry separately. }; +struct Idmap_constraint { + // Constraint type can be TYPE_DISPLAY_ID or TYP_DEVICE_ID, please refer + // to ConstraintType in OverlayConstraint.java + uint32_t constraint_type; + uint32_t constraint_value; +}; + struct Idmap_data_header { uint32_t target_entry_count; uint32_t target_inline_entry_count; @@ -254,13 +261,18 @@ std::optional<std::string_view> ReadString(const uint8_t** in_out_data_ptr, size #endif LoadedIdmap::LoadedIdmap(const std::string& idmap_path, const Idmap_header* header, - const Idmap_data_header* data_header, Idmap_target_entries target_entries, + const Idmap_constraint* constraints, + uint32_t constraints_count, + const Idmap_data_header* data_header, + Idmap_target_entries target_entries, Idmap_target_inline_entries target_inline_entries, const Idmap_target_entry_inline_value* inline_entry_values, const ConfigDescription* configs, Idmap_overlay_entries overlay_entries, std::unique_ptr<ResStringPool>&& string_pool, std::string_view overlay_apk_path, std::string_view target_apk_path) : header_(header), + constraints_(constraints), + constraints_count_(constraints_count), data_header_(data_header), target_entries_(target_entries), target_inline_entries_(target_inline_entries), @@ -298,9 +310,9 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie return {}; } std::optional<std::string_view> target_path = ReadString(&data_ptr, &data_size, "target path"); - if (!target_path) { - return {}; - } + if (!target_path) { + return {}; + } std::optional<std::string_view> overlay_path = ReadString(&data_ptr, &data_size, "overlay path"); if (!overlay_path) { return {}; @@ -310,6 +322,17 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie return {}; } + auto constraints_count = ReadType<uint32_t>(&data_ptr, &data_size, "constraints count"); + if (!constraints_count) { + return {}; + } + auto constraints = *constraints_count > 0 ? + ReadType<Idmap_constraint>(&data_ptr, &data_size, "constraints", *constraints_count) + : nullptr; + if (*constraints_count > 0 && !constraints) { + return {}; + } + // Parse the idmap data blocks. Currently idmap2 can only generate one data block. auto data_header = ReadType<Idmap_data_header>(&data_ptr, &data_size, "data header"); if (data_header == nullptr) { @@ -376,9 +399,10 @@ std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPie // Can't use make_unique because LoadedIdmap constructor is private. return std::unique_ptr<LoadedIdmap>( - new LoadedIdmap(std::string(idmap_path), header, data_header, target_entries, - target_inline_entries, target_inline_entry_values, configurations, - overlay_entries, std::move(idmap_string_pool), *overlay_path, *target_path)); + new LoadedIdmap(std::string(idmap_path), header, constraints, *constraints_count, + data_header, target_entries, target_inline_entries, + target_inline_entry_values,configurations, overlay_entries, + std::move(idmap_string_pool),*overlay_path, *target_path)); } bool LoadedIdmap::IsUpToDate() const { diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index de9991a8be5e..978bc768cd3d 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -290,11 +290,11 @@ static bool assertIdmapHeader(const void* idmap, size_t size) { } const uint32_t version = htodl(*(reinterpret_cast<const uint32_t*>(idmap) + 1)); - if (version != ResTable::IDMAP_CURRENT_VERSION) { + if (version != kIdmapCurrentVersion) { // We are strict about versions because files with this format are // auto-generated and don't need backwards compatibility. ALOGW("idmap: version mismatch in header (is 0x%08x, expected 0x%08x)", - version, ResTable::IDMAP_CURRENT_VERSION); + version, kIdmapCurrentVersion); return false; } return true; @@ -400,14 +400,18 @@ status_t parseIdmap(const void* idmap, size_t size, uint8_t* outPackageId, Keyed return UNKNOWN_ERROR; } - size -= ResTable::IDMAP_HEADER_SIZE_BYTES; + size_t sizeOfHeaderAndConstraints = ResTable::IDMAP_HEADER_SIZE_BYTES + + // This accounts for zero constraints, and hence takes only 4 bytes for + // the constraints count. + ResTable::IDMAP_CONSTRAINTS_COUNT_SIZE_BYTES; + size -= sizeOfHeaderAndConstraints; if (size < sizeof(uint16_t) * 2) { ALOGE("idmap: too small to contain any mapping"); return UNKNOWN_ERROR; } const uint16_t* data = reinterpret_cast<const uint16_t*>( - reinterpret_cast<const uint8_t*>(idmap) + ResTable::IDMAP_HEADER_SIZE_BYTES); + reinterpret_cast<const uint8_t*>(idmap) + sizeOfHeaderAndConstraints); uint16_t targetPackageId = dtohs(*(data++)); if (targetPackageId == 0 || targetPackageId > 255) { @@ -7492,7 +7496,7 @@ status_t ResTable::createIdmap(const ResTable& targetResTable, // write idmap header uint32_t* data = reinterpret_cast<uint32_t*>(*outData); *data++ = htodl(IDMAP_MAGIC); // write: magic - *data++ = htodl(ResTable::IDMAP_CURRENT_VERSION); // write: version + *data++ = htodl(kIdmapCurrentVersion); // write: version *data++ = htodl(targetCrc); // write: target crc *data++ = htodl(overlayCrc); // write: overlay crc @@ -7507,6 +7511,9 @@ status_t ResTable::createIdmap(const ResTable& targetResTable, } data += (2 * 256) / sizeof(uint32_t); + // write zero constraints count (no constraints) + *data++ = htodl(0); + // write idmap data header uint16_t* typeData = reinterpret_cast<uint16_t*>(data); *typeData++ = htods(targetPackageStruct->id); // write: target package id diff --git a/libs/androidfw/include/androidfw/Idmap.h b/libs/androidfw/include/androidfw/Idmap.h index ac75eb3bb98c..d1db13f53069 100644 --- a/libs/androidfw/include/androidfw/Idmap.h +++ b/libs/androidfw/include/androidfw/Idmap.h @@ -35,6 +35,7 @@ namespace android { class LoadedIdmap; class IdmapResMap; struct Idmap_header; +struct Idmap_constraint; struct Idmap_data_header; struct Idmap_target_entry; struct Idmap_target_entry_inline; @@ -203,6 +204,8 @@ class LoadedIdmap { LoadedIdmap() = default; const Idmap_header* header_; + const Idmap_constraint* constraints_; + uint32_t constraints_count_; const Idmap_data_header* data_header_; Idmap_target_entries target_entries_; Idmap_target_inline_entries target_inline_entries_; @@ -220,7 +223,10 @@ class LoadedIdmap { DISALLOW_COPY_AND_ASSIGN(LoadedIdmap); explicit LoadedIdmap(const std::string& idmap_path, const Idmap_header* header, - const Idmap_data_header* data_header, Idmap_target_entries target_entries, + const Idmap_constraint* constraints, + uint32_t constraints_count, + const Idmap_data_header* data_header, + Idmap_target_entries target_entries, Idmap_target_inline_entries target_inline_entries, const Idmap_target_entry_inline_value* inline_entry_values_, const ConfigDescription* configs, Idmap_overlay_entries overlay_entries, diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h index e330410ed1a0..8b2871c21a1e 100644 --- a/libs/androidfw/include/androidfw/ResourceTypes.h +++ b/libs/androidfw/include/androidfw/ResourceTypes.h @@ -48,7 +48,7 @@ namespace android { constexpr const uint32_t kIdmapMagic = 0x504D4449u; -constexpr const uint32_t kIdmapCurrentVersion = 0x0000000Au; +constexpr const uint32_t kIdmapCurrentVersion = 0x0000000Bu; // This must never change. constexpr const uint32_t kFabricatedOverlayMagic = 0x4f525246; // FRRO (big endian) @@ -2267,7 +2267,7 @@ public: void** outData, size_t* outSize) const; static const size_t IDMAP_HEADER_SIZE_BYTES = 4 * sizeof(uint32_t) + 2 * 256; - static const uint32_t IDMAP_CURRENT_VERSION = 0x00000001; + static const size_t IDMAP_CONSTRAINTS_COUNT_SIZE_BYTES = sizeof(uint32_t); // Retrieve idmap meta-data. // diff --git a/libs/androidfw/tests/data/overlay/overlay.idmap b/libs/androidfw/tests/data/overlay/overlay.idmap Binary files differindex 7e4b261cf109..6bd57c8d517c 100644 --- a/libs/androidfw/tests/data/overlay/overlay.idmap +++ b/libs/androidfw/tests/data/overlay/overlay.idmap |