blob: 23c25a7089decbf7b99d34929bcd13cd8da263aa [file] [log] [blame]
Mårten Kongstad02751232018-04-27 13:16:32 +02001/*
2 * Copyright (C) 2018 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
Ryan Mitchell52e1f7a2019-04-12 12:31:42 -070017#include "idmap2/Idmap.h"
18
Mårten Kongstad02751232018-04-27 13:16:32 +020019#include <algorithm>
20#include <iostream>
21#include <iterator>
22#include <limits>
23#include <map>
24#include <memory>
25#include <set>
26#include <string>
27#include <utility>
28#include <vector>
29
30#include "android-base/macros.h"
31#include "android-base/stringprintf.h"
32#include "androidfw/AssetManager2.h"
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -070033#include "idmap2/ResourceMapping.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020034#include "idmap2/ResourceUtils.h"
Mårten Kongstad0f763112018-11-19 14:14:37 +010035#include "idmap2/Result.h"
Mårten Kongstad4cbb0072018-11-30 16:22:05 +010036#include "idmap2/SysTrace.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020037#include "idmap2/ZipFile.h"
Ryan Mitchell52e1f7a2019-04-12 12:31:42 -070038#include "utils/String16.h"
39#include "utils/String8.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020040
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010041namespace android::idmap2 {
Mårten Kongstad02751232018-04-27 13:16:32 +020042
Mårten Kongstad744ccfe2018-12-20 14:56:14 +010043namespace {
44
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070045bool WARN_UNUSED Read8(std::istream& stream, uint8_t* out) {
46 uint8_t value;
47 if (stream.read(reinterpret_cast<char*>(&value), sizeof(uint8_t))) {
48 *out = value;
Mårten Kongstad02751232018-04-27 13:16:32 +020049 return true;
50 }
51 return false;
52}
53
Mårten Kongstad744ccfe2018-12-20 14:56:14 +010054bool WARN_UNUSED Read32(std::istream& stream, uint32_t* out) {
Mårten Kongstad02751232018-04-27 13:16:32 +020055 uint32_t value;
56 if (stream.read(reinterpret_cast<char*>(&value), sizeof(uint32_t))) {
57 *out = dtohl(value);
58 return true;
59 }
60 return false;
61}
62
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070063bool WARN_UNUSED ReadBuffer(std::istream& stream, std::unique_ptr<uint8_t[]>* out, size_t length) {
64 auto buffer = std::unique_ptr<uint8_t[]>(new uint8_t[length]);
65 if (stream.read(reinterpret_cast<char*>(buffer.get()), length)) {
66 *out = std::move(buffer);
67 return true;
68 }
69 return false;
70}
71
Mårten Kongstad02751232018-04-27 13:16:32 +020072// a string is encoded as a kIdmapStringLength char array; the array is always null-terminated
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020073bool WARN_UNUSED ReadString256(std::istream& stream, char out[kIdmapStringLength]) {
Mårten Kongstad02751232018-04-27 13:16:32 +020074 char buf[kIdmapStringLength];
75 memset(buf, 0, sizeof(buf));
76 if (!stream.read(buf, sizeof(buf))) {
77 return false;
78 }
79 if (buf[sizeof(buf) - 1] != '\0') {
80 return false;
81 }
82 memcpy(out, buf, sizeof(buf));
83 return true;
84}
85
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020086Result<std::string> ReadString(std::istream& stream) {
87 uint32_t size;
88 if (!Read32(stream, &size)) {
89 return Error("failed to read string size");
90 }
91 if (size == 0) {
92 return std::string("");
93 }
94 std::string buf(size, '\0');
95 if (!stream.read(buf.data(), size)) {
96 return Error("failed to read string of size %u", size);
97 }
98 // buf is guaranteed to be null terminated (with enough nulls to end on a word boundary)
99 buf.resize(strlen(buf.c_str()));
100 return buf;
101}
102
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700103} // namespace
104
105Result<uint32_t> GetPackageCrc(const ZipFile& zip) {
Mårten Kongstad9371dc12019-01-22 14:35:12 +0100106 const Result<uint32_t> a = zip.Crc("resources.arsc");
107 const Result<uint32_t> b = zip.Crc("AndroidManifest.xml");
Mårten Kongstad49d835d2019-01-31 10:50:48 +0100108 return a && b
109 ? Result<uint32_t>(*a ^ *b)
Mårten Kongstadce424902019-03-01 08:35:37 +0100110 : Error("failed to get CRC for \"%s\"", a ? "AndroidManifest.xml" : "resources.arsc");
Mårten Kongstad9371dc12019-01-22 14:35:12 +0100111}
112
Mårten Kongstad02751232018-04-27 13:16:32 +0200113std::unique_ptr<const IdmapHeader> IdmapHeader::FromBinaryStream(std::istream& stream) {
114 std::unique_ptr<IdmapHeader> idmap_header(new IdmapHeader());
Ryan Mitchella7070132020-05-13 14:17:52 -0700115 uint8_t enforce_overlayable;
Mårten Kongstad02751232018-04-27 13:16:32 +0200116 if (!Read32(stream, &idmap_header->magic_) || !Read32(stream, &idmap_header->version_) ||
117 !Read32(stream, &idmap_header->target_crc_) || !Read32(stream, &idmap_header->overlay_crc_) ||
Ryan Mitchell038a2842020-06-08 14:41:07 -0700118 !Read32(stream, &idmap_header->fulfilled_policies_) || !Read8(stream, &enforce_overlayable) ||
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200119 !ReadString256(stream, idmap_header->target_path_) ||
120 !ReadString256(stream, idmap_header->overlay_path_)) {
Mårten Kongstad02751232018-04-27 13:16:32 +0200121 return nullptr;
122 }
123
Ryan Mitchella7070132020-05-13 14:17:52 -0700124 idmap_header->enforce_overlayable_ = static_cast<bool>(enforce_overlayable);
125
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200126 auto debug_str = ReadString(stream);
127 if (!debug_str) {
128 return nullptr;
129 }
130 idmap_header->debug_info_ = std::move(*debug_str);
131
Mårten Kongstad02751232018-04-27 13:16:32 +0200132 return std::move(idmap_header);
133}
134
Ryan Mitchella7070132020-05-13 14:17:52 -0700135Result<Unit> IdmapHeader::IsUpToDate(const char* target_path, const char* overlay_path,
Ryan Mitchell038a2842020-06-08 14:41:07 -0700136 PolicyBitmask fulfilled_policies,
137 bool enforce_overlayable) const {
Ryan Mitchella7070132020-05-13 14:17:52 -0700138 const std::unique_ptr<const ZipFile> target_zip = ZipFile::Open(target_path);
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700139 if (!target_zip) {
Ryan Mitchella7070132020-05-13 14:17:52 -0700140 return Error("failed to open target %s", target_path);
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700141 }
142
Ryan Mitchella7070132020-05-13 14:17:52 -0700143 const Result<uint32_t> target_crc = GetPackageCrc(*target_zip);
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700144 if (!target_crc) {
145 return Error("failed to get target crc");
146 }
147
Ryan Mitchella7070132020-05-13 14:17:52 -0700148 const std::unique_ptr<const ZipFile> overlay_zip = ZipFile::Open(overlay_path);
149 if (!overlay_zip) {
150 return Error("failed to overlay target %s", overlay_path);
151 }
152
153 const Result<uint32_t> overlay_crc = GetPackageCrc(*overlay_zip);
154 if (!overlay_crc) {
155 return Error("failed to get overlay crc");
156 }
157
158 return IsUpToDate(target_path, overlay_path, *target_crc, *overlay_crc, fulfilled_policies,
159 enforce_overlayable);
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700160}
161
Ryan Mitchella7070132020-05-13 14:17:52 -0700162Result<Unit> IdmapHeader::IsUpToDate(const char* target_path, const char* overlay_path,
163 uint32_t target_crc, uint32_t overlay_crc,
Ryan Mitchell038a2842020-06-08 14:41:07 -0700164 PolicyBitmask fulfilled_policies,
165 bool enforce_overlayable) const {
Mårten Kongstad02751232018-04-27 13:16:32 +0200166 if (magic_ != kIdmapMagic) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100167 return Error("bad magic: actual 0x%08x, expected 0x%08x", magic_, kIdmapMagic);
Mårten Kongstad02751232018-04-27 13:16:32 +0200168 }
169
170 if (version_ != kIdmapCurrentVersion) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100171 return Error("bad version: actual 0x%08x, expected 0x%08x", version_, kIdmapCurrentVersion);
Mårten Kongstad02751232018-04-27 13:16:32 +0200172 }
173
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700174 if (target_crc_ != target_crc) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100175 return Error("bad target crc: idmap version 0x%08x, file system version 0x%08x", target_crc_,
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700176 target_crc);
Mårten Kongstad02751232018-04-27 13:16:32 +0200177 }
178
Ryan Mitchella7070132020-05-13 14:17:52 -0700179 if (overlay_crc_ != overlay_crc) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100180 return Error("bad overlay crc: idmap version 0x%08x, file system version 0x%08x", overlay_crc_,
Ryan Mitchella7070132020-05-13 14:17:52 -0700181 overlay_crc);
182 }
183
184 if (fulfilled_policies_ != fulfilled_policies) {
185 return Error("bad fulfilled policies: idmap version 0x%08x, file system version 0x%08x",
186 fulfilled_policies, fulfilled_policies_);
187 }
188
189 if (enforce_overlayable != enforce_overlayable_) {
190 return Error("bad enforce overlayable: idmap version %s, file system version %s",
Ryan Mitchell038a2842020-06-08 14:41:07 -0700191 enforce_overlayable ? "true" : "false", enforce_overlayable_ ? "true" : "false");
Ryan Mitchella7070132020-05-13 14:17:52 -0700192 }
193
194 if (strcmp(target_path, target_path_) != 0) {
195 return Error("bad target path: idmap version %s, file system version %s", target_path,
196 target_path_);
197 }
198
199 if (strcmp(overlay_path, overlay_path_) != 0) {
200 return Error("bad overlay path: idmap version %s, file system version %s", overlay_path,
201 overlay_path_);
Mårten Kongstad02751232018-04-27 13:16:32 +0200202 }
203
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100204 return Unit{};
Mårten Kongstad02751232018-04-27 13:16:32 +0200205}
206
207std::unique_ptr<const IdmapData::Header> IdmapData::Header::FromBinaryStream(std::istream& stream) {
208 std::unique_ptr<IdmapData::Header> idmap_data_header(new IdmapData::Header());
209
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700210 if (!Read8(stream, &idmap_data_header->target_package_id_) ||
211 !Read8(stream, &idmap_data_header->overlay_package_id_) ||
212 !Read32(stream, &idmap_data_header->target_entry_count) ||
213 !Read32(stream, &idmap_data_header->overlay_entry_count) ||
214 !Read32(stream, &idmap_data_header->string_pool_index_offset) ||
215 !Read32(stream, &idmap_data_header->string_pool_len)) {
Mårten Kongstad02751232018-04-27 13:16:32 +0200216 return nullptr;
217 }
Mårten Kongstad02751232018-04-27 13:16:32 +0200218
219 return std::move(idmap_data_header);
220}
221
Mårten Kongstad02751232018-04-27 13:16:32 +0200222std::unique_ptr<const IdmapData> IdmapData::FromBinaryStream(std::istream& stream) {
223 std::unique_ptr<IdmapData> data(new IdmapData());
224 data->header_ = IdmapData::Header::FromBinaryStream(stream);
225 if (!data->header_) {
226 return nullptr;
227 }
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700228 // Read the mapping of target resource id to overlay resource value.
229 for (size_t i = 0; i < data->header_->GetTargetEntryCount(); i++) {
230 TargetEntry target_entry{};
231 if (!Read32(stream, &target_entry.target_id) || !Read8(stream, &target_entry.data_type) ||
232 !Read32(stream, &target_entry.data_value)) {
Mårten Kongstad02751232018-04-27 13:16:32 +0200233 return nullptr;
234 }
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700235 data->target_entries_.emplace_back(target_entry);
Mårten Kongstad02751232018-04-27 13:16:32 +0200236 }
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700237
238 // Read the mapping of overlay resource id to target resource id.
239 for (size_t i = 0; i < data->header_->GetOverlayEntryCount(); i++) {
240 OverlayEntry overlay_entry{};
241 if (!Read32(stream, &overlay_entry.overlay_id) || !Read32(stream, &overlay_entry.target_id)) {
242 return nullptr;
243 }
244 data->overlay_entries_.emplace_back(overlay_entry);
245 }
246
247 // Read raw string pool bytes.
248 if (!ReadBuffer(stream, &data->string_pool_, data->header_->string_pool_len)) {
249 return nullptr;
250 }
251
Mårten Kongstad02751232018-04-27 13:16:32 +0200252 return std::move(data);
253}
254
255std::string Idmap::CanonicalIdmapPathFor(const std::string& absolute_dir,
256 const std::string& absolute_apk_path) {
257 assert(absolute_dir.size() > 0 && absolute_dir[0] == "/");
258 assert(absolute_apk_path.size() > 0 && absolute_apk_path[0] == "/");
259 std::string copy(++absolute_apk_path.cbegin(), absolute_apk_path.cend());
260 replace(copy.begin(), copy.end(), '/', '@');
261 return absolute_dir + "/" + copy + "@idmap";
262}
263
Mårten Kongstadce424902019-03-01 08:35:37 +0100264Result<std::unique_ptr<const Idmap>> Idmap::FromBinaryStream(std::istream& stream) {
Mårten Kongstad4cbb0072018-11-30 16:22:05 +0100265 SYSTRACE << "Idmap::FromBinaryStream";
Mårten Kongstad02751232018-04-27 13:16:32 +0200266 std::unique_ptr<Idmap> idmap(new Idmap());
267
268 idmap->header_ = IdmapHeader::FromBinaryStream(stream);
269 if (!idmap->header_) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100270 return Error("failed to parse idmap header");
Mårten Kongstad02751232018-04-27 13:16:32 +0200271 }
272
273 // idmap version 0x01 does not specify the number of data blocks that follow
274 // the idmap header; assume exactly one data block
275 for (int i = 0; i < 1; i++) {
276 std::unique_ptr<const IdmapData> data = IdmapData::FromBinaryStream(stream);
277 if (!data) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100278 return Error("failed to parse data block %d", i);
Mårten Kongstad02751232018-04-27 13:16:32 +0200279 }
280 idmap->data_.push_back(std::move(data));
281 }
282
Mårten Kongstadce424902019-03-01 08:35:37 +0100283 return {std::move(idmap)};
Mårten Kongstad02751232018-04-27 13:16:32 +0200284}
285
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700286Result<std::unique_ptr<const IdmapData>> IdmapData::FromResourceMapping(
287 const ResourceMapping& resource_mapping) {
288 if (resource_mapping.GetTargetToOverlayMap().empty()) {
289 return Error("no resources were overlaid");
290 }
291
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700292 std::unique_ptr<IdmapData> data(new IdmapData());
293 for (const auto& mappings : resource_mapping.GetTargetToOverlayMap()) {
294 data->target_entries_.emplace_back(IdmapData::TargetEntry{
295 mappings.first, mappings.second.data_type, mappings.second.data_value});
Ryan Mitchell4c09a4a2019-03-08 08:57:48 -0800296 }
297
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700298 for (const auto& mappings : resource_mapping.GetOverlayToTargetMap()) {
299 data->overlay_entries_.emplace_back(IdmapData::OverlayEntry{mappings.first, mappings.second});
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700300 }
301
302 std::unique_ptr<IdmapData::Header> data_header(new IdmapData::Header());
303 data_header->target_package_id_ = resource_mapping.GetTargetPackageId();
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700304 data_header->overlay_package_id_ = resource_mapping.GetOverlayPackageId();
305 data_header->target_entry_count = static_cast<uint32_t>(data->target_entries_.size());
306 data_header->overlay_entry_count = static_cast<uint32_t>(data->overlay_entries_.size());
307 data_header->string_pool_index_offset = resource_mapping.GetStringPoolOffset();
308
309 const auto string_pool_data = resource_mapping.GetStringPoolData();
310 data_header->string_pool_len = string_pool_data.second;
311 data->string_pool_ = std::unique_ptr<uint8_t[]>(new uint8_t[data_header->string_pool_len]);
312 memcpy(data->string_pool_.get(), string_pool_data.first, data_header->string_pool_len);
313
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700314 data->header_ = std::move(data_header);
315 return {std::move(data)};
Ryan Mitchell4c09a4a2019-03-08 08:57:48 -0800316}
317
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700318Result<std::unique_ptr<const Idmap>> Idmap::FromApkAssets(const ApkAssets& target_apk_assets,
Mårten Kongstadce424902019-03-01 08:35:37 +0100319 const ApkAssets& overlay_apk_assets,
320 const PolicyBitmask& fulfilled_policies,
321 bool enforce_overlayable) {
Mårten Kongstad4cbb0072018-11-30 16:22:05 +0100322 SYSTRACE << "Idmap::FromApkAssets";
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700323 const std::string& target_apk_path = target_apk_assets.GetPath();
324 const std::string& overlay_apk_path = overlay_apk_assets.GetPath();
Mårten Kongstad02751232018-04-27 13:16:32 +0200325
326 const std::unique_ptr<const ZipFile> target_zip = ZipFile::Open(target_apk_path);
327 if (!target_zip) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100328 return Error("failed to open target as zip");
Mårten Kongstad02751232018-04-27 13:16:32 +0200329 }
330
331 const std::unique_ptr<const ZipFile> overlay_zip = ZipFile::Open(overlay_apk_path);
332 if (!overlay_zip) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100333 return Error("failed to open overlay as zip");
Mårten Kongstad02751232018-04-27 13:16:32 +0200334 }
335
336 std::unique_ptr<IdmapHeader> header(new IdmapHeader());
337 header->magic_ = kIdmapMagic;
338 header->version_ = kIdmapCurrentVersion;
Mårten Kongstad0f763112018-11-19 14:14:37 +0100339
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700340 Result<uint32_t> crc = GetPackageCrc(*target_zip);
Mårten Kongstad0f763112018-11-19 14:14:37 +0100341 if (!crc) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100342 return Error(crc.GetError(), "failed to get zip CRC for target");
Mårten Kongstad02751232018-04-27 13:16:32 +0200343 }
Mårten Kongstad0f763112018-11-19 14:14:37 +0100344 header->target_crc_ = *crc;
345
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700346 crc = GetPackageCrc(*overlay_zip);
Mårten Kongstad0f763112018-11-19 14:14:37 +0100347 if (!crc) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100348 return Error(crc.GetError(), "failed to get zip CRC for overlay");
Mårten Kongstad02751232018-04-27 13:16:32 +0200349 }
Mårten Kongstad0f763112018-11-19 14:14:37 +0100350 header->overlay_crc_ = *crc;
Mårten Kongstad02751232018-04-27 13:16:32 +0200351
Ryan Mitchella7070132020-05-13 14:17:52 -0700352 header->fulfilled_policies_ = fulfilled_policies;
353 header->enforce_overlayable_ = enforce_overlayable;
354
Mårten Kongstad02751232018-04-27 13:16:32 +0200355 if (target_apk_path.size() > sizeof(header->target_path_)) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100356 return Error("target apk path \"%s\" longer than maximum size %zu", target_apk_path.c_str(),
357 sizeof(header->target_path_));
Mårten Kongstad02751232018-04-27 13:16:32 +0200358 }
359 memset(header->target_path_, 0, sizeof(header->target_path_));
360 memcpy(header->target_path_, target_apk_path.data(), target_apk_path.size());
361
362 if (overlay_apk_path.size() > sizeof(header->overlay_path_)) {
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700363 return Error("overlay apk path \"%s\" longer than maximum size %zu", overlay_apk_path.c_str(),
Mårten Kongstadce424902019-03-01 08:35:37 +0100364 sizeof(header->target_path_));
Mårten Kongstad02751232018-04-27 13:16:32 +0200365 }
366 memset(header->overlay_path_, 0, sizeof(header->overlay_path_));
367 memcpy(header->overlay_path_, overlay_apk_path.data(), overlay_apk_path.size());
368
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700369 auto overlay_info = utils::ExtractOverlayManifestInfo(overlay_apk_path);
370 if (!overlay_info) {
371 return overlay_info.GetError();
Mårten Kongstad02751232018-04-27 13:16:32 +0200372 }
373
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200374 LogInfo log_info;
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700375 auto resource_mapping =
376 ResourceMapping::FromApkAssets(target_apk_assets, overlay_apk_assets, *overlay_info,
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200377 fulfilled_policies, enforce_overlayable, log_info);
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700378 if (!resource_mapping) {
379 return resource_mapping.GetError();
Ryan Mitchellb863ca32019-03-07 14:31:54 -0800380 }
381
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700382 auto idmap_data = IdmapData::FromResourceMapping(*resource_mapping);
383 if (!idmap_data) {
384 return idmap_data.GetError();
Mårten Kongstad02751232018-04-27 13:16:32 +0200385 }
386
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200387 std::unique_ptr<Idmap> idmap(new Idmap());
388 header->debug_info_ = log_info.GetString();
389 idmap->header_ = std::move(header);
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700390 idmap->data_.push_back(std::move(*idmap_data));
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200391
Mårten Kongstadce424902019-03-01 08:35:37 +0100392 return {std::move(idmap)};
Mårten Kongstad02751232018-04-27 13:16:32 +0200393}
394
395void IdmapHeader::accept(Visitor* v) const {
396 assert(v != nullptr);
397 v->visit(*this);
398}
399
400void IdmapData::Header::accept(Visitor* v) const {
401 assert(v != nullptr);
402 v->visit(*this);
403}
404
Mårten Kongstad02751232018-04-27 13:16:32 +0200405void IdmapData::accept(Visitor* v) const {
406 assert(v != nullptr);
Mårten Kongstad02751232018-04-27 13:16:32 +0200407 header_->accept(v);
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700408 v->visit(*this);
Mårten Kongstad02751232018-04-27 13:16:32 +0200409}
410
411void Idmap::accept(Visitor* v) const {
412 assert(v != nullptr);
Mårten Kongstad02751232018-04-27 13:16:32 +0200413 header_->accept(v);
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700414 v->visit(*this);
Mårten Kongstad02751232018-04-27 13:16:32 +0200415 auto end = data_.cend();
416 for (auto iter = data_.cbegin(); iter != end; ++iter) {
417 (*iter)->accept(v);
418 }
419}
420
Mårten Kongstad0eba72a2018-11-29 08:23:14 +0100421} // namespace android::idmap2