blob: 3ecd82b074a11747b306b05a24cbf6f8433af221 [file] [log] [blame]
Adam Lesinski970bd8d2017-09-25 13:21:55 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define ATRACE_TAG ATRACE_TAG_RESOURCES
18
19#include "androidfw/Idmap.h"
20
Yurii Zubrytskyie7c1f002024-01-30 13:50:57 -080021#include "android-base/file.h"
Adam Lesinski970bd8d2017-09-25 13:21:55 -070022#include "android-base/logging.h"
23#include "android-base/stringprintf.h"
Yurii Zubrytskyie7c1f002024-01-30 13:50:57 -080024#include "android-base/utf8.h"
Ryan Mitchella9093052020-03-26 17:15:01 -070025#include "androidfw/misc.h"
Ryan Mitchell8a891d82019-07-01 09:48:23 -070026#include "androidfw/ResourceTypes.h"
27#include "androidfw/Util.h"
Adam Lesinski970bd8d2017-09-25 13:21:55 -070028#include "utils/ByteOrder.h"
29#include "utils/Trace.h"
30
31#ifdef _WIN32
32#ifdef ERROR
33#undef ERROR
34#endif
35#endif
36
Adam Lesinski970bd8d2017-09-25 13:21:55 -070037using ::android::base::StringPrintf;
38
39namespace android {
40
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080041// See frameworks/base/cmds/idmap2/include/idmap2/Idmap.h for full idmap file format specification.
42struct Idmap_header {
43 // Always 0x504D4449 ('IDMP')
44 uint32_t magic;
45 uint32_t version;
Adam Lesinski970bd8d2017-09-25 13:21:55 -070046
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080047 uint32_t target_crc32;
48 uint32_t overlay_crc32;
49
50 uint32_t fulfilled_policies;
51 uint32_t enforce_overlayable;
52
53 // overlay_path, target_path, and other string values encoded in the idmap header and read and
54 // stored in separate structures. This allows the idmap header data to be casted to this struct
55 // without having to read/store each header entry separately.
56};
57
58struct Idmap_data_header {
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080059 uint32_t target_entry_count;
60 uint32_t target_inline_entry_count;
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000061 uint32_t target_inline_entry_value_count;
62 uint32_t configuration_count;
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080063 uint32_t overlay_entry_count;
64
65 uint32_t string_pool_index_offset;
66};
67
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080068struct Idmap_target_entry_inline {
Jeremy Meyerbe2b7792022-08-23 17:42:50 +000069 uint32_t start_value_index;
70 uint32_t value_count;
71};
72
73struct Idmap_target_entry_inline_value {
74 uint32_t config_index;
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080075 Res_value value;
76};
77
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -070078static constexpr uint32_t convert_dev_target_id(uint32_t dev_target_id) {
79 return (0x00FFFFFFU & dtohl(dev_target_id));
80}
MÃ¥rten Kongstadd7e8a532019-10-11 08:32:04 +020081
Ryan Mitchell8a891d82019-07-01 09:48:23 -070082OverlayStringPool::OverlayStringPool(const LoadedIdmap* loaded_idmap)
Ryan Mitchell73bfe412019-11-12 16:22:04 -080083 : data_header_(loaded_idmap->data_header_),
84 idmap_string_pool_(loaded_idmap->string_pool_.get()) { };
Ryan Mitchell8a891d82019-07-01 09:48:23 -070085
86OverlayStringPool::~OverlayStringPool() {
87 uninit();
88}
89
Ryan Mitchelldb21f09a2020-11-16 23:08:18 +000090base::expected<StringPiece16, NullOrIOError> OverlayStringPool::stringAt(size_t idx) const {
Ryan Mitchell8a891d82019-07-01 09:48:23 -070091 const size_t offset = dtohl(data_header_->string_pool_index_offset);
Ryan Mitchelldf9e7322019-12-12 10:23:54 -080092 if (idmap_string_pool_ != nullptr && idx >= ResStringPool::size() && idx >= offset) {
Ryan Mitchelldb21f09a2020-11-16 23:08:18 +000093 return idmap_string_pool_->stringAt(idx - offset);
Adam Lesinski970bd8d2017-09-25 13:21:55 -070094 }
95
Ryan Mitchelldb21f09a2020-11-16 23:08:18 +000096 return ResStringPool::stringAt(idx);
Ryan Mitchell8a891d82019-07-01 09:48:23 -070097}
98
Ryan Mitchelldb21f09a2020-11-16 23:08:18 +000099base::expected<StringPiece, NullOrIOError> OverlayStringPool::string8At(size_t idx) const {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700100 const size_t offset = dtohl(data_header_->string_pool_index_offset);
Ryan Mitchelldf9e7322019-12-12 10:23:54 -0800101 if (idmap_string_pool_ != nullptr && idx >= ResStringPool::size() && idx >= offset) {
Ryan Mitchelldb21f09a2020-11-16 23:08:18 +0000102 return idmap_string_pool_->string8At(idx - offset);
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700103 }
104
Ryan Mitchelldb21f09a2020-11-16 23:08:18 +0000105 return ResStringPool::string8At(idx);
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700106}
107
Ryan Mitchelldf9e7322019-12-12 10:23:54 -0800108size_t OverlayStringPool::size() const {
109 return ResStringPool::size() + (idmap_string_pool_ != nullptr ? idmap_string_pool_->size() : 0U);
110}
111
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700112OverlayDynamicRefTable::OverlayDynamicRefTable(const Idmap_data_header* data_header,
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700113 Idmap_overlay_entries entries,
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700114 uint8_t target_assigned_package_id)
115 : data_header_(data_header),
116 entries_(entries),
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700117 target_assigned_package_id_(target_assigned_package_id) {
118}
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700119
120status_t OverlayDynamicRefTable::lookupResourceId(uint32_t* resId) const {
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700121 const auto count = dtohl(data_header_->overlay_entry_count);
122 const auto overlay_it_end = entries_.overlay_id + count;
123 const auto entry_it = std::lower_bound(entries_.overlay_id, overlay_it_end, *resId,
124 [](uint32_t dev_overlay_id, uint32_t overlay_id) {
125 return dtohl(dev_overlay_id) < overlay_id;
126 });
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700127
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700128 if (entry_it == overlay_it_end || dtohl(*entry_it) != *resId) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700129 // A mapping for the target resource id could not be found.
130 return DynamicRefTable::lookupResourceId(resId);
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700131 }
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700132
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700133 const auto index = entry_it - entries_.overlay_id;
134 *resId = convert_dev_target_id(entries_.target_id[index]) |
135 (((uint32_t)target_assigned_package_id_) << 24U);
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700136 return NO_ERROR;
137}
138
139status_t OverlayDynamicRefTable::lookupResourceIdNoRewrite(uint32_t* resId) const {
140 return DynamicRefTable::lookupResourceId(resId);
141}
142
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700143IdmapResMap::IdmapResMap(const Idmap_data_header* data_header, Idmap_target_entries entries,
144 Idmap_target_inline_entries inline_entries,
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000145 const Idmap_target_entry_inline_value* inline_entry_values,
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700146 const ConfigDescription* configs, uint8_t target_assigned_package_id,
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700147 const OverlayDynamicRefTable* overlay_ref_table)
148 : data_header_(data_header),
149 entries_(entries),
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700150 inline_entries_(inline_entries),
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000151 inline_entry_values_(inline_entry_values),
152 configurations_(configs),
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700153 target_assigned_package_id_(target_assigned_package_id),
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700154 overlay_ref_table_(overlay_ref_table) {
155}
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700156
157IdmapResMap::Result IdmapResMap::Lookup(uint32_t target_res_id) const {
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700158 if ((target_res_id >> 24U) != target_assigned_package_id_) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700159 // The resource id must have the same package id as the target package.
160 return {};
161 }
162
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800163 // The resource ids encoded within the idmap are build-time resource ids so do not consider the
164 // package id when determining if the resource in the target package is overlaid.
165 target_res_id &= 0x00FFFFFFU;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700166
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700167 // Check if the target resource is mapped to an overlay resource.
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700168 const auto target_end = entries_.target_id + dtohl(data_header_->target_entry_count);
169 auto target_it = std::lower_bound(entries_.target_id, target_end, target_res_id,
170 [](uint32_t dev_target_id, uint32_t target_id) {
171 return convert_dev_target_id(dev_target_id) < target_id;
172 });
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700173
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700174 if (target_it != target_end && convert_dev_target_id(*target_it) == target_res_id) {
175 const auto index = target_it - entries_.target_id;
176 uint32_t overlay_resource_id = dtohl(entries_.overlay_id[index]);
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700177 // Lookup the resource without rewriting the overlay resource id back to the target resource id
178 // being looked up.
179 overlay_ref_table_->lookupResourceIdNoRewrite(&overlay_resource_id);
180 return Result(overlay_resource_id);
181 }
182
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700183 // Check if the target resources is mapped to an inline table entry.
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700184 const auto inline_entry_target_end =
185 inline_entries_.target_id + dtohl(data_header_->target_inline_entry_count);
186 const auto inline_entry_target_it =
187 std::lower_bound(inline_entries_.target_id, inline_entry_target_end, target_res_id,
188 [](uint32_t dev_target_id, uint32_t target_id) {
189 return convert_dev_target_id(dev_target_id) < target_id;
190 });
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700191
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700192 if (inline_entry_target_it != inline_entry_target_end &&
193 convert_dev_target_id(*inline_entry_target_it) == target_res_id) {
194 const auto index = inline_entry_target_it - inline_entries_.target_id;
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000195 std::map<ConfigDescription, Res_value> values_map;
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700196 const auto& inline_entry = inline_entries_.entry[index];
197 for (int i = 0; i < dtohl(inline_entry.value_count); i++) {
198 const auto& value = inline_entry_values_[dtohl(inline_entry.start_value_index) + i];
199 const auto& config = configurations_[dtohl(value.config_index)];
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000200 values_map[config] = value.value;
201 }
Yurii Zubrytskyia5bc9582022-11-30 23:53:59 -0800202 return Result(std::move(values_map));
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700203 }
204 return {};
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700205}
206
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800207namespace {
208template <typename T>
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700209const T* ReadType(const uint8_t** in_out_data_ptr, size_t* in_out_size, const char* label,
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800210 size_t count = 1) {
211 if (!util::IsFourByteAligned(*in_out_data_ptr)) {
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700212 LOG(ERROR) << "Idmap " << label << " in " << __func__ << " is not word aligned.";
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800213 return {};
214 }
215 if ((*in_out_size / sizeof(T)) < count) {
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700216 LOG(ERROR) << "Idmap too small for the number of " << label << " in " << __func__
217 << " entries (" << count << ").";
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800218 return nullptr;
219 }
220 auto data_ptr = *in_out_data_ptr;
221 const size_t read_size = sizeof(T) * count;
222 *in_out_data_ptr += read_size;
223 *in_out_size -= read_size;
224 return reinterpret_cast<const T*>(data_ptr);
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700225}
226
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800227std::optional<std::string_view> ReadString(const uint8_t** in_out_data_ptr, size_t* in_out_size,
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700228 const char* label) {
229 const auto* len = ReadType<uint32_t>(in_out_data_ptr, in_out_size, label);
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800230 if (len == nullptr) {
231 return {};
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700232 }
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800233 const auto* data = ReadType<char>(in_out_data_ptr, in_out_size, label, *len);
234 if (data == nullptr) {
235 return {};
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700236 }
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800237 // Strings are padded to the next 4 byte boundary.
238 const uint32_t padding_size = (4U - ((size_t)*in_out_data_ptr & 0x3U)) % 4U;
239 for (uint32_t i = 0; i < padding_size; i++) {
240 if (**in_out_data_ptr != 0) {
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700241 LOG(ERROR) << " Idmap padding of " << label << " in " << __func__ << " is non-zero.";
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800242 return {};
243 }
244 *in_out_data_ptr += sizeof(uint8_t);
245 *in_out_size -= sizeof(uint8_t);
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700246 }
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800247 return std::string_view(data, *len);
248}
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800249} // namespace
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700250
Yurii Zubrytskyie7c1f002024-01-30 13:50:57 -0800251// O_PATH is a lightweight way of creating an FD, only exists on Linux
252#ifndef O_PATH
253#define O_PATH (0)
254#endif
255
256LoadedIdmap::LoadedIdmap(const std::string& idmap_path, const Idmap_header* header,
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700257 const Idmap_data_header* data_header, Idmap_target_entries target_entries,
258 Idmap_target_inline_entries target_inline_entries,
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000259 const Idmap_target_entry_inline_value* inline_entry_values,
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700260 const ConfigDescription* configs, Idmap_overlay_entries overlay_entries,
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800261 std::unique_ptr<ResStringPool>&& string_pool,
Yurii Zubrytskyia5bc9582022-11-30 23:53:59 -0800262 std::string_view overlay_apk_path, std::string_view target_apk_path)
263 : header_(header),
264 data_header_(data_header),
265 target_entries_(target_entries),
266 target_inline_entries_(target_inline_entries),
267 inline_entry_values_(inline_entry_values),
268 configurations_(configs),
269 overlay_entries_(overlay_entries),
270 string_pool_(std::move(string_pool)),
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700271 idmap_fd_(
272 android::base::utf8::open(idmap_path.c_str(), O_RDONLY | O_CLOEXEC | O_BINARY | O_PATH)),
Yurii Zubrytskyia5bc9582022-11-30 23:53:59 -0800273 overlay_apk_path_(overlay_apk_path),
274 target_apk_path_(target_apk_path),
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700275 idmap_last_mod_time_(getFileModDate(idmap_fd_.get())) {
276}
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700277
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700278std::unique_ptr<LoadedIdmap> LoadedIdmap::Load(StringPiece idmap_path, StringPiece idmap_data) {
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700279 ATRACE_CALL();
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800280 size_t data_size = idmap_data.size();
281 auto data_ptr = reinterpret_cast<const uint8_t*>(idmap_data.data());
282
283 // Parse the idmap header
284 auto header = ReadType<Idmap_header>(&data_ptr, &data_size, "header");
285 if (header == nullptr) {
286 return {};
287 }
288 if (dtohl(header->magic) != kIdmapMagic) {
289 LOG(ERROR) << StringPrintf("Invalid Idmap file: bad magic value (was 0x%08x, expected 0x%08x)",
290 dtohl(header->magic), kIdmapMagic);
291 return {};
292 }
293 if (dtohl(header->version) != kIdmapCurrentVersion) {
294 // We are strict about versions because files with this format are generated at runtime and
295 // don't need backwards compatibility.
296 LOG(ERROR) << StringPrintf("Version mismatch in Idmap (was 0x%08x, expected 0x%08x)",
297 dtohl(header->version), kIdmapCurrentVersion);
298 return {};
299 }
Brandon Liu9e93ae42023-03-23 00:16:19 +0000300 std::optional<std::string_view> target_path = ReadString(&data_ptr, &data_size, "target path");
301 if (!target_path) {
302 return {};
303 }
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800304 std::optional<std::string_view> overlay_path = ReadString(&data_ptr, &data_size, "overlay path");
305 if (!overlay_path) {
306 return {};
307 }
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800308 if (!ReadString(&data_ptr, &data_size, "target name") ||
309 !ReadString(&data_ptr, &data_size, "debug info")) {
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700310 return {};
311 }
312
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800313 // Parse the idmap data blocks. Currently idmap2 can only generate one data block.
314 auto data_header = ReadType<Idmap_data_header>(&data_ptr, &data_size, "data header");
315 if (data_header == nullptr) {
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700316 return {};
317 }
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700318 Idmap_target_entries target_entries{
319 .target_id = ReadType<uint32_t>(&data_ptr, &data_size, "entries.target_id",
320 dtohl(data_header->target_entry_count)),
321 .overlay_id = ReadType<uint32_t>(&data_ptr, &data_size, "entries.overlay_id",
322 dtohl(data_header->target_entry_count)),
323 };
324 if (!target_entries.target_id || !target_entries.overlay_id) {
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700325 return {};
326 }
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700327 Idmap_target_inline_entries target_inline_entries{
328 .target_id = ReadType<uint32_t>(&data_ptr, &data_size, "target inline.target_id",
329 dtohl(data_header->target_inline_entry_count)),
330 .entry = ReadType<Idmap_target_entry_inline>(&data_ptr, &data_size, "target inline.entry",
331 dtohl(data_header->target_inline_entry_count))};
332 if (!target_inline_entries.target_id || !target_inline_entries.entry) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700333 return {};
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700334 }
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000335
336 auto target_inline_entry_values = ReadType<Idmap_target_entry_inline_value>(
337 &data_ptr, &data_size, "target inline values",
338 dtohl(data_header->target_inline_entry_value_count));
339 if (target_inline_entry_values == nullptr) {
340 return {};
341 }
342
343 auto configurations = ReadType<ConfigDescription>(
344 &data_ptr, &data_size, "configurations",
345 dtohl(data_header->configuration_count));
346 if (configurations == nullptr) {
347 return {};
348 }
349
Yurii Zubrytskyid67e90e2024-08-30 17:39:56 -0700350 Idmap_overlay_entries overlay_entries{
351 .overlay_id = ReadType<uint32_t>(&data_ptr, &data_size, "overlay entries.overlay_id",
352 dtohl(data_header->overlay_entry_count)),
353 .target_id = ReadType<uint32_t>(&data_ptr, &data_size, "overlay entries.target_id",
354 dtohl(data_header->overlay_entry_count)),
355 };
356 if (!overlay_entries.overlay_id || !overlay_entries.target_id) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700357 return {};
358 }
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800359 std::optional<std::string_view> string_pool = ReadString(&data_ptr, &data_size, "string pool");
360 if (!string_pool) {
361 return {};
362 }
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700363 auto idmap_string_pool = util::make_unique<ResStringPool>();
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800364 if (!string_pool->empty()) {
365 const status_t err = idmap_string_pool->setTo(string_pool->data(), string_pool->size());
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700366 if (err != NO_ERROR) {
367 LOG(ERROR) << "idmap string pool corrupt.";
368 return {};
369 }
370 }
371
Ryan Mitchell831b0722021-01-13 10:11:18 -0800372 if (data_size != 0) {
373 LOG(ERROR) << "idmap parsed with " << data_size << "bytes remaining";
374 return {};
375 }
376
Ryan Mitchell73bfe412019-11-12 16:22:04 -0800377 // Can't use make_unique because LoadedIdmap constructor is private.
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800378 return std::unique_ptr<LoadedIdmap>(
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700379 new LoadedIdmap(std::string(idmap_path), header, data_header, target_entries,
Jeremy Meyerbe2b7792022-08-23 17:42:50 +0000380 target_inline_entries, target_inline_entry_values, configurations,
Brandon Liu9e93ae42023-03-23 00:16:19 +0000381 overlay_entries, std::move(idmap_string_pool), *overlay_path, *target_path));
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700382}
383
Ryan Mitchella9093052020-03-26 17:15:01 -0700384bool LoadedIdmap::IsUpToDate() const {
Yurii Zubrytskyie7c1f002024-01-30 13:50:57 -0800385 return idmap_last_mod_time_ == getFileModDate(idmap_fd_.get());
Ryan Mitchella9093052020-03-26 17:15:01 -0700386}
387
Adam Lesinski970bd8d2017-09-25 13:21:55 -0700388} // namespace android