blob: a844a43698e5b2ad839305053f1c7228edc50386 [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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 "process/SymbolTable.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -080019#include <iostream>
20
21#include "android-base/logging.h"
22#include "android-base/stringprintf.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070023#include "androidfw/AssetManager.h"
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020024#include "androidfw/ConfigDescription.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070025#include "androidfw/ResourceTypes.h"
26
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -080027#include "NameMangler.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070028#include "Resource.h"
Adam Lesinskid0f116b2016-07-08 15:00:32 -070029#include "ResourceUtils.h"
Adam Lesinskie78fd612015-10-22 12:48:43 -070030#include "ValueVisitor.h"
Adam Lesinskie78fd612015-10-22 12:48:43 -070031#include "util/Util.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070032
Mårten Kongstad24c9aa62018-06-20 08:46:41 +020033using ::android::ConfigDescription;
Adam Lesinskidc785052017-12-07 15:58:46 -080034using ::android::StringPiece;
35using ::android::StringPiece16;
Adam Lesinskid5083f62017-01-16 15:07:21 -080036
Adam Lesinski1ab598f2015-08-14 14:26:04 -070037namespace aapt {
38
Adam Lesinski1e4b0e52017-04-27 15:01:10 -070039SymbolTable::SymbolTable(NameMangler* mangler)
40 : mangler_(mangler),
41 delegate_(util::make_unique<DefaultSymbolTableDelegate>()),
42 cache_(200),
43 id_cache_(200) {
44}
45
46void SymbolTable::SetDelegate(std::unique_ptr<ISymbolTableDelegate> delegate) {
47 CHECK(delegate != nullptr) << "can't set a nullptr delegate";
48 delegate_ = std::move(delegate);
49
50 // Clear the cache in case this delegate changes the order of lookup.
51 cache_.clear();
52}
53
Adam Lesinskice5e56e2016-10-21 17:56:45 -070054void SymbolTable::AppendSource(std::unique_ptr<ISymbolSource> source) {
55 sources_.push_back(std::move(source));
Adam Lesinski64587af2016-02-18 18:33:06 -080056
Adam Lesinskicacb28f2016-10-19 12:18:14 -070057 // We do not clear the cache, because sources earlier in the list take
58 // precedent.
Adam Lesinski64587af2016-02-18 18:33:06 -080059}
60
Adam Lesinskice5e56e2016-10-21 17:56:45 -070061void SymbolTable::PrependSource(std::unique_ptr<ISymbolSource> source) {
62 sources_.insert(sources_.begin(), std::move(source));
Adam Lesinski64587af2016-02-18 18:33:06 -080063
Adam Lesinskicacb28f2016-10-19 12:18:14 -070064 // We must clear the cache in case we did a lookup before adding this
65 // resource.
Adam Lesinskice5e56e2016-10-21 17:56:45 -070066 cache_.clear();
Adam Lesinski64587af2016-02-18 18:33:06 -080067}
68
Adam Lesinskice5e56e2016-10-21 17:56:45 -070069const SymbolTable::Symbol* SymbolTable::FindByName(const ResourceName& name) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -080070 const ResourceName* name_with_package = &name;
71
72 // Fill in the package name if necessary.
73 // If there is no package in `name`, we will need to copy the ResourceName
74 // and store it somewhere; we use the Maybe<> class to reserve storage.
75 Maybe<ResourceName> name_with_package_impl;
76 if (name.package.empty()) {
77 name_with_package_impl = ResourceName(mangler_->GetTargetPackageName(), name.type, name.entry);
78 name_with_package = &name_with_package_impl.value();
79 }
80
81 // We store the name unmangled in the cache, so look it up as-is.
82 if (const std::shared_ptr<Symbol>& s = cache_.get(*name_with_package)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070083 return s.get();
84 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070085
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -080086 // The name was not found in the cache. Mangle it (if necessary) and find it in our sources.
87 // Again, here we use a Maybe<> object to reserve storage if we need to mangle.
88 const ResourceName* mangled_name = name_with_package;
89 Maybe<ResourceName> mangled_name_impl;
90 if (mangler_->ShouldMangle(name_with_package->package)) {
91 mangled_name_impl = mangler_->MangleName(*name_with_package);
92 mangled_name = &mangled_name_impl.value();
93 }
94
Adam Lesinski1e4b0e52017-04-27 15:01:10 -070095 std::unique_ptr<Symbol> symbol = delegate_->FindByName(*mangled_name, sources_);
96 if (symbol == nullptr) {
97 return nullptr;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070098 }
Adam Lesinski1e4b0e52017-04-27 15:01:10 -070099
100 // Take ownership of the symbol into a shared_ptr. We do this because
101 // LruCache doesn't support unique_ptr.
102 std::shared_ptr<Symbol> shared_symbol(std::move(symbol));
103
104 // Since we look in the cache with the unmangled, but package prefixed
105 // name, we must put the same name into the cache.
106 cache_.put(*name_with_package, shared_symbol);
107
108 if (shared_symbol->id) {
109 // The symbol has an ID, so we can also cache this!
110 id_cache_.put(shared_symbol->id.value(), shared_symbol);
111 }
112
113 // Returns the raw pointer. Callers are not expected to hold on to this
114 // between calls to Find*.
115 return shared_symbol.get();
Adam Lesinski64587af2016-02-18 18:33:06 -0800116}
117
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700118const SymbolTable::Symbol* SymbolTable::FindById(const ResourceId& id) {
119 if (const std::shared_ptr<Symbol>& s = id_cache_.get(id)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700120 return s.get();
121 }
Adam Lesinski64587af2016-02-18 18:33:06 -0800122
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700123 // We did not find it in the cache, so look through the sources.
Adam Lesinski1e4b0e52017-04-27 15:01:10 -0700124 std::unique_ptr<Symbol> symbol = delegate_->FindById(id, sources_);
125 if (symbol == nullptr) {
126 return nullptr;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700127 }
Adam Lesinski1e4b0e52017-04-27 15:01:10 -0700128
129 // Take ownership of the symbol into a shared_ptr. We do this because LruCache
130 // doesn't support unique_ptr.
131 std::shared_ptr<Symbol> shared_symbol(std::move(symbol));
132 id_cache_.put(id, shared_symbol);
133
134 // Returns the raw pointer. Callers are not expected to hold on to this
135 // between calls to Find*.
136 return shared_symbol.get();
Adam Lesinski64587af2016-02-18 18:33:06 -0800137}
138
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700139const SymbolTable::Symbol* SymbolTable::FindByReference(const Reference& ref) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800140 // First try the ID. This is because when we lookup by ID, we only fill in the ID cache.
141 // Looking up by name fills in the name and ID cache. So a cache miss will cause a failed
142 // ID lookup, then a successful name lookup. Subsequent look ups will hit immediately
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700143 // because the ID is cached too.
144 //
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800145 // If we looked up by name first, a cache miss would mean we failed to lookup by name, then
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700146 // succeeded to lookup by ID. Subsequent lookups will miss then hit.
147 const SymbolTable::Symbol* symbol = nullptr;
148 if (ref.id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700149 symbol = FindById(ref.id.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700150 }
Adam Lesinski7656554f2016-03-10 21:55:04 -0800151
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700152 if (ref.name && !symbol) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700153 symbol = FindByName(ref.name.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700154 }
155 return symbol;
Adam Lesinski7656554f2016-03-10 21:55:04 -0800156}
157
Adam Lesinski1e4b0e52017-04-27 15:01:10 -0700158std::unique_ptr<SymbolTable::Symbol> DefaultSymbolTableDelegate::FindByName(
159 const ResourceName& name, const std::vector<std::unique_ptr<ISymbolSource>>& sources) {
160 for (auto& source : sources) {
161 std::unique_ptr<SymbolTable::Symbol> symbol = source->FindByName(name);
162 if (symbol) {
163 return symbol;
164 }
165 }
166 return {};
167}
168
169std::unique_ptr<SymbolTable::Symbol> DefaultSymbolTableDelegate::FindById(
170 ResourceId id, const std::vector<std::unique_ptr<ISymbolSource>>& sources) {
171 for (auto& source : sources) {
172 std::unique_ptr<SymbolTable::Symbol> symbol = source->FindById(id);
173 if (symbol) {
174 return symbol;
175 }
176 }
177 return {};
178}
179
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700180std::unique_ptr<SymbolTable::Symbol> ResourceTableSymbolSource::FindByName(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700181 const ResourceName& name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700182 Maybe<ResourceTable::SearchResult> result = table_->FindResource(name);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700183 if (!result) {
184 if (name.type == ResourceType::kAttr) {
185 // Recurse and try looking up a private attribute.
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800186 return FindByName(ResourceName(name.package, ResourceType::kAttrPrivate, name.entry));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700187 }
188 return {};
189 }
190
191 ResourceTable::SearchResult sr = result.value();
192
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800193 std::unique_ptr<SymbolTable::Symbol> symbol = util::make_unique<SymbolTable::Symbol>();
Adam Lesinski71be7052017-12-12 16:48:07 -0800194 symbol->is_public = (sr.entry->visibility.level == Visibility::Level::kPublic);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700195
196 if (sr.package->id && sr.type->id && sr.entry->id) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800197 symbol->id = ResourceId(sr.package->id.value(), sr.type->id.value(), sr.entry->id.value());
Todd Kennedy196dbc32018-07-24 14:37:15 -0700198 symbol->is_dynamic = (sr.package->id.value() == 0);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700199 }
200
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800201 if (name.type == ResourceType::kAttr || name.type == ResourceType::kAttrPrivate) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700202 const ConfigDescription kDefaultConfig;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700203 ResourceConfigValue* config_value = sr.entry->FindValue(kDefaultConfig);
204 if (config_value) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700205 // This resource has an Attribute.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700206 if (Attribute* attr = ValueCast<Attribute>(config_value->value.get())) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700207 symbol->attribute = std::make_shared<Attribute>(*attr);
208 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700209 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700210 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700211 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700212 }
213 return symbol;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700214}
215
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700216bool AssetManagerSymbolSource::AddAssetPath(const StringPiece& path) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700217 int32_t cookie = 0;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800218 return assets_.addAssetPath(android::String8(path.data(), path.size()), &cookie);
219}
220
221std::map<size_t, std::string> AssetManagerSymbolSource::GetAssignedPackageIds() const {
222 std::map<size_t, std::string> package_map;
223 const android::ResTable& table = assets_.getResources(false);
224 const size_t package_count = table.getBasePackageCount();
225 for (size_t i = 0; i < package_count; i++) {
226 package_map[table.getBasePackageId(i)] =
227 util::Utf16ToUtf8(android::StringPiece16(table.getBasePackageName(i).string()));
228 }
229 return package_map;
Adam Lesinski64587af2016-02-18 18:33:06 -0800230}
231
Todd Kennedy32512992018-04-25 16:45:59 -0700232bool AssetManagerSymbolSource::IsPackageDynamic(uint32_t packageId) const {
233 return assets_.getResources(false).isPackageDynamic(packageId);
234}
235
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700236static std::unique_ptr<SymbolTable::Symbol> LookupAttributeInTable(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700237 const android::ResTable& table, ResourceId id) {
238 // Try as a bag.
239 const android::ResTable::bag_entry* entry;
240 ssize_t count = table.lockBag(id.id, &entry);
241 if (count < 0) {
242 table.unlockBag(entry);
243 return nullptr;
244 }
245
246 // We found a resource.
Adam Lesinskic744ae82017-05-17 19:28:38 -0700247 std::unique_ptr<SymbolTable::Symbol> s = util::make_unique<SymbolTable::Symbol>(id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700248
249 // Check to see if it is an attribute.
250 for (size_t i = 0; i < (size_t)count; i++) {
251 if (entry[i].map.name.ident == android::ResTable_map::ATTR_TYPE) {
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800252 s->attribute = std::make_shared<Attribute>(entry[i].map.value.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700253 break;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700254 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700255 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700256
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700257 if (s->attribute) {
258 for (size_t i = 0; i < (size_t)count; i++) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700259 const android::ResTable_map& map_entry = entry[i].map;
260 if (Res_INTERNALID(map_entry.name.ident)) {
261 switch (map_entry.name.ident) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700262 case android::ResTable_map::ATTR_MIN:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700263 s->attribute->min_int = static_cast<int32_t>(map_entry.value.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700264 break;
265 case android::ResTable_map::ATTR_MAX:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700266 s->attribute->max_int = static_cast<int32_t>(map_entry.value.data);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700267 break;
268 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700269 continue;
270 }
271
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700272 android::ResTable::resource_name entry_name;
273 if (!table.getResourceName(map_entry.name.ident, false, &entry_name)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700274 table.unlockBag(entry);
275 return nullptr;
276 }
277
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800278 Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(entry_name);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700279 if (!parsed_name) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700280 return nullptr;
281 }
282
283 Attribute::Symbol symbol;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700284 symbol.symbol.name = parsed_name.value();
285 symbol.symbol.id = ResourceId(map_entry.name.ident);
286 symbol.value = map_entry.value.data;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700287 s->attribute->symbols.push_back(std::move(symbol));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700288 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700289 }
290 table.unlockBag(entry);
291 return s;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700292}
293
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700294std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700295 const ResourceName& name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700296 const android::ResTable& table = assets_.getResources(false);
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700297
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700298 const std::u16string package16 = util::Utf8ToUtf16(name.package);
Adam Lesinski93190b72017-11-03 15:20:17 -0700299 const std::u16string type16 = util::Utf8ToUtf16(to_string(name.type));
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700300 const std::u16string entry16 = util::Utf8ToUtf16(name.entry);
Adam Lesinskidc785052017-12-07 15:58:46 -0800301 const std::u16string mangled_entry16 =
302 util::Utf8ToUtf16(NameMangler::MangleEntry(name.package, name.entry));
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700303
Adam Lesinskidc785052017-12-07 15:58:46 -0800304 uint32_t type_spec_flags;
305 ResourceId res_id;
306
307 // There can be mangled resources embedded within other packages. Here we will
308 // look into each package and look-up the mangled name until we find the resource.
309 const size_t count = table.getBasePackageCount();
310 for (size_t i = 0; i < count; i++) {
311 const android::String16 package_name = table.getBasePackageName(i);
312 StringPiece16 real_package16 = package16;
313 StringPiece16 real_entry16 = entry16;
314 std::u16string scratch_entry16;
315 if (StringPiece16(package_name) != package16) {
316 real_entry16 = mangled_entry16;
317 real_package16 = package_name.string();
318 }
319
320 type_spec_flags = 0;
321 res_id = table.identifierForName(real_entry16.data(), real_entry16.size(), type16.data(),
322 type16.size(), real_package16.data(), real_package16.size(),
323 &type_spec_flags);
324 if (res_id.is_valid()) {
325 break;
326 }
327 }
328
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700329 if (!res_id.is_valid()) {
Adam Lesinski64587af2016-02-18 18:33:06 -0800330 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700331 }
332
333 std::unique_ptr<SymbolTable::Symbol> s;
334 if (name.type == ResourceType::kAttr) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700335 s = LookupAttributeInTable(table, res_id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700336 } else {
337 s = util::make_unique<SymbolTable::Symbol>();
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700338 s->id = res_id;
Todd Kennedy32512992018-04-25 16:45:59 -0700339 s->is_dynamic = table.isResourceDynamic(res_id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700340 }
341
342 if (s) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800343 s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700344 return s;
345 }
346 return {};
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700347}
348
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700349static Maybe<ResourceName> GetResourceName(const android::ResTable& table,
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700350 ResourceId id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700351 android::ResTable::resource_name res_name = {};
352 if (!table.getResourceName(id.id, true, &res_name)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700353 return {};
354 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700355 return ResourceUtils::ToResourceName(res_name);
Adam Lesinski467f1712015-11-16 17:35:44 -0800356}
357
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700358std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700359 ResourceId id) {
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800360 if (!id.is_valid()) {
361 // Exit early and avoid the error logs from AssetManager.
362 return {};
363 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700364 const android::ResTable& table = assets_.getResources(false);
365 Maybe<ResourceName> maybe_name = GetResourceName(table, id);
366 if (!maybe_name) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700367 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700368 }
369
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700370 uint32_t type_spec_flags = 0;
371 table.getResourceFlags(id.id, &type_spec_flags);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700372
373 std::unique_ptr<SymbolTable::Symbol> s;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700374 if (maybe_name.value().type == ResourceType::kAttr) {
375 s = LookupAttributeInTable(table, id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700376 } else {
377 s = util::make_unique<SymbolTable::Symbol>();
378 s->id = id;
Todd Kennedy32512992018-04-25 16:45:59 -0700379 s->is_dynamic = table.isResourceDynamic(id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700380 }
381
382 if (s) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800383 s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700384 return s;
385 }
386 return {};
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700387}
388
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700389std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByReference(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700390 const Reference& ref) {
391 // AssetManager always prefers IDs.
392 if (ref.id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700393 return FindById(ref.id.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700394 } else if (ref.name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700395 return FindByName(ref.name.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700396 }
397 return {};
Adam Lesinski7656554f2016-03-10 21:55:04 -0800398}
399
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700400} // namespace aapt