blob: 97514599c0b183bcc277188cbfafc25d88d8c1e6 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 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
Adam Lesinskicacb28f2016-10-19 12:18:14 -070017#include "ResourceTable.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080018
Adam Lesinskicacb28f2016-10-19 12:18:14 -070019#include <algorithm>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020#include <memory>
Ryan Mitchell4382e442021-07-14 12:53:01 -070021#include <optional>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080022#include <tuple>
23
Adam Lesinski66ea8402017-06-28 11:44:11 -070024#include "android-base/logging.h"
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020025#include "androidfw/ConfigDescription.h"
Adam Lesinski66ea8402017-06-28 11:44:11 -070026#include "androidfw/ResourceTypes.h"
27
Adam Lesinski66ea8402017-06-28 11:44:11 -070028#include "NameMangler.h"
Ryan Mitchell9634efb2021-03-19 14:53:17 -070029#include "ResourceUtils.h"
Adam Lesinski66ea8402017-06-28 11:44:11 -070030#include "ResourceValues.h"
31#include "ValueVisitor.h"
32#include "text/Unicode.h"
Ryan Mitchell9634efb2021-03-19 14:53:17 -070033#include "trace/TraceBuffer.h"
Adam Lesinski66ea8402017-06-28 11:44:11 -070034#include "util/Util.h"
35
36using ::aapt::text::IsValidResourceEntryName;
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020037using ::android::ConfigDescription;
Adam Lesinski66ea8402017-06-28 11:44:11 -070038using ::android::StringPiece;
Adam Lesinski71be7052017-12-12 16:48:07 -080039using ::android::base::StringPrintf;
Adam Lesinskid5083f62017-01-16 15:07:21 -080040
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080041namespace aapt {
42
Ryan Mitchell54237ff2018-12-13 15:44:29 -080043const char* Overlayable::kActorScheme = "overlay";
44
Ryan Mitchell9634efb2021-03-19 14:53:17 -070045namespace {
Iurii Makhnof0c5ff42022-02-22 13:31:02 +000046bool less_than_type(const std::unique_ptr<ResourceTableType>& lhs,
47 const ResourceNamedTypeRef& rhs) {
48 return lhs->named_type < rhs;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080049}
50
Adam Lesinski1ab598f2015-08-14 14:26:04 -070051template <typename T>
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070052bool less_than_struct_with_name(const std::unique_ptr<T>& lhs, StringPiece rhs) {
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -070053 return lhs->name < rhs;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080054}
55
David Chaloupkae3c1a4a2018-01-18 13:44:36 +000056template <typename T>
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070057bool greater_than_struct_with_name(StringPiece lhs, const std::unique_ptr<T>& rhs) {
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -070058 return rhs->name > lhs;
David Chaloupkae3c1a4a2018-01-18 13:44:36 +000059}
60
Ryan Mitchell9634efb2021-03-19 14:53:17 -070061template <typename T>
62struct NameEqualRange {
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070063 bool operator()(const std::unique_ptr<T>& lhs, StringPiece rhs) const {
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -070064 return less_than_struct_with_name(lhs, rhs);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070065 }
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070066 bool operator()(StringPiece lhs, const std::unique_ptr<T>& rhs) const {
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -070067 return greater_than_struct_with_name(lhs, rhs);
Ryan Mitchell9634efb2021-03-19 14:53:17 -070068 }
69};
70
71template <typename T, typename U>
72bool less_than_struct_with_name_and_id(const T& lhs,
Ryan Mitchell4382e442021-07-14 12:53:01 -070073 const std::pair<std::string_view, std::optional<U>>& rhs) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -070074 if (lhs.id != rhs.second) {
75 return lhs.id < rhs.second;
76 }
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -070077 return lhs.name < rhs.first;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080078}
79
Ryan Mitchell9634efb2021-03-19 14:53:17 -070080template <typename T, typename Func, typename Elements>
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070081T* FindElementsRunAction(android::StringPiece name, Elements& entries, Func action) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -070082 const auto iter =
83 std::lower_bound(entries.begin(), entries.end(), name, less_than_struct_with_name<T>);
84 const bool found = iter != entries.end() && name == (*iter)->name;
85 return action(found, iter);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080086}
87
Ryan Mitchell2fedba92021-04-23 07:47:38 -070088struct ConfigKey {
89 const ConfigDescription* config;
Yurii Zubrytskyia5775142022-11-02 17:49:49 -070090 StringPiece product;
Ryan Mitchell2fedba92021-04-23 07:47:38 -070091};
92
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -070093struct lt_config_key_ref {
94 template <typename T>
95 bool operator()(const T& lhs, const ConfigKey& rhs) const noexcept {
96 int cmp = lhs->config.compare(*rhs.config);
97 if (cmp == 0) {
98 cmp = lhs->product.compare(rhs.product);
99 }
100 return cmp < 0;
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700101 }
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700102};
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700103
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700104} // namespace
David Chaloupkae3c1a4a2018-01-18 13:44:36 +0000105
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700106ResourceTable::ResourceTable(ResourceTable::Validation validation) : validation_(validation) {
David Chaloupkae3c1a4a2018-01-18 13:44:36 +0000107}
108
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700109ResourceTablePackage* ResourceTable::FindPackage(android::StringPiece name) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700110 return FindElementsRunAction<ResourceTablePackage>(
111 name, packages, [&](bool found, auto& iter) { return found ? iter->get() : nullptr; });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700112}
113
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700114ResourceTablePackage* ResourceTable::FindOrCreatePackage(android::StringPiece name) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700115 return FindElementsRunAction<ResourceTablePackage>(name, packages, [&](bool found, auto& iter) {
116 return found ? iter->get() : packages.emplace(iter, new ResourceTablePackage(name))->get();
117 });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700118}
119
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700120template <typename Func, typename Elements>
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000121static ResourceTableType* FindTypeRunAction(const ResourceNamedTypeRef& type, Elements& entries,
122 Func action) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700123 const auto iter = std::lower_bound(entries.begin(), entries.end(), type, less_than_type);
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000124 const bool found = iter != entries.end() && type == (*iter)->named_type;
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700125 return action(found, iter);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700126}
127
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000128ResourceTableType* ResourceTablePackage::FindTypeWithDefaultName(const ResourceType type) const {
129 auto named_type = ResourceNamedTypeWithDefaultName(type);
130 return FindType(named_type);
131}
132
133ResourceTableType* ResourceTablePackage::FindType(const ResourceNamedTypeRef& type) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700134 return FindTypeRunAction(type, types,
135 [&](bool found, auto& iter) { return found ? iter->get() : nullptr; });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700136}
137
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000138ResourceTableType* ResourceTablePackage::FindOrCreateType(const ResourceNamedTypeRef& type) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700139 return FindTypeRunAction(type, types, [&](bool found, auto& iter) {
140 return found ? iter->get() : types.emplace(iter, new ResourceTableType(type))->get();
141 });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700142}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800143
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700144ResourceEntry* ResourceTableType::CreateEntry(android::StringPiece name) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700145 return FindElementsRunAction<ResourceEntry>(name, entries, [&](bool found, auto& iter) {
146 return entries.emplace(iter, new ResourceEntry(name))->get();
147 });
148}
149
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700150ResourceEntry* ResourceTableType::FindEntry(android::StringPiece name) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700151 return FindElementsRunAction<ResourceEntry>(
152 name, entries, [&](bool found, auto& iter) { return found ? iter->get() : nullptr; });
153}
154
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700155ResourceEntry* ResourceTableType::FindOrCreateEntry(android::StringPiece name) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700156 return FindElementsRunAction<ResourceEntry>(name, entries, [&](bool found, auto& iter) {
157 return found ? iter->get() : entries.emplace(iter, new ResourceEntry(name))->get();
158 });
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800159}
160
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700161ResourceConfigValue* ResourceEntry::FindValue(const ConfigDescription& config,
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700162 android::StringPiece product) {
163 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700164 lt_config_key_ref());
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700165 if (iter != values.end()) {
166 ResourceConfigValue* value = iter->get();
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700167 if (value->config == config && value->product == product) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700168 return value;
169 }
170 }
171 return nullptr;
172}
173
174const ResourceConfigValue* ResourceEntry::FindValue(const android::ConfigDescription& config,
175 android::StringPiece product) const {
Adam Lesinski34a16872018-02-23 16:18:10 -0800176 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700177 lt_config_key_ref());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700178 if (iter != values.end()) {
179 ResourceConfigValue* value = iter->get();
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700180 if (value->config == config && value->product == product) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700181 return value;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800182 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700183 }
184 return nullptr;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800185}
186
Adam Lesinskib1afa072017-03-29 13:52:38 -0700187ResourceConfigValue* ResourceEntry::FindOrCreateValue(const ConfigDescription& config,
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700188 StringPiece product) {
Adam Lesinski34a16872018-02-23 16:18:10 -0800189 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700190 lt_config_key_ref());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700191 if (iter != values.end()) {
192 ResourceConfigValue* value = iter->get();
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700193 if (value->config == config && value->product == product) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700194 return value;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800195 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700196 }
197 ResourceConfigValue* newValue =
Adam Lesinskib1afa072017-03-29 13:52:38 -0700198 values.insert(iter, util::make_unique<ResourceConfigValue>(config, product))->get();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700199 return newValue;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800200}
201
Adam Lesinskib1afa072017-03-29 13:52:38 -0700202std::vector<ResourceConfigValue*> ResourceEntry::FindAllValues(const ConfigDescription& config) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700203 std::vector<ResourceConfigValue*> results;
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700204 auto iter =
205 std::lower_bound(values.begin(), values.end(), ConfigKey{&config, ""}, lt_config_key_ref());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700206 for (; iter != values.end(); ++iter) {
207 ResourceConfigValue* value = iter->get();
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700208 if (value->config != config) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700209 break;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800210 }
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700211 results.push_back(value);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700212 }
213 return results;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800214}
215
Adam Lesinski34a16872018-02-23 16:18:10 -0800216bool ResourceEntry::HasDefaultValue() const {
Adam Lesinski34a16872018-02-23 16:18:10 -0800217 // The default config should be at the top of the list, since the list is sorted.
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700218 return !values.empty() && values.front()->config == ConfigDescription::DefaultConfig();
Adam Lesinski458b8772016-04-25 14:20:21 -0700219}
220
Jeremy Meyer211bec22024-06-04 14:22:03 -0700221ResourceTable::CollisionResult ResourceTable::ResolveFlagCollision(FlagStatus existing,
222 FlagStatus incoming) {
223 switch (existing) {
224 case FlagStatus::NoFlag:
225 switch (incoming) {
226 case FlagStatus::NoFlag:
227 return CollisionResult::kConflict;
228 case FlagStatus::Disabled:
229 return CollisionResult::kKeepOriginal;
230 case FlagStatus::Enabled:
231 return CollisionResult::kTakeNew;
232 default:
233 return CollisionResult::kConflict;
234 }
235 case FlagStatus::Disabled:
236 switch (incoming) {
237 case FlagStatus::NoFlag:
238 return CollisionResult::kTakeNew;
239 case FlagStatus::Disabled:
240 return CollisionResult::kKeepOriginal;
241 case FlagStatus::Enabled:
242 return CollisionResult::kTakeNew;
243 default:
244 return CollisionResult::kConflict;
245 }
246 case FlagStatus::Enabled:
247 switch (incoming) {
248 case FlagStatus::NoFlag:
249 return CollisionResult::kKeepOriginal;
250 case FlagStatus::Disabled:
251 return CollisionResult::kKeepOriginal;
252 case FlagStatus::Enabled:
253 return CollisionResult::kConflict;
254 default:
255 return CollisionResult::kConflict;
256 }
257 default:
258 return CollisionResult::kConflict;
259 }
260}
261
Adam Lesinski71be7052017-12-12 16:48:07 -0800262// The default handler for collisions.
263//
264// Typically, a weak value will be overridden by a strong value. An existing weak
265// value will not be overridden by an incoming weak value.
266//
267// There are some exceptions:
268//
269// Attributes: There are two types of Attribute values: USE and DECL.
270//
271// USE is anywhere an Attribute is declared without a format, and in a place that would
272// be legal to declare if the Attribute already existed. This is typically in a
273// <declare-styleable> tag. Attributes defined in a <declare-styleable> are also weak.
274//
275// DECL is an absolute declaration of an Attribute and specifies an explicit format.
276//
277// A DECL will override a USE without error. Two DECLs must match in their format for there to be
278// no error.
Adam Lesinskib1afa072017-03-29 13:52:38 -0700279ResourceTable::CollisionResult ResourceTable::ResolveValueCollision(Value* existing,
280 Value* incoming) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700281 Attribute* existing_attr = ValueCast<Attribute>(existing);
282 Attribute* incoming_attr = ValueCast<Attribute>(incoming);
283 if (!incoming_attr) {
284 if (incoming->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700285 // We're trying to add a weak resource but a resource
286 // already exists. Keep the existing.
287 return CollisionResult::kKeepOriginal;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700288 } else if (existing->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700289 // Override the weak resource with the new strong resource.
290 return CollisionResult::kTakeNew;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800291 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700292 // The existing and incoming values are strong, this is an error
293 // if the values are not both attributes.
Adam Lesinski5c3464c2016-08-24 16:03:48 -0700294 return CollisionResult::kConflict;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700295 }
296
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700297 if (!existing_attr) {
298 if (existing->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700299 // The existing value is not an attribute and it is weak,
300 // so take the incoming attribute value.
301 return CollisionResult::kTakeNew;
302 }
303 // The existing value is not an attribute and it is strong,
304 // so the incoming attribute value is an error.
305 return CollisionResult::kConflict;
306 }
307
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700308 CHECK(incoming_attr != nullptr && existing_attr != nullptr);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700309
310 //
311 // Attribute specific handling. At this point we know both
312 // values are attributes. Since we can declare and define
313 // attributes all-over, we do special handling to see
314 // which definition sticks.
315 //
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800316 if (existing_attr->IsCompatibleWith(*incoming_attr)) {
317 // The two attributes are both DECLs, but they are plain attributes with compatible formats.
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700318 // Keep the strongest one.
Adam Lesinskib1afa072017-03-29 13:52:38 -0700319 return existing_attr->IsWeak() ? CollisionResult::kTakeNew : CollisionResult::kKeepOriginal;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700320 }
321
Adam Lesinskib1afa072017-03-29 13:52:38 -0700322 if (existing_attr->IsWeak() && existing_attr->type_mask == android::ResTable_map::TYPE_ANY) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700323 // Any incoming attribute is better than this.
324 return CollisionResult::kTakeNew;
325 }
326
Adam Lesinskib1afa072017-03-29 13:52:38 -0700327 if (incoming_attr->IsWeak() && incoming_attr->type_mask == android::ResTable_map::TYPE_ANY) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700328 // The incoming attribute may be a USE instead of a DECL.
329 // Keep the existing attribute.
330 return CollisionResult::kKeepOriginal;
331 }
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700332
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700333 return CollisionResult::kConflict;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800334}
335
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700336namespace {
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700337template <typename T, typename Comparer>
338struct SortedVectorInserter : public Comparer {
339 std::pair<bool, typename std::vector<T>::iterator> LowerBound(std::vector<T>& el,
340 const T& value) {
341 auto it = std::lower_bound(el.begin(), el.end(), value, [&](auto& lhs, auto& rhs) {
342 return Comparer::operator()(lhs, rhs);
343 });
344 bool found =
345 it != el.end() && !Comparer::operator()(*it, value) && !Comparer::operator()(value, *it);
346 return std::make_pair(found, it);
347 }
348
349 T* Insert(std::vector<T>& el, T&& value) {
350 auto [found, it] = LowerBound(el, value);
351 if (found) {
352 return &*it;
353 }
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700354 return &*el.insert(it, std::move(value));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700355 }
356};
357
358struct PackageViewComparer {
359 bool operator()(const ResourceTablePackageView& lhs, const ResourceTablePackageView& rhs) {
360 return less_than_struct_with_name_and_id<ResourceTablePackageView, uint8_t>(
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700361 lhs, std::tie(rhs.name, rhs.id));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700362 }
363};
364
365struct TypeViewComparer {
366 bool operator()(const ResourceTableTypeView& lhs, const ResourceTableTypeView& rhs) {
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000367 return lhs.id != rhs.id ? lhs.id < rhs.id : lhs.named_type < rhs.named_type;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700368 }
369};
370
371struct EntryViewComparer {
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700372 bool operator()(const ResourceTableEntryView& lhs, const ResourceTableEntryView& rhs) {
373 return less_than_struct_with_name_and_id<ResourceTableEntryView, uint16_t>(
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700374 lhs, std::tie(rhs.name, rhs.id));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700375 }
376};
377
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700378void InsertEntryIntoTableView(ResourceTableView& table, const ResourceTablePackage* package,
379 const ResourceTableType* type, const std::string& entry_name,
Ryan Mitchell4382e442021-07-14 12:53:01 -0700380 const std::optional<ResourceId>& id, const Visibility& visibility,
381 const std::optional<AllowNew>& allow_new,
382 const std::optional<OverlayableItem>& overlayable_item,
383 const std::optional<StagedId>& staged_id,
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700384 const std::vector<std::unique_ptr<ResourceConfigValue>>& values) {
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700385 SortedVectorInserter<ResourceTablePackageView, PackageViewComparer> package_inserter;
386 SortedVectorInserter<ResourceTableTypeView, TypeViewComparer> type_inserter;
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700387 SortedVectorInserter<ResourceTableEntryView, EntryViewComparer> entry_inserter;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700388
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700389 ResourceTablePackageView new_package{package->name,
Ryan Mitchell4382e442021-07-14 12:53:01 -0700390 id ? id.value().package_id() : std::optional<uint8_t>{}};
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700391 auto view_package = package_inserter.Insert(table.packages, std::move(new_package));
392
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000393 ResourceTableTypeView new_type{type->named_type,
394 id ? id.value().type_id() : std::optional<uint8_t>{}};
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700395 auto view_type = type_inserter.Insert(view_package->types, std::move(new_type));
396
397 if (visibility.level == Visibility::Level::kPublic) {
398 // Only mark the type visibility level as public, it doesn't care about being private.
399 view_type->visibility_level = Visibility::Level::kPublic;
400 }
401
402 ResourceTableEntryView new_entry{.name = entry_name,
Ryan Mitchell4382e442021-07-14 12:53:01 -0700403 .id = id ? id.value().entry_id() : std::optional<uint16_t>{},
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700404 .visibility = visibility,
405 .allow_new = allow_new,
406 .overlayable_item = overlayable_item,
407 .staged_id = staged_id};
408 for (auto& value : values) {
409 new_entry.values.emplace_back(value.get());
410 }
411
412 entry_inserter.Insert(view_type->entries, std::move(new_entry));
413}
414} // namespace
415
416const ResourceConfigValue* ResourceTableEntryView::FindValue(const ConfigDescription& config,
417 android::StringPiece product) const {
418 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700419 lt_config_key_ref());
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700420 if (iter != values.end()) {
421 const ResourceConfigValue* value = *iter;
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700422 if (value->config == config && value->product == product) {
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700423 return value;
424 }
425 }
426 return nullptr;
427}
428
429ResourceTableView ResourceTable::GetPartitionedView(const ResourceTableViewOptions& options) const {
430 ResourceTableView view;
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700431 for (const auto& package : packages) {
432 for (const auto& type : package->types) {
433 for (const auto& entry : type->entries) {
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700434 InsertEntryIntoTableView(view, package.get(), type.get(), entry->name, entry->id,
435 entry->visibility, entry->allow_new, entry->overlayable_item,
436 entry->staged_id, entry->values);
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700437
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700438 if (options.create_alias_entries && entry->staged_id) {
439 auto alias_id = entry->staged_id.value().id;
440 InsertEntryIntoTableView(view, package.get(), type.get(), entry->name, alias_id,
441 entry->visibility, entry->allow_new, entry->overlayable_item, {},
442 entry->values);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700443 }
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700444 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800445 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700446 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800447
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700448 // The android runtime does not support querying resources when the there are multiple type ids
449 // for the same resource type within the same package. For this reason, if there are types with
450 // multiple type ids, each type needs to exist in its own package in order to be queried by name.
451 std::vector<ResourceTablePackageView> new_packages;
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700452 SortedVectorInserter<ResourceTablePackageView, PackageViewComparer> package_inserter;
453 SortedVectorInserter<ResourceTableTypeView, TypeViewComparer> type_inserter;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700454 for (auto& package : view.packages) {
455 // If a new package was already created for a different type within this package, then
456 // we can reuse those packages for other types that need to be extracted from this package.
457 // `start_index` is the index of the first newly created package that can be reused.
458 const size_t start_index = new_packages.size();
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000459 std::map<ResourceNamedType, size_t> type_new_package_index;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700460 for (auto type_it = package.types.begin(); type_it != package.types.end();) {
461 auto& type = *type_it;
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000462 auto type_index_iter = type_new_package_index.find(type.named_type);
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700463 if (type_index_iter == type_new_package_index.end()) {
464 // First occurrence of the resource type in this package. Keep it in this package.
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000465 type_new_package_index.insert(type_index_iter,
466 std::make_pair(type.named_type, start_index));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700467 ++type_it;
468 continue;
469 }
470
471 // The resource type has already been seen for this package, so this type must be extracted to
472 // a new separate package.
473 const size_t index = type_index_iter->second;
474 if (new_packages.size() == index) {
475 new_packages.emplace_back(ResourceTablePackageView{package.name, package.id});
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700476 }
477
478 // Move the type into a new package
479 auto& other_package = new_packages[index];
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000480 type_new_package_index[type.named_type] = index + 1;
Greg Kaiserb40f3ab2021-10-18 06:37:26 -0700481 type_inserter.Insert(other_package.types, std::move(type));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700482 type_it = package.types.erase(type_it);
483 }
484 }
485
486 for (auto& new_package : new_packages) {
487 // Insert newly created packages after their original packages
488 auto [_, it] = package_inserter.LowerBound(view.packages, new_package);
489 view.packages.insert(++it, std::move(new_package));
490 }
491
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700492 return view;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800493}
494
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000495bool ResourceTable::AddResource(NewResource&& res, android::IDiagnostics* diag) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700496 CHECK(diag != nullptr) << "Diagnostic pointer is null";
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700497
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700498 const bool validate = validation_ == Validation::kEnabled;
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000499 const android::Source source = res.value ? res.value->GetSource() : android::Source{};
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700500 if (validate && !res.allow_mangled && !IsValidResourceEntryName(res.name.entry)) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000501 diag->Error(android::DiagMessage(source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700502 << "resource '" << res.name << "' has invalid entry name '" << res.name.entry);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700503 return false;
504 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800505
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700506 if (res.id.has_value() && !res.id->first.is_valid()) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000507 diag->Error(android::DiagMessage(source)
508 << "trying to add resource '" << res.name << "' with ID " << res.id->first
509 << " but that ID is invalid");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700510 return false;
511 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700512
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700513 auto package = FindOrCreatePackage(res.name.package);
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000514 auto type = package->FindOrCreateType(res.name.type);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700515 auto entry_it = std::equal_range(type->entries.begin(), type->entries.end(), res.name.entry,
516 NameEqualRange<ResourceEntry>{});
517 const size_t entry_count = std::distance(entry_it.first, entry_it.second);
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700518
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700519 ResourceEntry* entry;
520 if (entry_count == 0) {
521 // Adding a new resource
522 entry = type->CreateEntry(res.name.entry);
523 } else if (entry_count == 1) {
524 // Assume that the existing resource is being modified
525 entry = entry_it.first->get();
526 } else {
527 // Multiple resources with the same name exist in the resource table. The only way to
528 // distinguish between them is using resource id since each resource should have a unique id.
529 CHECK(res.id.has_value()) << "ambiguous modification of resource entry '" << res.name
530 << "' without specifying a resource id.";
531 entry = entry_it.first->get();
532 for (auto it = entry_it.first; it != entry_it.second; ++it) {
533 CHECK((bool)(*it)->id) << "ambiguous modification of resource entry '" << res.name
534 << "' with multiple entries without resource ids";
535 if ((*it)->id == res.id->first) {
536 entry = it->get();
537 break;
538 }
539 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700540 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800541
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700542 if (res.id.has_value()) {
543 if (entry->id && entry->id.value() != res.id->first) {
544 if (res.id->second != OnIdConflict::CREATE_ENTRY) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000545 diag->Error(android::DiagMessage(source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700546 << "trying to add resource '" << res.name << "' with ID " << res.id->first
547 << " but resource already has ID " << entry->id.value());
548 return false;
549 }
550 entry = type->CreateEntry(res.name.entry);
551 }
552 entry->id = res.id->first;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700553 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800554
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700555 if (res.visibility.has_value()) {
556 // Only mark the type visibility level as public, it doesn't care about being private.
557 if (res.visibility->level == Visibility::Level::kPublic) {
558 type->visibility_level = Visibility::Level::kPublic;
559 }
560
561 if (res.visibility->level > entry->visibility.level) {
562 // This symbol definition takes precedence, replace.
563 entry->visibility = res.visibility.value();
564 }
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700565
566 if (res.visibility->staged_api) {
567 entry->visibility.staged_api = entry->visibility.staged_api;
568 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700569 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800570
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700571 if (res.overlayable.has_value()) {
572 if (entry->overlayable_item) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000573 diag->Error(android::DiagMessage(res.overlayable->source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700574 << "duplicate overlayable declaration for resource '" << res.name << "'");
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000575 diag->Error(android::DiagMessage(entry->overlayable_item.value().source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700576 << "previous declaration here");
577 return false;
578 }
579 entry->overlayable_item = res.overlayable.value();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700580 }
581
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700582 if (res.allow_new.has_value()) {
583 entry->allow_new = res.allow_new.value();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700584 }
585
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700586 if (res.staged_id.has_value()) {
587 entry->staged_id = res.staged_id.value();
588 }
589
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700590 if (res.value != nullptr) {
591 auto config_value = entry->FindOrCreateValue(res.config, res.product);
592 if (!config_value->value) {
593 // Resource does not exist, add it now.
594 config_value->value = std::move(res.value);
595 } else {
596 // When validation is enabled, ensure that a resource cannot have multiple values defined for
Jeremy Meyer211bec22024-06-04 14:22:03 -0700597 // the same configuration unless protected by flags.
Jeremy Meyerd52bd682024-08-14 11:16:58 -0700598 auto result =
599 validate ? ResolveFlagCollision(config_value->value->GetFlagStatus(), res.flag_status)
600 : CollisionResult::kKeepBoth;
Jeremy Meyer211bec22024-06-04 14:22:03 -0700601 if (result == CollisionResult::kConflict) {
602 result = ResolveValueCollision(config_value->value.get(), res.value.get());
603 }
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700604 switch (result) {
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700605 case CollisionResult::kKeepBoth: {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700606 // Insert the value ignoring for duplicate configurations
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700607 auto it = entry->values.insert(
608 std::lower_bound(entry->values.begin(), entry->values.end(),
609 ConfigKey{&res.config, res.product}, lt_config_key_ref()),
610 util::make_unique<ResourceConfigValue>(res.config, res.product));
611 (*it)->value = std::move(res.value);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700612 break;
Yurii Zubrytskyia62e6be2024-08-27 14:20:51 -0700613 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800614
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700615 case CollisionResult::kTakeNew:
616 // Take the incoming value.
617 config_value->value = std::move(res.value);
618 break;
Adam Lesinski71be7052017-12-12 16:48:07 -0800619
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700620 case CollisionResult::kConflict:
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000621 diag->Error(android::DiagMessage(source)
622 << "duplicate value for resource '" << res.name << "' "
623 << "with config '" << res.config << "'");
624 diag->Error(android::DiagMessage(source) << "resource previously defined here");
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700625 return false;
Adam Lesinski71be7052017-12-12 16:48:07 -0800626
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700627 case CollisionResult::kKeepOriginal:
628 break;
629 }
630 }
Adam Lesinski71be7052017-12-12 16:48:07 -0800631 }
632
Adam Lesinski71be7052017-12-12 16:48:07 -0800633 return true;
634}
635
Ryan Mitchell4382e442021-07-14 12:53:01 -0700636std::optional<ResourceTable::SearchResult> ResourceTable::FindResource(
637 const ResourceNameRef& name) const {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700638 ResourceTablePackage* package = FindPackage(name.package);
Adam Lesinski71be7052017-12-12 16:48:07 -0800639 if (package == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700640 return {};
641 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800642
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000643 ResourceTableType* type = package->FindType(name.type);
Adam Lesinski71be7052017-12-12 16:48:07 -0800644 if (type == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700645 return {};
646 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800647
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700648 ResourceEntry* entry = type->FindEntry(name.entry);
Adam Lesinski71be7052017-12-12 16:48:07 -0800649 if (entry == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700650 return {};
651 }
652 return SearchResult{package, type, entry};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800653}
654
Ryan Mitchell4382e442021-07-14 12:53:01 -0700655std::optional<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNameRef& name,
656 ResourceId id) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700657 ResourceTablePackage* package = FindPackage(name.package);
658 if (package == nullptr) {
659 return {};
660 }
661
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000662 ResourceTableType* type = package->FindType(name.type);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700663 if (type == nullptr) {
664 return {};
665 }
666
667 auto entry_it = std::equal_range(type->entries.begin(), type->entries.end(), name.entry,
668 NameEqualRange<ResourceEntry>{});
669 for (auto it = entry_it.first; it != entry_it.second; ++it) {
670 if ((*it)->id == id) {
671 return SearchResult{package, type, it->get()};
672 }
673 }
674 return {};
675}
676
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700677bool ResourceTable::RemoveResource(const ResourceNameRef& name, ResourceId id) const {
678 ResourceTablePackage* package = FindPackage(name.package);
679 if (package == nullptr) {
680 return {};
681 }
682
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000683 ResourceTableType* type = package->FindType(name.type);
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700684 if (type == nullptr) {
685 return {};
686 }
687
688 auto entry_it = std::equal_range(type->entries.begin(), type->entries.end(), name.entry,
689 NameEqualRange<ResourceEntry>{});
690 for (auto it = entry_it.first; it != entry_it.second; ++it) {
691 if ((*it)->id == id) {
692 type->entries.erase(it);
693 return true;
694 }
695 }
696 return false;
697}
698
Shane Farmer0a5b2012017-06-22 12:24:12 -0700699std::unique_ptr<ResourceTable> ResourceTable::Clone() const {
700 std::unique_ptr<ResourceTable> new_table = util::make_unique<ResourceTable>();
Ryan Mitchellefcdb952021-04-14 17:31:37 -0700701 CloningValueTransformer cloner(&new_table->string_pool);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700702 for (const auto& pkg : packages) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700703 ResourceTablePackage* new_pkg = new_table->FindOrCreatePackage(pkg->name);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700704 for (const auto& type : pkg->types) {
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000705 ResourceTableType* new_type = new_pkg->FindOrCreateType(type->named_type);
Adam Lesinski71be7052017-12-12 16:48:07 -0800706 new_type->visibility_level = type->visibility_level;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700707
708 for (const auto& entry : type->entries) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700709 ResourceEntry* new_entry = new_type->CreateEntry(entry->name);
Adam Lesinski71be7052017-12-12 16:48:07 -0800710 new_entry->id = entry->id;
711 new_entry->visibility = entry->visibility;
712 new_entry->allow_new = entry->allow_new;
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800713 new_entry->overlayable_item = entry->overlayable_item;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700714
715 for (const auto& config_value : entry->values) {
716 ResourceConfigValue* new_value =
717 new_entry->FindOrCreateValue(config_value->config, config_value->product);
Ryan Mitchellefcdb952021-04-14 17:31:37 -0700718 new_value->value = config_value->value->Transform(cloner);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700719 }
720 }
721 }
722 }
723 return new_table;
724}
725
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700726NewResourceBuilder::NewResourceBuilder(const ResourceNameRef& name) {
727 res_.name = name.ToResourceName();
728}
729
730NewResourceBuilder::NewResourceBuilder(const std::string& name) {
731 ResourceNameRef ref;
732 CHECK(ResourceUtils::ParseResourceName(name, &ref)) << "invalid resource name: " << name;
733 res_.name = ref.ToResourceName();
734}
735
736NewResourceBuilder& NewResourceBuilder::SetValue(std::unique_ptr<Value> value,
737 android::ConfigDescription config,
738 std::string product) {
739 res_.value = std::move(value);
740 res_.config = std::move(config);
741 res_.product = std::move(product);
742 return *this;
743}
744
745NewResourceBuilder& NewResourceBuilder::SetId(ResourceId id, OnIdConflict on_conflict) {
746 res_.id = std::make_pair(id, on_conflict);
747 return *this;
748}
749
750NewResourceBuilder& NewResourceBuilder::SetVisibility(Visibility visibility) {
751 res_.visibility = std::move(visibility);
752 return *this;
753}
754
755NewResourceBuilder& NewResourceBuilder::SetOverlayable(OverlayableItem overlayable) {
756 res_.overlayable = std::move(overlayable);
757 return *this;
758}
759NewResourceBuilder& NewResourceBuilder::SetAllowNew(AllowNew allow_new) {
760 res_.allow_new = std::move(allow_new);
761 return *this;
762}
763
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700764NewResourceBuilder& NewResourceBuilder::SetStagedId(StagedId staged_alias) {
765 res_.staged_id = std::move(staged_alias);
766 return *this;
767}
768
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700769NewResourceBuilder& NewResourceBuilder::SetAllowMangled(bool allow_mangled) {
770 res_.allow_mangled = allow_mangled;
771 return *this;
772}
773
Jeremy Meyer211bec22024-06-04 14:22:03 -0700774NewResourceBuilder& NewResourceBuilder::SetFlagStatus(FlagStatus flag_status) {
775 res_.flag_status = flag_status;
776 return *this;
777}
778
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700779NewResource NewResourceBuilder::Build() {
780 return std::move(res_);
781}
782
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700783} // namespace aapt