blob: 1cdb71551d5dce23eeb21551030e4c6cd9402d0b [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) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070053 return lhs->name.compare(0, lhs->name.size(), rhs.data(), rhs.size()) < 0;
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) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -070058 return rhs->name.compare(0, rhs->name.size(), lhs.data(), lhs.size()) > 0;
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 {
Ryan Mitchell9634efb2021-03-19 14:53:17 -070064 return less_than_struct_with_name<T>(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 {
Ryan Mitchell9634efb2021-03-19 14:53:17 -070067 return greater_than_struct_with_name<T>(lhs, rhs);
68 }
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 }
77 return lhs.name.compare(0, lhs.name.size(), rhs.first.data(), rhs.first.size()) < 0;
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
93template <typename T>
94bool lt_config_key_ref(const T& lhs, const ConfigKey& rhs) {
95 int cmp = lhs->config.compare(*rhs.config);
96 if (cmp == 0) {
97 cmp = StringPiece(lhs->product).compare(rhs.product);
98 }
99 return cmp < 0;
100}
101
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700102} // namespace
David Chaloupkae3c1a4a2018-01-18 13:44:36 +0000103
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700104ResourceTable::ResourceTable(ResourceTable::Validation validation) : validation_(validation) {
David Chaloupkae3c1a4a2018-01-18 13:44:36 +0000105}
106
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700107ResourceTablePackage* ResourceTable::FindPackage(android::StringPiece name) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700108 return FindElementsRunAction<ResourceTablePackage>(
109 name, packages, [&](bool found, auto& iter) { return found ? iter->get() : nullptr; });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700110}
111
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700112ResourceTablePackage* ResourceTable::FindOrCreatePackage(android::StringPiece name) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700113 return FindElementsRunAction<ResourceTablePackage>(name, packages, [&](bool found, auto& iter) {
114 return found ? iter->get() : packages.emplace(iter, new ResourceTablePackage(name))->get();
115 });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700116}
117
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700118template <typename Func, typename Elements>
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000119static ResourceTableType* FindTypeRunAction(const ResourceNamedTypeRef& type, Elements& entries,
120 Func action) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700121 const auto iter = std::lower_bound(entries.begin(), entries.end(), type, less_than_type);
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000122 const bool found = iter != entries.end() && type == (*iter)->named_type;
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700123 return action(found, iter);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700124}
125
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000126ResourceTableType* ResourceTablePackage::FindTypeWithDefaultName(const ResourceType type) const {
127 auto named_type = ResourceNamedTypeWithDefaultName(type);
128 return FindType(named_type);
129}
130
131ResourceTableType* ResourceTablePackage::FindType(const ResourceNamedTypeRef& type) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700132 return FindTypeRunAction(type, types,
133 [&](bool found, auto& iter) { return found ? iter->get() : nullptr; });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700134}
135
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000136ResourceTableType* ResourceTablePackage::FindOrCreateType(const ResourceNamedTypeRef& type) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700137 return FindTypeRunAction(type, types, [&](bool found, auto& iter) {
138 return found ? iter->get() : types.emplace(iter, new ResourceTableType(type))->get();
139 });
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700140}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800141
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700142ResourceEntry* ResourceTableType::CreateEntry(android::StringPiece name) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700143 return FindElementsRunAction<ResourceEntry>(name, entries, [&](bool found, auto& iter) {
144 return entries.emplace(iter, new ResourceEntry(name))->get();
145 });
146}
147
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700148ResourceEntry* ResourceTableType::FindEntry(android::StringPiece name) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700149 return FindElementsRunAction<ResourceEntry>(
150 name, entries, [&](bool found, auto& iter) { return found ? iter->get() : nullptr; });
151}
152
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700153ResourceEntry* ResourceTableType::FindOrCreateEntry(android::StringPiece name) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700154 return FindElementsRunAction<ResourceEntry>(name, entries, [&](bool found, auto& iter) {
155 return found ? iter->get() : entries.emplace(iter, new ResourceEntry(name))->get();
156 });
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800157}
158
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700159ResourceConfigValue* ResourceEntry::FindValue(const ConfigDescription& config,
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700160 android::StringPiece product) {
161 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700162 lt_config_key_ref<std::unique_ptr<ResourceConfigValue>>);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700163 if (iter != values.end()) {
164 ResourceConfigValue* value = iter->get();
165 if (value->config == config && StringPiece(value->product) == product) {
166 return value;
167 }
168 }
169 return nullptr;
170}
171
172const ResourceConfigValue* ResourceEntry::FindValue(const android::ConfigDescription& config,
173 android::StringPiece product) const {
Adam Lesinski34a16872018-02-23 16:18:10 -0800174 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700175 lt_config_key_ref<std::unique_ptr<ResourceConfigValue>>);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700176 if (iter != values.end()) {
177 ResourceConfigValue* value = iter->get();
178 if (value->config == config && StringPiece(value->product) == product) {
179 return value;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800180 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700181 }
182 return nullptr;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800183}
184
Adam Lesinskib1afa072017-03-29 13:52:38 -0700185ResourceConfigValue* ResourceEntry::FindOrCreateValue(const ConfigDescription& config,
Yurii Zubrytskyia5775142022-11-02 17:49:49 -0700186 StringPiece product) {
Adam Lesinski34a16872018-02-23 16:18:10 -0800187 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700188 lt_config_key_ref<std::unique_ptr<ResourceConfigValue>>);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700189 if (iter != values.end()) {
190 ResourceConfigValue* value = iter->get();
191 if (value->config == config && StringPiece(value->product) == product) {
192 return value;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800193 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700194 }
195 ResourceConfigValue* newValue =
Adam Lesinskib1afa072017-03-29 13:52:38 -0700196 values.insert(iter, util::make_unique<ResourceConfigValue>(config, product))->get();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700197 return newValue;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800198}
199
Adam Lesinskib1afa072017-03-29 13:52:38 -0700200std::vector<ResourceConfigValue*> ResourceEntry::FindAllValues(const ConfigDescription& config) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700201 std::vector<ResourceConfigValue*> results;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800202
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700203 auto iter = values.begin();
204 for (; iter != values.end(); ++iter) {
205 ResourceConfigValue* value = iter->get();
206 if (value->config == config) {
207 results.push_back(value);
208 ++iter;
209 break;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800210 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700211 }
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800212
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700213 for (; iter != values.end(); ++iter) {
214 ResourceConfigValue* value = iter->get();
215 if (value->config == config) {
216 results.push_back(value);
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800217 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700218 }
219 return results;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -0800220}
221
Adam Lesinski34a16872018-02-23 16:18:10 -0800222bool ResourceEntry::HasDefaultValue() const {
223 const ConfigDescription& default_config = ConfigDescription::DefaultConfig();
224
225 // The default config should be at the top of the list, since the list is sorted.
226 for (auto& config_value : values) {
227 if (config_value->config == default_config) {
228 return true;
Adam Lesinski458b8772016-04-25 14:20:21 -0700229 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700230 }
Adam Lesinski34a16872018-02-23 16:18:10 -0800231 return false;
Adam Lesinski458b8772016-04-25 14:20:21 -0700232}
233
Jeremy Meyer211bec22024-06-04 14:22:03 -0700234ResourceTable::CollisionResult ResourceTable::ResolveFlagCollision(FlagStatus existing,
235 FlagStatus incoming) {
236 switch (existing) {
237 case FlagStatus::NoFlag:
238 switch (incoming) {
239 case FlagStatus::NoFlag:
240 return CollisionResult::kConflict;
241 case FlagStatus::Disabled:
242 return CollisionResult::kKeepOriginal;
243 case FlagStatus::Enabled:
244 return CollisionResult::kTakeNew;
245 default:
246 return CollisionResult::kConflict;
247 }
248 case FlagStatus::Disabled:
249 switch (incoming) {
250 case FlagStatus::NoFlag:
251 return CollisionResult::kTakeNew;
252 case FlagStatus::Disabled:
253 return CollisionResult::kKeepOriginal;
254 case FlagStatus::Enabled:
255 return CollisionResult::kTakeNew;
256 default:
257 return CollisionResult::kConflict;
258 }
259 case FlagStatus::Enabled:
260 switch (incoming) {
261 case FlagStatus::NoFlag:
262 return CollisionResult::kKeepOriginal;
263 case FlagStatus::Disabled:
264 return CollisionResult::kKeepOriginal;
265 case FlagStatus::Enabled:
266 return CollisionResult::kConflict;
267 default:
268 return CollisionResult::kConflict;
269 }
270 default:
271 return CollisionResult::kConflict;
272 }
273}
274
Adam Lesinski71be7052017-12-12 16:48:07 -0800275// The default handler for collisions.
276//
277// Typically, a weak value will be overridden by a strong value. An existing weak
278// value will not be overridden by an incoming weak value.
279//
280// There are some exceptions:
281//
282// Attributes: There are two types of Attribute values: USE and DECL.
283//
284// USE is anywhere an Attribute is declared without a format, and in a place that would
285// be legal to declare if the Attribute already existed. This is typically in a
286// <declare-styleable> tag. Attributes defined in a <declare-styleable> are also weak.
287//
288// DECL is an absolute declaration of an Attribute and specifies an explicit format.
289//
290// A DECL will override a USE without error. Two DECLs must match in their format for there to be
291// no error.
Adam Lesinskib1afa072017-03-29 13:52:38 -0700292ResourceTable::CollisionResult ResourceTable::ResolveValueCollision(Value* existing,
293 Value* incoming) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700294 Attribute* existing_attr = ValueCast<Attribute>(existing);
295 Attribute* incoming_attr = ValueCast<Attribute>(incoming);
296 if (!incoming_attr) {
297 if (incoming->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700298 // We're trying to add a weak resource but a resource
299 // already exists. Keep the existing.
300 return CollisionResult::kKeepOriginal;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700301 } else if (existing->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700302 // Override the weak resource with the new strong resource.
303 return CollisionResult::kTakeNew;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800304 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700305 // The existing and incoming values are strong, this is an error
306 // if the values are not both attributes.
Adam Lesinski5c3464c2016-08-24 16:03:48 -0700307 return CollisionResult::kConflict;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700308 }
309
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700310 if (!existing_attr) {
311 if (existing->IsWeak()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700312 // The existing value is not an attribute and it is weak,
313 // so take the incoming attribute value.
314 return CollisionResult::kTakeNew;
315 }
316 // The existing value is not an attribute and it is strong,
317 // so the incoming attribute value is an error.
318 return CollisionResult::kConflict;
319 }
320
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700321 CHECK(incoming_attr != nullptr && existing_attr != nullptr);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700322
323 //
324 // Attribute specific handling. At this point we know both
325 // values are attributes. Since we can declare and define
326 // attributes all-over, we do special handling to see
327 // which definition sticks.
328 //
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800329 if (existing_attr->IsCompatibleWith(*incoming_attr)) {
330 // The two attributes are both DECLs, but they are plain attributes with compatible formats.
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700331 // Keep the strongest one.
Adam Lesinskib1afa072017-03-29 13:52:38 -0700332 return existing_attr->IsWeak() ? CollisionResult::kTakeNew : CollisionResult::kKeepOriginal;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700333 }
334
Adam Lesinskib1afa072017-03-29 13:52:38 -0700335 if (existing_attr->IsWeak() && existing_attr->type_mask == android::ResTable_map::TYPE_ANY) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700336 // Any incoming attribute is better than this.
337 return CollisionResult::kTakeNew;
338 }
339
Adam Lesinskib1afa072017-03-29 13:52:38 -0700340 if (incoming_attr->IsWeak() && incoming_attr->type_mask == android::ResTable_map::TYPE_ANY) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700341 // The incoming attribute may be a USE instead of a DECL.
342 // Keep the existing attribute.
343 return CollisionResult::kKeepOriginal;
344 }
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700345
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700346 return CollisionResult::kConflict;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800347}
348
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700349namespace {
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700350template <typename T, typename Comparer>
351struct SortedVectorInserter : public Comparer {
352 std::pair<bool, typename std::vector<T>::iterator> LowerBound(std::vector<T>& el,
353 const T& value) {
354 auto it = std::lower_bound(el.begin(), el.end(), value, [&](auto& lhs, auto& rhs) {
355 return Comparer::operator()(lhs, rhs);
356 });
357 bool found =
358 it != el.end() && !Comparer::operator()(*it, value) && !Comparer::operator()(value, *it);
359 return std::make_pair(found, it);
360 }
361
362 T* Insert(std::vector<T>& el, T&& value) {
363 auto [found, it] = LowerBound(el, value);
364 if (found) {
365 return &*it;
366 }
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700367 return &*el.insert(it, std::forward<T>(value));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700368 }
369};
370
371struct PackageViewComparer {
372 bool operator()(const ResourceTablePackageView& lhs, const ResourceTablePackageView& rhs) {
373 return less_than_struct_with_name_and_id<ResourceTablePackageView, uint8_t>(
374 lhs, std::make_pair(rhs.name, rhs.id));
375 }
376};
377
378struct TypeViewComparer {
379 bool operator()(const ResourceTableTypeView& lhs, const ResourceTableTypeView& rhs) {
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000380 return lhs.id != rhs.id ? lhs.id < rhs.id : lhs.named_type < rhs.named_type;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700381 }
382};
383
384struct EntryViewComparer {
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700385 bool operator()(const ResourceTableEntryView& lhs, const ResourceTableEntryView& rhs) {
386 return less_than_struct_with_name_and_id<ResourceTableEntryView, uint16_t>(
387 lhs, std::make_pair(rhs.name, rhs.id));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700388 }
389};
390
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700391void InsertEntryIntoTableView(ResourceTableView& table, const ResourceTablePackage* package,
392 const ResourceTableType* type, const std::string& entry_name,
Ryan Mitchell4382e442021-07-14 12:53:01 -0700393 const std::optional<ResourceId>& id, const Visibility& visibility,
394 const std::optional<AllowNew>& allow_new,
395 const std::optional<OverlayableItem>& overlayable_item,
396 const std::optional<StagedId>& staged_id,
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700397 const std::vector<std::unique_ptr<ResourceConfigValue>>& values) {
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700398 SortedVectorInserter<ResourceTablePackageView, PackageViewComparer> package_inserter;
399 SortedVectorInserter<ResourceTableTypeView, TypeViewComparer> type_inserter;
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700400 SortedVectorInserter<ResourceTableEntryView, EntryViewComparer> entry_inserter;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700401
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700402 ResourceTablePackageView new_package{package->name,
Ryan Mitchell4382e442021-07-14 12:53:01 -0700403 id ? id.value().package_id() : std::optional<uint8_t>{}};
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700404 auto view_package = package_inserter.Insert(table.packages, std::move(new_package));
405
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000406 ResourceTableTypeView new_type{type->named_type,
407 id ? id.value().type_id() : std::optional<uint8_t>{}};
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700408 auto view_type = type_inserter.Insert(view_package->types, std::move(new_type));
409
410 if (visibility.level == Visibility::Level::kPublic) {
411 // Only mark the type visibility level as public, it doesn't care about being private.
412 view_type->visibility_level = Visibility::Level::kPublic;
413 }
414
415 ResourceTableEntryView new_entry{.name = entry_name,
Ryan Mitchell4382e442021-07-14 12:53:01 -0700416 .id = id ? id.value().entry_id() : std::optional<uint16_t>{},
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700417 .visibility = visibility,
418 .allow_new = allow_new,
419 .overlayable_item = overlayable_item,
420 .staged_id = staged_id};
421 for (auto& value : values) {
422 new_entry.values.emplace_back(value.get());
423 }
424
425 entry_inserter.Insert(view_type->entries, std::move(new_entry));
426}
427} // namespace
428
429const ResourceConfigValue* ResourceTableEntryView::FindValue(const ConfigDescription& config,
430 android::StringPiece product) const {
431 auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product},
432 lt_config_key_ref<const ResourceConfigValue*>);
433 if (iter != values.end()) {
434 const ResourceConfigValue* value = *iter;
435 if (value->config == config && StringPiece(value->product) == product) {
436 return value;
437 }
438 }
439 return nullptr;
440}
441
442ResourceTableView ResourceTable::GetPartitionedView(const ResourceTableViewOptions& options) const {
443 ResourceTableView view;
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700444 for (const auto& package : packages) {
445 for (const auto& type : package->types) {
446 for (const auto& entry : type->entries) {
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700447 InsertEntryIntoTableView(view, package.get(), type.get(), entry->name, entry->id,
448 entry->visibility, entry->allow_new, entry->overlayable_item,
449 entry->staged_id, entry->values);
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700450
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700451 if (options.create_alias_entries && entry->staged_id) {
452 auto alias_id = entry->staged_id.value().id;
453 InsertEntryIntoTableView(view, package.get(), type.get(), entry->name, alias_id,
454 entry->visibility, entry->allow_new, entry->overlayable_item, {},
455 entry->values);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700456 }
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700457 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800458 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700459 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800460
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700461 // The android runtime does not support querying resources when the there are multiple type ids
462 // for the same resource type within the same package. For this reason, if there are types with
463 // multiple type ids, each type needs to exist in its own package in order to be queried by name.
464 std::vector<ResourceTablePackageView> new_packages;
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700465 SortedVectorInserter<ResourceTablePackageView, PackageViewComparer> package_inserter;
466 SortedVectorInserter<ResourceTableTypeView, TypeViewComparer> type_inserter;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700467 for (auto& package : view.packages) {
468 // If a new package was already created for a different type within this package, then
469 // we can reuse those packages for other types that need to be extracted from this package.
470 // `start_index` is the index of the first newly created package that can be reused.
471 const size_t start_index = new_packages.size();
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000472 std::map<ResourceNamedType, size_t> type_new_package_index;
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700473 for (auto type_it = package.types.begin(); type_it != package.types.end();) {
474 auto& type = *type_it;
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000475 auto type_index_iter = type_new_package_index.find(type.named_type);
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700476 if (type_index_iter == type_new_package_index.end()) {
477 // First occurrence of the resource type in this package. Keep it in this package.
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000478 type_new_package_index.insert(type_index_iter,
479 std::make_pair(type.named_type, start_index));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700480 ++type_it;
481 continue;
482 }
483
484 // The resource type has already been seen for this package, so this type must be extracted to
485 // a new separate package.
486 const size_t index = type_index_iter->second;
487 if (new_packages.size() == index) {
488 new_packages.emplace_back(ResourceTablePackageView{package.name, package.id});
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700489 }
490
491 // Move the type into a new package
492 auto& other_package = new_packages[index];
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000493 type_new_package_index[type.named_type] = index + 1;
Greg Kaiserb40f3ab2021-10-18 06:37:26 -0700494 type_inserter.Insert(other_package.types, std::move(type));
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700495 type_it = package.types.erase(type_it);
496 }
497 }
498
499 for (auto& new_package : new_packages) {
500 // Insert newly created packages after their original packages
501 auto [_, it] = package_inserter.LowerBound(view.packages, new_package);
502 view.packages.insert(++it, std::move(new_package));
503 }
504
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700505 return view;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800506}
507
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000508bool ResourceTable::AddResource(NewResource&& res, android::IDiagnostics* diag) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700509 CHECK(diag != nullptr) << "Diagnostic pointer is null";
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700510
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700511 const bool validate = validation_ == Validation::kEnabled;
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000512 const android::Source source = res.value ? res.value->GetSource() : android::Source{};
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700513 if (validate && !res.allow_mangled && !IsValidResourceEntryName(res.name.entry)) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000514 diag->Error(android::DiagMessage(source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700515 << "resource '" << res.name << "' has invalid entry name '" << res.name.entry);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700516 return false;
517 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800518
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700519 if (res.id.has_value() && !res.id->first.is_valid()) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000520 diag->Error(android::DiagMessage(source)
521 << "trying to add resource '" << res.name << "' with ID " << res.id->first
522 << " but that ID is invalid");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700523 return false;
524 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700525
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700526 auto package = FindOrCreatePackage(res.name.package);
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000527 auto type = package->FindOrCreateType(res.name.type);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700528 auto entry_it = std::equal_range(type->entries.begin(), type->entries.end(), res.name.entry,
529 NameEqualRange<ResourceEntry>{});
530 const size_t entry_count = std::distance(entry_it.first, entry_it.second);
Ryan Mitchell83a37ad2018-08-06 16:32:24 -0700531
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700532 ResourceEntry* entry;
533 if (entry_count == 0) {
534 // Adding a new resource
535 entry = type->CreateEntry(res.name.entry);
536 } else if (entry_count == 1) {
537 // Assume that the existing resource is being modified
538 entry = entry_it.first->get();
539 } else {
540 // Multiple resources with the same name exist in the resource table. The only way to
541 // distinguish between them is using resource id since each resource should have a unique id.
542 CHECK(res.id.has_value()) << "ambiguous modification of resource entry '" << res.name
543 << "' without specifying a resource id.";
544 entry = entry_it.first->get();
545 for (auto it = entry_it.first; it != entry_it.second; ++it) {
546 CHECK((bool)(*it)->id) << "ambiguous modification of resource entry '" << res.name
547 << "' with multiple entries without resource ids";
548 if ((*it)->id == res.id->first) {
549 entry = it->get();
550 break;
551 }
552 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700553 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800554
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700555 if (res.id.has_value()) {
556 if (entry->id && entry->id.value() != res.id->first) {
557 if (res.id->second != OnIdConflict::CREATE_ENTRY) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000558 diag->Error(android::DiagMessage(source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700559 << "trying to add resource '" << res.name << "' with ID " << res.id->first
560 << " but resource already has ID " << entry->id.value());
561 return false;
562 }
563 entry = type->CreateEntry(res.name.entry);
564 }
565 entry->id = res.id->first;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700566 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800567
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700568 if (res.visibility.has_value()) {
569 // Only mark the type visibility level as public, it doesn't care about being private.
570 if (res.visibility->level == Visibility::Level::kPublic) {
571 type->visibility_level = Visibility::Level::kPublic;
572 }
573
574 if (res.visibility->level > entry->visibility.level) {
575 // This symbol definition takes precedence, replace.
576 entry->visibility = res.visibility.value();
577 }
Ryan Mitchell2e9bec12021-03-22 09:31:00 -0700578
579 if (res.visibility->staged_api) {
580 entry->visibility.staged_api = entry->visibility.staged_api;
581 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700582 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800583
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700584 if (res.overlayable.has_value()) {
585 if (entry->overlayable_item) {
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000586 diag->Error(android::DiagMessage(res.overlayable->source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700587 << "duplicate overlayable declaration for resource '" << res.name << "'");
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000588 diag->Error(android::DiagMessage(entry->overlayable_item.value().source)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700589 << "previous declaration here");
590 return false;
591 }
592 entry->overlayable_item = res.overlayable.value();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700593 }
594
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700595 if (res.allow_new.has_value()) {
596 entry->allow_new = res.allow_new.value();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700597 }
598
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700599 if (res.staged_id.has_value()) {
600 entry->staged_id = res.staged_id.value();
601 }
602
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700603 if (res.value != nullptr) {
604 auto config_value = entry->FindOrCreateValue(res.config, res.product);
605 if (!config_value->value) {
606 // Resource does not exist, add it now.
607 config_value->value = std::move(res.value);
Jeremy Meyer211bec22024-06-04 14:22:03 -0700608 config_value->flag_status = res.flag_status;
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700609 } else {
610 // When validation is enabled, ensure that a resource cannot have multiple values defined for
Jeremy Meyer211bec22024-06-04 14:22:03 -0700611 // the same configuration unless protected by flags.
612 auto result = validate ? ResolveFlagCollision(config_value->flag_status, res.flag_status)
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700613 : CollisionResult::kKeepBoth;
Jeremy Meyer211bec22024-06-04 14:22:03 -0700614 if (result == CollisionResult::kConflict) {
615 result = ResolveValueCollision(config_value->value.get(), res.value.get());
616 }
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700617 switch (result) {
618 case CollisionResult::kKeepBoth:
619 // Insert the value ignoring for duplicate configurations
620 entry->values.push_back(util::make_unique<ResourceConfigValue>(res.config, res.product));
621 entry->values.back()->value = std::move(res.value);
Jeremy Meyer211bec22024-06-04 14:22:03 -0700622 entry->values.back()->flag_status = res.flag_status;
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700623 break;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800624
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700625 case CollisionResult::kTakeNew:
626 // Take the incoming value.
627 config_value->value = std::move(res.value);
628 break;
Adam Lesinski71be7052017-12-12 16:48:07 -0800629
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700630 case CollisionResult::kConflict:
Jeremy Meyer56f36e82022-05-20 20:35:42 +0000631 diag->Error(android::DiagMessage(source)
632 << "duplicate value for resource '" << res.name << "' "
633 << "with config '" << res.config << "'");
634 diag->Error(android::DiagMessage(source) << "resource previously defined here");
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700635 return false;
Adam Lesinski71be7052017-12-12 16:48:07 -0800636
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700637 case CollisionResult::kKeepOriginal:
638 break;
639 }
640 }
Adam Lesinski71be7052017-12-12 16:48:07 -0800641 }
642
Adam Lesinski71be7052017-12-12 16:48:07 -0800643 return true;
644}
645
Ryan Mitchell4382e442021-07-14 12:53:01 -0700646std::optional<ResourceTable::SearchResult> ResourceTable::FindResource(
647 const ResourceNameRef& name) const {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700648 ResourceTablePackage* package = FindPackage(name.package);
Adam Lesinski71be7052017-12-12 16:48:07 -0800649 if (package == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700650 return {};
651 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800652
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000653 ResourceTableType* type = package->FindType(name.type);
Adam Lesinski71be7052017-12-12 16:48:07 -0800654 if (type == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700655 return {};
656 }
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800657
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700658 ResourceEntry* entry = type->FindEntry(name.entry);
Adam Lesinski71be7052017-12-12 16:48:07 -0800659 if (entry == nullptr) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700660 return {};
661 }
662 return SearchResult{package, type, entry};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800663}
664
Ryan Mitchell4382e442021-07-14 12:53:01 -0700665std::optional<ResourceTable::SearchResult> ResourceTable::FindResource(const ResourceNameRef& name,
666 ResourceId id) const {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700667 ResourceTablePackage* package = FindPackage(name.package);
668 if (package == nullptr) {
669 return {};
670 }
671
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000672 ResourceTableType* type = package->FindType(name.type);
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700673 if (type == nullptr) {
674 return {};
675 }
676
677 auto entry_it = std::equal_range(type->entries.begin(), type->entries.end(), name.entry,
678 NameEqualRange<ResourceEntry>{});
679 for (auto it = entry_it.first; it != entry_it.second; ++it) {
680 if ((*it)->id == id) {
681 return SearchResult{package, type, it->get()};
682 }
683 }
684 return {};
685}
686
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700687bool ResourceTable::RemoveResource(const ResourceNameRef& name, ResourceId id) const {
688 ResourceTablePackage* package = FindPackage(name.package);
689 if (package == nullptr) {
690 return {};
691 }
692
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000693 ResourceTableType* type = package->FindType(name.type);
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700694 if (type == nullptr) {
695 return {};
696 }
697
698 auto entry_it = std::equal_range(type->entries.begin(), type->entries.end(), name.entry,
699 NameEqualRange<ResourceEntry>{});
700 for (auto it = entry_it.first; it != entry_it.second; ++it) {
701 if ((*it)->id == id) {
702 type->entries.erase(it);
703 return true;
704 }
705 }
706 return false;
707}
708
Shane Farmer0a5b2012017-06-22 12:24:12 -0700709std::unique_ptr<ResourceTable> ResourceTable::Clone() const {
710 std::unique_ptr<ResourceTable> new_table = util::make_unique<ResourceTable>();
Ryan Mitchellefcdb952021-04-14 17:31:37 -0700711 CloningValueTransformer cloner(&new_table->string_pool);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700712 for (const auto& pkg : packages) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700713 ResourceTablePackage* new_pkg = new_table->FindOrCreatePackage(pkg->name);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700714 for (const auto& type : pkg->types) {
Iurii Makhnof0c5ff42022-02-22 13:31:02 +0000715 ResourceTableType* new_type = new_pkg->FindOrCreateType(type->named_type);
Adam Lesinski71be7052017-12-12 16:48:07 -0800716 new_type->visibility_level = type->visibility_level;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700717
718 for (const auto& entry : type->entries) {
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700719 ResourceEntry* new_entry = new_type->CreateEntry(entry->name);
Adam Lesinski71be7052017-12-12 16:48:07 -0800720 new_entry->id = entry->id;
721 new_entry->visibility = entry->visibility;
722 new_entry->allow_new = entry->allow_new;
Ryan Mitchell54237ff2018-12-13 15:44:29 -0800723 new_entry->overlayable_item = entry->overlayable_item;
Shane Farmer0a5b2012017-06-22 12:24:12 -0700724
725 for (const auto& config_value : entry->values) {
726 ResourceConfigValue* new_value =
727 new_entry->FindOrCreateValue(config_value->config, config_value->product);
Ryan Mitchellefcdb952021-04-14 17:31:37 -0700728 new_value->value = config_value->value->Transform(cloner);
Shane Farmer0a5b2012017-06-22 12:24:12 -0700729 }
730 }
731 }
732 }
733 return new_table;
734}
735
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700736NewResourceBuilder::NewResourceBuilder(const ResourceNameRef& name) {
737 res_.name = name.ToResourceName();
738}
739
740NewResourceBuilder::NewResourceBuilder(const std::string& name) {
741 ResourceNameRef ref;
742 CHECK(ResourceUtils::ParseResourceName(name, &ref)) << "invalid resource name: " << name;
743 res_.name = ref.ToResourceName();
744}
745
746NewResourceBuilder& NewResourceBuilder::SetValue(std::unique_ptr<Value> value,
747 android::ConfigDescription config,
748 std::string product) {
749 res_.value = std::move(value);
750 res_.config = std::move(config);
751 res_.product = std::move(product);
752 return *this;
753}
754
755NewResourceBuilder& NewResourceBuilder::SetId(ResourceId id, OnIdConflict on_conflict) {
756 res_.id = std::make_pair(id, on_conflict);
757 return *this;
758}
759
760NewResourceBuilder& NewResourceBuilder::SetVisibility(Visibility visibility) {
761 res_.visibility = std::move(visibility);
762 return *this;
763}
764
765NewResourceBuilder& NewResourceBuilder::SetOverlayable(OverlayableItem overlayable) {
766 res_.overlayable = std::move(overlayable);
767 return *this;
768}
769NewResourceBuilder& NewResourceBuilder::SetAllowNew(AllowNew allow_new) {
770 res_.allow_new = std::move(allow_new);
771 return *this;
772}
773
Ryan Mitchell2fedba92021-04-23 07:47:38 -0700774NewResourceBuilder& NewResourceBuilder::SetStagedId(StagedId staged_alias) {
775 res_.staged_id = std::move(staged_alias);
776 return *this;
777}
778
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700779NewResourceBuilder& NewResourceBuilder::SetAllowMangled(bool allow_mangled) {
780 res_.allow_mangled = allow_mangled;
781 return *this;
782}
783
Jeremy Meyer211bec22024-06-04 14:22:03 -0700784NewResourceBuilder& NewResourceBuilder::SetFlagStatus(FlagStatus flag_status) {
785 res_.flag_status = flag_status;
786 return *this;
787}
788
Ryan Mitchell9634efb2021-03-19 14:53:17 -0700789NewResource NewResourceBuilder::Build() {
790 return std::move(res_);
791}
792
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700793} // namespace aapt