blob: 06650f681b24c5e2d1c1cd292267806180c4677b [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>
Ryan Prichardd9a3ffa2022-08-30 14:24:57 -070020#include <cassert>
Mårten Kongstad02751232018-04-27 13:16:32 +020021#include <iostream>
22#include <iterator>
23#include <limits>
Mårten Kongstad02751232018-04-27 13:16:32 +020024#include <memory>
Mårten Kongstad02751232018-04-27 13:16:32 +020025#include <string>
26#include <utility>
Mårten Kongstad02751232018-04-27 13:16:32 +020027
28#include "android-base/macros.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020029#include "androidfw/AssetManager2.h"
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -070030#include "idmap2/ResourceMapping.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020031#include "idmap2/ResourceUtils.h"
Mårten Kongstad0f763112018-11-19 14:14:37 +010032#include "idmap2/Result.h"
Mårten Kongstad4cbb0072018-11-30 16:22:05 +010033#include "idmap2/SysTrace.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020034
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010035namespace android::idmap2 {
Mårten Kongstad02751232018-04-27 13:16:32 +020036
Mårten Kongstad744ccfe2018-12-20 14:56:14 +010037namespace {
38
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070039bool WARN_UNUSED Read8(std::istream& stream, uint8_t* out) {
40 uint8_t value;
41 if (stream.read(reinterpret_cast<char*>(&value), sizeof(uint8_t))) {
42 *out = value;
Mårten Kongstad02751232018-04-27 13:16:32 +020043 return true;
44 }
45 return false;
46}
47
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070048bool WARN_UNUSED Read16(std::istream& stream, uint16_t* out) {
49 uint16_t value;
50 if (stream.read(reinterpret_cast<char*>(&value), sizeof(uint16_t))) {
51 *out = dtohs(value);
Mårten Kongstad02751232018-04-27 13:16:32 +020052 return true;
53 }
54 return false;
55}
56
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070057bool WARN_UNUSED Read32(std::istream& stream, uint32_t* out) {
58 uint32_t value;
59 if (stream.read(reinterpret_cast<char*>(&value), sizeof(uint32_t))) {
60 *out = dtohl(value);
Ryan Mitchelle753ffe2019-09-23 09:47:02 -070061 return true;
62 }
63 return false;
64}
65
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080066bool WARN_UNUSED ReadString(std::istream& stream, std::string* out) {
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020067 uint32_t size;
68 if (!Read32(stream, &size)) {
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080069 return false;
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020070 }
71 if (size == 0) {
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080072 *out = "";
73 return true;
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020074 }
75 std::string buf(size, '\0');
76 if (!stream.read(buf.data(), size)) {
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080077 return false;
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020078 }
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070079 uint32_t padding_size = CalculatePadding(size);
80 std::string padding(padding_size, '\0');
81 if (!stream.read(padding.data(), padding_size)) {
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080082 return false;
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -070083 }
Ryan Mitchell0699f1d2020-12-03 15:41:42 -080084 *out = buf;
85 return true;
Mårten Kongstadd7e8a532019-10-11 08:32:04 +020086}
87
Ryan Mitchell7d53f192020-04-24 17:45:25 -070088} // namespace
89
Mårten Kongstad02751232018-04-27 13:16:32 +020090std::unique_ptr<const IdmapHeader> IdmapHeader::FromBinaryStream(std::istream& stream) {
91 std::unique_ptr<IdmapHeader> idmap_header(new IdmapHeader());
Ryan Mitchell9289a042021-01-13 17:21:29 -080092 if (!Read32(stream, &idmap_header->magic_) || !Read32(stream, &idmap_header->version_)) {
93 return nullptr;
94 }
95
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -080096 if (idmap_header->magic_ != kIdmapMagic || idmap_header->version_ != kIdmapCurrentVersion) {
Ryan Mitchell9289a042021-01-13 17:21:29 -080097 // Do not continue parsing if the file is not a current version idmap.
98 return nullptr;
99 }
100
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700101 uint32_t enforce_overlayable;
Ryan Mitchell9289a042021-01-13 17:21:29 -0800102 if (!Read32(stream, &idmap_header->target_crc_) || !Read32(stream, &idmap_header->overlay_crc_) ||
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700103 !Read32(stream, &idmap_header->fulfilled_policies_) ||
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800104 !Read32(stream, &enforce_overlayable) || !ReadString(stream, &idmap_header->target_path_) ||
105 !ReadString(stream, &idmap_header->overlay_path_) ||
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800106 !ReadString(stream, &idmap_header->overlay_name_) ||
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800107 !ReadString(stream, &idmap_header->debug_info_)) {
Mårten Kongstad02751232018-04-27 13:16:32 +0200108 return nullptr;
109 }
110
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700111 idmap_header->enforce_overlayable_ = enforce_overlayable != 0U;
Mårten Kongstad02751232018-04-27 13:16:32 +0200112 return std::move(idmap_header);
113}
114
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800115Result<Unit> IdmapHeader::IsUpToDate(const TargetResourceContainer& target,
116 const OverlayResourceContainer& overlay,
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800117 const std::string& overlay_name,
Ryan Mitchell038a2842020-06-08 14:41:07 -0700118 PolicyBitmask fulfilled_policies,
119 bool enforce_overlayable) const {
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800120 const Result<uint32_t> target_crc = target.GetCrc();
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700121 if (!target_crc) {
122 return Error("failed to get target crc");
123 }
124
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800125 const Result<uint32_t> overlay_crc = overlay.GetCrc();
Ryan Mitchella7070132020-05-13 14:17:52 -0700126 if (!overlay_crc) {
127 return Error("failed to get overlay crc");
128 }
129
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800130 return IsUpToDate(target.GetPath(), overlay.GetPath(), overlay_name, *target_crc, *overlay_crc,
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800131 fulfilled_policies, enforce_overlayable);
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700132}
133
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800134Result<Unit> IdmapHeader::IsUpToDate(const std::string& target_path,
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800135 const std::string& overlay_path,
136 const std::string& overlay_name, uint32_t target_crc,
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800137 uint32_t overlay_crc, PolicyBitmask fulfilled_policies,
Ryan Mitchell038a2842020-06-08 14:41:07 -0700138 bool enforce_overlayable) const {
Mårten Kongstad02751232018-04-27 13:16:32 +0200139 if (magic_ != kIdmapMagic) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100140 return Error("bad magic: actual 0x%08x, expected 0x%08x", magic_, kIdmapMagic);
Mårten Kongstad02751232018-04-27 13:16:32 +0200141 }
142
143 if (version_ != kIdmapCurrentVersion) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100144 return Error("bad version: actual 0x%08x, expected 0x%08x", version_, kIdmapCurrentVersion);
Mårten Kongstad02751232018-04-27 13:16:32 +0200145 }
146
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700147 if (target_crc_ != target_crc) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100148 return Error("bad target crc: idmap version 0x%08x, file system version 0x%08x", target_crc_,
Ryan Mitchell7d53f192020-04-24 17:45:25 -0700149 target_crc);
Mårten Kongstad02751232018-04-27 13:16:32 +0200150 }
151
Ryan Mitchella7070132020-05-13 14:17:52 -0700152 if (overlay_crc_ != overlay_crc) {
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100153 return Error("bad overlay crc: idmap version 0x%08x, file system version 0x%08x", overlay_crc_,
Ryan Mitchella7070132020-05-13 14:17:52 -0700154 overlay_crc);
155 }
156
157 if (fulfilled_policies_ != fulfilled_policies) {
158 return Error("bad fulfilled policies: idmap version 0x%08x, file system version 0x%08x",
159 fulfilled_policies, fulfilled_policies_);
160 }
161
162 if (enforce_overlayable != enforce_overlayable_) {
163 return Error("bad enforce overlayable: idmap version %s, file system version %s",
Ryan Mitchell038a2842020-06-08 14:41:07 -0700164 enforce_overlayable ? "true" : "false", enforce_overlayable_ ? "true" : "false");
Ryan Mitchella7070132020-05-13 14:17:52 -0700165 }
166
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800167 if (target_path != target_path_) {
168 return Error("bad target path: idmap version %s, file system version %s", target_path.c_str(),
169 target_path_.c_str());
Ryan Mitchella7070132020-05-13 14:17:52 -0700170 }
171
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800172 if (overlay_path != overlay_path_) {
173 return Error("bad overlay path: idmap version %s, file system version %s", overlay_path.c_str(),
174 overlay_path_.c_str());
Mårten Kongstad02751232018-04-27 13:16:32 +0200175 }
176
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800177 if (overlay_name != overlay_name_) {
178 return Error("bad overlay name: idmap version %s, file system version %s", overlay_name.c_str(),
179 overlay_name_.c_str());
180 }
181
Mårten Kongstad0c6ff1d2019-02-07 02:21:56 +0100182 return Unit{};
Mårten Kongstad02751232018-04-27 13:16:32 +0200183}
184
185std::unique_ptr<const IdmapData::Header> IdmapData::Header::FromBinaryStream(std::istream& stream) {
186 std::unique_ptr<IdmapData::Header> idmap_data_header(new IdmapData::Header());
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800187 if (!Read32(stream, &idmap_data_header->target_entry_count) ||
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700188 !Read32(stream, &idmap_data_header->target_entry_inline_count) ||
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700189 !Read32(stream, &idmap_data_header->overlay_entry_count) ||
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700190 !Read32(stream, &idmap_data_header->string_pool_index_offset)) {
Mårten Kongstad02751232018-04-27 13:16:32 +0200191 return nullptr;
192 }
Mårten Kongstad02751232018-04-27 13:16:32 +0200193
194 return std::move(idmap_data_header);
195}
196
Mårten Kongstad02751232018-04-27 13:16:32 +0200197std::unique_ptr<const IdmapData> IdmapData::FromBinaryStream(std::istream& stream) {
198 std::unique_ptr<IdmapData> data(new IdmapData());
199 data->header_ = IdmapData::Header::FromBinaryStream(stream);
200 if (!data->header_) {
201 return nullptr;
202 }
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700203
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700204 // Read the mapping of target resource id to overlay resource value.
205 for (size_t i = 0; i < data->header_->GetTargetEntryCount(); i++) {
206 TargetEntry target_entry{};
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700207 if (!Read32(stream, &target_entry.target_id) || !Read32(stream, &target_entry.overlay_id)) {
Mårten Kongstad02751232018-04-27 13:16:32 +0200208 return nullptr;
209 }
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700210 data->target_entries_.push_back(target_entry);
211 }
212
213 // Read the mapping of target resource id to inline overlay values.
214 uint8_t unused1;
215 uint16_t unused2;
216 for (size_t i = 0; i < data->header_->GetTargetInlineEntryCount(); i++) {
217 TargetInlineEntry target_entry{};
218 if (!Read32(stream, &target_entry.target_id) || !Read16(stream, &unused2) ||
219 !Read8(stream, &unused1) || !Read8(stream, &target_entry.value.data_type) ||
220 !Read32(stream, &target_entry.value.data_value)) {
221 return nullptr;
222 }
223 data->target_inline_entries_.push_back(target_entry);
Mårten Kongstad02751232018-04-27 13:16:32 +0200224 }
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700225
226 // Read the mapping of overlay resource id to target resource id.
227 for (size_t i = 0; i < data->header_->GetOverlayEntryCount(); i++) {
228 OverlayEntry overlay_entry{};
229 if (!Read32(stream, &overlay_entry.overlay_id) || !Read32(stream, &overlay_entry.target_id)) {
230 return nullptr;
231 }
232 data->overlay_entries_.emplace_back(overlay_entry);
233 }
234
235 // Read raw string pool bytes.
Ryan Mitchell0699f1d2020-12-03 15:41:42 -0800236 if (!ReadString(stream, &data->string_pool_data_)) {
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700237 return nullptr;
238 }
Mårten Kongstad02751232018-04-27 13:16:32 +0200239 return std::move(data);
240}
241
242std::string Idmap::CanonicalIdmapPathFor(const std::string& absolute_dir,
243 const std::string& absolute_apk_path) {
244 assert(absolute_dir.size() > 0 && absolute_dir[0] == "/");
245 assert(absolute_apk_path.size() > 0 && absolute_apk_path[0] == "/");
246 std::string copy(++absolute_apk_path.cbegin(), absolute_apk_path.cend());
247 replace(copy.begin(), copy.end(), '/', '@');
248 return absolute_dir + "/" + copy + "@idmap";
249}
250
Mårten Kongstadce424902019-03-01 08:35:37 +0100251Result<std::unique_ptr<const Idmap>> Idmap::FromBinaryStream(std::istream& stream) {
Mårten Kongstad4cbb0072018-11-30 16:22:05 +0100252 SYSTRACE << "Idmap::FromBinaryStream";
Mårten Kongstad02751232018-04-27 13:16:32 +0200253 std::unique_ptr<Idmap> idmap(new Idmap());
254
255 idmap->header_ = IdmapHeader::FromBinaryStream(stream);
256 if (!idmap->header_) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100257 return Error("failed to parse idmap header");
Mårten Kongstad02751232018-04-27 13:16:32 +0200258 }
259
260 // idmap version 0x01 does not specify the number of data blocks that follow
261 // the idmap header; assume exactly one data block
262 for (int i = 0; i < 1; i++) {
263 std::unique_ptr<const IdmapData> data = IdmapData::FromBinaryStream(stream);
264 if (!data) {
Mårten Kongstadce424902019-03-01 08:35:37 +0100265 return Error("failed to parse data block %d", i);
Mårten Kongstad02751232018-04-27 13:16:32 +0200266 }
267 idmap->data_.push_back(std::move(data));
268 }
269
Mårten Kongstadce424902019-03-01 08:35:37 +0100270 return {std::move(idmap)};
Mårten Kongstad02751232018-04-27 13:16:32 +0200271}
272
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700273Result<std::unique_ptr<const IdmapData>> IdmapData::FromResourceMapping(
274 const ResourceMapping& resource_mapping) {
275 if (resource_mapping.GetTargetToOverlayMap().empty()) {
276 return Error("no resources were overlaid");
277 }
278
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700279 std::unique_ptr<IdmapData> data(new IdmapData());
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700280 data->string_pool_data_ = resource_mapping.GetStringPoolData().to_string();
281 for (const auto& mapping : resource_mapping.GetTargetToOverlayMap()) {
282 if (auto overlay_resource = std::get_if<ResourceId>(&mapping.second)) {
283 data->target_entries_.push_back({mapping.first, *overlay_resource});
284 } else {
285 data->target_inline_entries_.push_back(
286 {mapping.first, std::get<TargetValue>(mapping.second)});
287 }
Ryan Mitchell4c09a4a2019-03-08 08:57:48 -0800288 }
289
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700290 for (const auto& mapping : resource_mapping.GetOverlayToTargetMap()) {
291 data->overlay_entries_.emplace_back(IdmapData::OverlayEntry{mapping.first, mapping.second});
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700292 }
293
294 std::unique_ptr<IdmapData::Header> data_header(new IdmapData::Header());
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700295 data_header->target_entry_count = static_cast<uint32_t>(data->target_entries_.size());
Ryan Mitchellbf1f45b2020-09-29 17:22:52 -0700296 data_header->target_entry_inline_count =
297 static_cast<uint32_t>(data->target_inline_entries_.size());
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700298 data_header->overlay_entry_count = static_cast<uint32_t>(data->overlay_entries_.size());
299 data_header->string_pool_index_offset = resource_mapping.GetStringPoolOffset();
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700300 data->header_ = std::move(data_header);
301 return {std::move(data)};
Ryan Mitchell4c09a4a2019-03-08 08:57:48 -0800302}
303
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800304Result<std::unique_ptr<const Idmap>> Idmap::FromContainers(const TargetResourceContainer& target,
305 const OverlayResourceContainer& overlay,
306 const std::string& overlay_name,
307 const PolicyBitmask& fulfilled_policies,
308 bool enforce_overlayable) {
Mårten Kongstad4cbb0072018-11-30 16:22:05 +0100309 SYSTRACE << "Idmap::FromApkAssets";
Mårten Kongstad02751232018-04-27 13:16:32 +0200310 std::unique_ptr<IdmapHeader> header(new IdmapHeader());
311 header->magic_ = kIdmapMagic;
312 header->version_ = kIdmapCurrentVersion;
Mårten Kongstad0f763112018-11-19 14:14:37 +0100313
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800314 const auto target_crc = target.GetCrc();
315 if (!target_crc) {
316 return Error(target_crc.GetError(), "failed to get zip CRC for '%s'", target.GetPath().data());
Mårten Kongstad02751232018-04-27 13:16:32 +0200317 }
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800318 header->target_crc_ = *target_crc;
Mårten Kongstad0f763112018-11-19 14:14:37 +0100319
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800320 const auto overlay_crc = overlay.GetCrc();
321 if (!overlay_crc) {
322 return Error(overlay_crc.GetError(), "failed to get zip CRC for '%s'",
323 overlay.GetPath().data());
Mårten Kongstad02751232018-04-27 13:16:32 +0200324 }
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800325 header->overlay_crc_ = *overlay_crc;
326
Ryan Mitchella7070132020-05-13 14:17:52 -0700327 header->fulfilled_policies_ = fulfilled_policies;
328 header->enforce_overlayable_ = enforce_overlayable;
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800329 header->target_path_ = target.GetPath();
330 header->overlay_path_ = overlay.GetPath();
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800331 header->overlay_name_ = overlay_name;
Mårten Kongstad02751232018-04-27 13:16:32 +0200332
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800333 auto info = overlay.FindOverlayInfo(overlay_name);
Ryan Mitchell30dc2e02020-12-02 11:43:18 -0800334 if (!info) {
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800335 return Error(info.GetError(), "failed to get overlay info for '%s'", overlay.GetPath().data());
Mårten Kongstad02751232018-04-27 13:16:32 +0200336 }
337
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200338 LogInfo log_info;
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800339 auto resource_mapping = ResourceMapping::FromContainers(
340 target, overlay, *info, fulfilled_policies, enforce_overlayable, log_info);
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700341 if (!resource_mapping) {
Ryan Mitchell2ed8bfa2021-01-08 13:34:28 -0800342 return Error(resource_mapping.GetError(), "failed to generate resource map for '%s'",
343 overlay.GetPath().data());
Ryan Mitchellb863ca32019-03-07 14:31:54 -0800344 }
345
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700346 auto idmap_data = IdmapData::FromResourceMapping(*resource_mapping);
347 if (!idmap_data) {
348 return idmap_data.GetError();
Mårten Kongstad02751232018-04-27 13:16:32 +0200349 }
350
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200351 std::unique_ptr<Idmap> idmap(new Idmap());
352 header->debug_info_ = log_info.GetString();
353 idmap->header_ = std::move(header);
Ryan Mitchell9e4f52b2019-09-19 12:15:52 -0700354 idmap->data_.push_back(std::move(*idmap_data));
Mårten Kongstadd7e8a532019-10-11 08:32:04 +0200355
Mårten Kongstadce424902019-03-01 08:35:37 +0100356 return {std::move(idmap)};
Mårten Kongstad02751232018-04-27 13:16:32 +0200357}
358
359void IdmapHeader::accept(Visitor* v) const {
360 assert(v != nullptr);
361 v->visit(*this);
362}
363
364void IdmapData::Header::accept(Visitor* v) const {
365 assert(v != nullptr);
366 v->visit(*this);
367}
368
Mårten Kongstad02751232018-04-27 13:16:32 +0200369void IdmapData::accept(Visitor* v) const {
370 assert(v != nullptr);
Mårten Kongstad02751232018-04-27 13:16:32 +0200371 header_->accept(v);
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700372 v->visit(*this);
Mårten Kongstad02751232018-04-27 13:16:32 +0200373}
374
375void Idmap::accept(Visitor* v) const {
376 assert(v != nullptr);
Mårten Kongstad02751232018-04-27 13:16:32 +0200377 header_->accept(v);
Ryan Mitchelle753ffe2019-09-23 09:47:02 -0700378 v->visit(*this);
Mårten Kongstad02751232018-04-27 13:16:32 +0200379 auto end = data_.cend();
380 for (auto iter = data_.cbegin(); iter != end; ++iter) {
381 (*iter)->accept(v);
382 }
383}
384
Mårten Kongstad0eba72a2018-11-29 08:23:14 +0100385} // namespace android::idmap2