summaryrefslogtreecommitdiff
path: root/libs/androidfw/Idmap.cpp
diff options
context:
space:
mode:
author Ryan Mitchell <rtmitchell@google.com> 2021-01-08 13:34:28 -0800
committer Ryan Mitchell <rtmitchell@google.com> 2021-02-09 20:13:50 -0800
commit2ed8bfa7fda3c42280e0816c6cf1af852981723b (patch)
tree4fbe3151d2a0094f9bb97b8714a4afa9be2ed094 /libs/androidfw/Idmap.cpp
parent5c8ba79373ef7a950f6bfb87e7aa694f29ace243 (diff)
Add fabricated RRO generation to libidmap2
Fabricated Runtime Resource Overlays are overlays that are generated at runtime and are stored in the data/ partition. The system can fabricate RROs at runtime to dynamically theme the device. Idmaps can now be created from APK RROs and fabricated RROs. Rather than operating on ApkAssets, libidmap2 now operates on abstract resource "containers" that supply resource values. Target resource containers implement methods needed to query overlayable and target overlay information. Currently only APKs can be loaded as target resource containers. Overlay resource containers implement methods to supply the mapping of target resource to overlay value and other overlay information. The format of a fabricated RRO is as follows: 0x00 - 0x04 : fabricated overlay magic (always FRRO) 0x04 - 0x08 : file format version 0x08 - 0x0c : crc of version + proto data 0x0c - EOF : proto fabricated overlay data The magic is used to quickly detect if the file is a fabricated overlay. The version is incremented whenever backwards incompatible changes are made to the proto file format. Idmap must always be able to upgrade fabricated overlays from previous versions to new versions, so all previous versions must be checked into the tree. Bug: 172471315 Test: libidmap2_tests && libandroidfw_tests Change-Id: I4c9f29da278672e5695fb57d131a44c11a835180
Diffstat (limited to 'libs/androidfw/Idmap.cpp')
-rw-r--r--libs/androidfw/Idmap.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp
index f216f55771c2..efd1f6a25786 100644
--- a/libs/androidfw/Idmap.cpp
+++ b/libs/androidfw/Idmap.cpp
@@ -54,12 +54,6 @@ struct Idmap_header {
};
struct Idmap_data_header {
- uint8_t target_package_id;
- uint8_t overlay_package_id;
-
- // Padding to ensure 4 byte alignment for target_entry_count
- uint16_t p0;
-
uint32_t target_entry_count;
uint32_t target_inline_entry_count;
uint32_t overlay_entry_count;
@@ -158,19 +152,19 @@ IdmapResMap::Result IdmapResMap::Lookup(uint32_t target_res_id) const {
return {};
}
- // The resource ids encoded within the idmap are build-time resource ids.
- target_res_id = (0x00FFFFFFU & target_res_id)
- | (((uint32_t) data_header_->target_package_id) << 24U);
+ // The resource ids encoded within the idmap are build-time resource ids so do not consider the
+ // package id when determining if the resource in the target package is overlaid.
+ target_res_id &= 0x00FFFFFFU;
// Check if the target resource is mapped to an overlay resource.
auto first_entry = entries_;
auto end_entry = entries_ + dtohl(data_header_->target_entry_count);
auto entry = std::lower_bound(first_entry, end_entry, target_res_id,
- [](const Idmap_target_entry &e, const uint32_t target_id) {
- return dtohl(e.target_id) < target_id;
+ [](const Idmap_target_entry& e, const uint32_t target_id) {
+ return (0x00FFFFFFU & dtohl(e.target_id)) < target_id;
});
- if (entry != end_entry && dtohl(entry->target_id) == target_res_id) {
+ if (entry != end_entry && (0x00FFFFFFU & dtohl(entry->target_id)) == target_res_id) {
uint32_t overlay_resource_id = dtohl(entry->overlay_id);
// Lookup the resource without rewriting the overlay resource id back to the target resource id
// being looked up.
@@ -182,12 +176,13 @@ IdmapResMap::Result IdmapResMap::Lookup(uint32_t target_res_id) const {
auto first_inline_entry = inline_entries_;
auto end_inline_entry = inline_entries_ + dtohl(data_header_->target_inline_entry_count);
auto inline_entry = std::lower_bound(first_inline_entry, end_inline_entry, target_res_id,
- [](const Idmap_target_entry_inline &e,
+ [](const Idmap_target_entry_inline& e,
const uint32_t target_id) {
- return dtohl(e.target_id) < target_id;
+ return (0x00FFFFFFU & dtohl(e.target_id)) < target_id;
});
- if (inline_entry != end_inline_entry && dtohl(inline_entry->target_id) == target_res_id) {
+ if (inline_entry != end_inline_entry &&
+ (0x00FFFFFFU & dtohl(inline_entry->target_id)) == target_res_id) {
return Result(inline_entry->value);
}
return {};
@@ -235,7 +230,7 @@ std::optional<std::string_view> ReadString(const uint8_t** in_out_data_ptr, size
}
return std::string_view(data, *len);
}
-}
+} // namespace
LoadedIdmap::LoadedIdmap(std::string&& idmap_path,
const Idmap_header* header,