blob: 70efbf5d17b2fc1034f7413a475169fee68cf94a [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"
24#include "androidfw/ResourceTypes.h"
25
Adam Lesinski1ab598f2015-08-14 14:26:04 -070026#include "ConfigDescription.h"
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
Adam Lesinskidc785052017-12-07 15:58:46 -080033using ::android::StringPiece;
34using ::android::StringPiece16;
Adam Lesinskid5083f62017-01-16 15:07:21 -080035
Adam Lesinski1ab598f2015-08-14 14:26:04 -070036namespace aapt {
37
Adam Lesinski1e4b0e52017-04-27 15:01:10 -070038SymbolTable::SymbolTable(NameMangler* mangler)
39 : mangler_(mangler),
40 delegate_(util::make_unique<DefaultSymbolTableDelegate>()),
41 cache_(200),
42 id_cache_(200) {
43}
44
45void SymbolTable::SetDelegate(std::unique_ptr<ISymbolTableDelegate> delegate) {
46 CHECK(delegate != nullptr) << "can't set a nullptr delegate";
47 delegate_ = std::move(delegate);
48
49 // Clear the cache in case this delegate changes the order of lookup.
50 cache_.clear();
51}
52
Adam Lesinskice5e56e2016-10-21 17:56:45 -070053void SymbolTable::AppendSource(std::unique_ptr<ISymbolSource> source) {
54 sources_.push_back(std::move(source));
Adam Lesinski64587af2016-02-18 18:33:06 -080055
Adam Lesinskicacb28f2016-10-19 12:18:14 -070056 // We do not clear the cache, because sources earlier in the list take
57 // precedent.
Adam Lesinski64587af2016-02-18 18:33:06 -080058}
59
Adam Lesinskice5e56e2016-10-21 17:56:45 -070060void SymbolTable::PrependSource(std::unique_ptr<ISymbolSource> source) {
61 sources_.insert(sources_.begin(), std::move(source));
Adam Lesinski64587af2016-02-18 18:33:06 -080062
Adam Lesinskicacb28f2016-10-19 12:18:14 -070063 // We must clear the cache in case we did a lookup before adding this
64 // resource.
Adam Lesinskice5e56e2016-10-21 17:56:45 -070065 cache_.clear();
Adam Lesinski64587af2016-02-18 18:33:06 -080066}
67
Adam Lesinskice5e56e2016-10-21 17:56:45 -070068const SymbolTable::Symbol* SymbolTable::FindByName(const ResourceName& name) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -080069 const ResourceName* name_with_package = &name;
70
71 // Fill in the package name if necessary.
72 // If there is no package in `name`, we will need to copy the ResourceName
73 // and store it somewhere; we use the Maybe<> class to reserve storage.
74 Maybe<ResourceName> name_with_package_impl;
75 if (name.package.empty()) {
76 name_with_package_impl = ResourceName(mangler_->GetTargetPackageName(), name.type, name.entry);
77 name_with_package = &name_with_package_impl.value();
78 }
79
80 // We store the name unmangled in the cache, so look it up as-is.
81 if (const std::shared_ptr<Symbol>& s = cache_.get(*name_with_package)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070082 return s.get();
83 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070084
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -080085 // The name was not found in the cache. Mangle it (if necessary) and find it in our sources.
86 // Again, here we use a Maybe<> object to reserve storage if we need to mangle.
87 const ResourceName* mangled_name = name_with_package;
88 Maybe<ResourceName> mangled_name_impl;
89 if (mangler_->ShouldMangle(name_with_package->package)) {
90 mangled_name_impl = mangler_->MangleName(*name_with_package);
91 mangled_name = &mangled_name_impl.value();
92 }
93
Adam Lesinski1e4b0e52017-04-27 15:01:10 -070094 std::unique_ptr<Symbol> symbol = delegate_->FindByName(*mangled_name, sources_);
95 if (symbol == nullptr) {
96 return nullptr;
Adam Lesinskicacb28f2016-10-19 12:18:14 -070097 }
Adam Lesinski1e4b0e52017-04-27 15:01:10 -070098
99 // Take ownership of the symbol into a shared_ptr. We do this because
100 // LruCache doesn't support unique_ptr.
101 std::shared_ptr<Symbol> shared_symbol(std::move(symbol));
102
103 // Since we look in the cache with the unmangled, but package prefixed
104 // name, we must put the same name into the cache.
105 cache_.put(*name_with_package, shared_symbol);
106
107 if (shared_symbol->id) {
108 // The symbol has an ID, so we can also cache this!
109 id_cache_.put(shared_symbol->id.value(), shared_symbol);
110 }
111
112 // Returns the raw pointer. Callers are not expected to hold on to this
113 // between calls to Find*.
114 return shared_symbol.get();
Adam Lesinski64587af2016-02-18 18:33:06 -0800115}
116
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700117const SymbolTable::Symbol* SymbolTable::FindById(const ResourceId& id) {
118 if (const std::shared_ptr<Symbol>& s = id_cache_.get(id)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700119 return s.get();
120 }
Adam Lesinski64587af2016-02-18 18:33:06 -0800121
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700122 // We did not find it in the cache, so look through the sources.
Adam Lesinski1e4b0e52017-04-27 15:01:10 -0700123 std::unique_ptr<Symbol> symbol = delegate_->FindById(id, sources_);
124 if (symbol == nullptr) {
125 return nullptr;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700126 }
Adam Lesinski1e4b0e52017-04-27 15:01:10 -0700127
128 // Take ownership of the symbol into a shared_ptr. We do this because LruCache
129 // doesn't support unique_ptr.
130 std::shared_ptr<Symbol> shared_symbol(std::move(symbol));
131 id_cache_.put(id, shared_symbol);
132
133 // Returns the raw pointer. Callers are not expected to hold on to this
134 // between calls to Find*.
135 return shared_symbol.get();
Adam Lesinski64587af2016-02-18 18:33:06 -0800136}
137
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700138const SymbolTable::Symbol* SymbolTable::FindByReference(const Reference& ref) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800139 // First try the ID. This is because when we lookup by ID, we only fill in the ID cache.
140 // Looking up by name fills in the name and ID cache. So a cache miss will cause a failed
141 // ID lookup, then a successful name lookup. Subsequent look ups will hit immediately
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700142 // because the ID is cached too.
143 //
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800144 // 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 -0700145 // succeeded to lookup by ID. Subsequent lookups will miss then hit.
146 const SymbolTable::Symbol* symbol = nullptr;
147 if (ref.id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700148 symbol = FindById(ref.id.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700149 }
Adam Lesinski7656554f2016-03-10 21:55:04 -0800150
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700151 if (ref.name && !symbol) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700152 symbol = FindByName(ref.name.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700153 }
154 return symbol;
Adam Lesinski7656554f2016-03-10 21:55:04 -0800155}
156
Adam Lesinski1e4b0e52017-04-27 15:01:10 -0700157std::unique_ptr<SymbolTable::Symbol> DefaultSymbolTableDelegate::FindByName(
158 const ResourceName& name, const std::vector<std::unique_ptr<ISymbolSource>>& sources) {
159 for (auto& source : sources) {
160 std::unique_ptr<SymbolTable::Symbol> symbol = source->FindByName(name);
161 if (symbol) {
162 return symbol;
163 }
164 }
165 return {};
166}
167
168std::unique_ptr<SymbolTable::Symbol> DefaultSymbolTableDelegate::FindById(
169 ResourceId id, const std::vector<std::unique_ptr<ISymbolSource>>& sources) {
170 for (auto& source : sources) {
171 std::unique_ptr<SymbolTable::Symbol> symbol = source->FindById(id);
172 if (symbol) {
173 return symbol;
174 }
175 }
176 return {};
177}
178
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700179std::unique_ptr<SymbolTable::Symbol> ResourceTableSymbolSource::FindByName(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700180 const ResourceName& name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700181 Maybe<ResourceTable::SearchResult> result = table_->FindResource(name);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700182 if (!result) {
183 if (name.type == ResourceType::kAttr) {
184 // Recurse and try looking up a private attribute.
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800185 return FindByName(ResourceName(name.package, ResourceType::kAttrPrivate, name.entry));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700186 }
187 return {};
188 }
189
190 ResourceTable::SearchResult sr = result.value();
191
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800192 std::unique_ptr<SymbolTable::Symbol> symbol = util::make_unique<SymbolTable::Symbol>();
Adam Lesinski71be7052017-12-12 16:48:07 -0800193 symbol->is_public = (sr.entry->visibility.level == Visibility::Level::kPublic);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700194
195 if (sr.package->id && sr.type->id && sr.entry->id) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800196 symbol->id = ResourceId(sr.package->id.value(), sr.type->id.value(), sr.entry->id.value());
Todd Kennedy196dbc32018-07-24 14:37:15 -0700197 symbol->is_dynamic = (sr.package->id.value() == 0);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700198 }
199
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800200 if (name.type == ResourceType::kAttr || name.type == ResourceType::kAttrPrivate) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700201 const ConfigDescription kDefaultConfig;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700202 ResourceConfigValue* config_value = sr.entry->FindValue(kDefaultConfig);
203 if (config_value) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700204 // This resource has an Attribute.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700205 if (Attribute* attr = ValueCast<Attribute>(config_value->value.get())) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700206 symbol->attribute = std::make_shared<Attribute>(*attr);
207 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700208 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700209 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700210 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700211 }
212 return symbol;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700213}
214
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700215bool AssetManagerSymbolSource::AddAssetPath(const StringPiece& path) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700216 int32_t cookie = 0;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800217 return assets_.addAssetPath(android::String8(path.data(), path.size()), &cookie);
218}
219
220std::map<size_t, std::string> AssetManagerSymbolSource::GetAssignedPackageIds() const {
221 std::map<size_t, std::string> package_map;
222 const android::ResTable& table = assets_.getResources(false);
223 const size_t package_count = table.getBasePackageCount();
224 for (size_t i = 0; i < package_count; i++) {
225 package_map[table.getBasePackageId(i)] =
226 util::Utf16ToUtf8(android::StringPiece16(table.getBasePackageName(i).string()));
227 }
228 return package_map;
Adam Lesinski64587af2016-02-18 18:33:06 -0800229}
230
Todd Kennedy32512992018-04-25 16:45:59 -0700231bool AssetManagerSymbolSource::IsPackageDynamic(uint32_t packageId) const {
232 return assets_.getResources(false).isPackageDynamic(packageId);
233}
234
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700235static std::unique_ptr<SymbolTable::Symbol> LookupAttributeInTable(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700236 const android::ResTable& table, ResourceId id) {
237 // Try as a bag.
238 const android::ResTable::bag_entry* entry;
239 ssize_t count = table.lockBag(id.id, &entry);
240 if (count < 0) {
241 table.unlockBag(entry);
242 return nullptr;
243 }
244
245 // We found a resource.
Adam Lesinskic744ae82017-05-17 19:28:38 -0700246 std::unique_ptr<SymbolTable::Symbol> s = util::make_unique<SymbolTable::Symbol>(id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700247
248 // Check to see if it is an attribute.
249 for (size_t i = 0; i < (size_t)count; i++) {
250 if (entry[i].map.name.ident == android::ResTable_map::ATTR_TYPE) {
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800251 s->attribute = std::make_shared<Attribute>(entry[i].map.value.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700252 break;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700253 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700254 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700255
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700256 if (s->attribute) {
257 for (size_t i = 0; i < (size_t)count; i++) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700258 const android::ResTable_map& map_entry = entry[i].map;
259 if (Res_INTERNALID(map_entry.name.ident)) {
260 switch (map_entry.name.ident) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700261 case android::ResTable_map::ATTR_MIN:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700262 s->attribute->min_int = static_cast<int32_t>(map_entry.value.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700263 break;
264 case android::ResTable_map::ATTR_MAX:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700265 s->attribute->max_int = static_cast<int32_t>(map_entry.value.data);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700266 break;
267 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700268 continue;
269 }
270
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700271 android::ResTable::resource_name entry_name;
272 if (!table.getResourceName(map_entry.name.ident, false, &entry_name)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700273 table.unlockBag(entry);
274 return nullptr;
275 }
276
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800277 Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(entry_name);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700278 if (!parsed_name) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700279 return nullptr;
280 }
281
282 Attribute::Symbol symbol;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700283 symbol.symbol.name = parsed_name.value();
284 symbol.symbol.id = ResourceId(map_entry.name.ident);
285 symbol.value = map_entry.value.data;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700286 s->attribute->symbols.push_back(std::move(symbol));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700287 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700288 }
289 table.unlockBag(entry);
290 return s;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700291}
292
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700293std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700294 const ResourceName& name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700295 const android::ResTable& table = assets_.getResources(false);
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700296
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700297 const std::u16string package16 = util::Utf8ToUtf16(name.package);
Adam Lesinski93190b72017-11-03 15:20:17 -0700298 const std::u16string type16 = util::Utf8ToUtf16(to_string(name.type));
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700299 const std::u16string entry16 = util::Utf8ToUtf16(name.entry);
Adam Lesinskidc785052017-12-07 15:58:46 -0800300 const std::u16string mangled_entry16 =
301 util::Utf8ToUtf16(NameMangler::MangleEntry(name.package, name.entry));
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700302
Adam Lesinskidc785052017-12-07 15:58:46 -0800303 uint32_t type_spec_flags;
304 ResourceId res_id;
305
306 // There can be mangled resources embedded within other packages. Here we will
307 // look into each package and look-up the mangled name until we find the resource.
308 const size_t count = table.getBasePackageCount();
309 for (size_t i = 0; i < count; i++) {
310 const android::String16 package_name = table.getBasePackageName(i);
311 StringPiece16 real_package16 = package16;
312 StringPiece16 real_entry16 = entry16;
313 std::u16string scratch_entry16;
314 if (StringPiece16(package_name) != package16) {
315 real_entry16 = mangled_entry16;
316 real_package16 = package_name.string();
317 }
318
319 type_spec_flags = 0;
320 res_id = table.identifierForName(real_entry16.data(), real_entry16.size(), type16.data(),
321 type16.size(), real_package16.data(), real_package16.size(),
322 &type_spec_flags);
323 if (res_id.is_valid()) {
324 break;
325 }
326 }
327
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700328 if (!res_id.is_valid()) {
Adam Lesinski64587af2016-02-18 18:33:06 -0800329 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700330 }
331
332 std::unique_ptr<SymbolTable::Symbol> s;
333 if (name.type == ResourceType::kAttr) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700334 s = LookupAttributeInTable(table, res_id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700335 } else {
336 s = util::make_unique<SymbolTable::Symbol>();
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700337 s->id = res_id;
Todd Kennedy32512992018-04-25 16:45:59 -0700338 s->is_dynamic = table.isResourceDynamic(res_id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700339 }
340
341 if (s) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800342 s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700343 return s;
344 }
345 return {};
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700346}
347
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700348static Maybe<ResourceName> GetResourceName(const android::ResTable& table,
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700349 ResourceId id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700350 android::ResTable::resource_name res_name = {};
351 if (!table.getResourceName(id.id, true, &res_name)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700352 return {};
353 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700354 return ResourceUtils::ToResourceName(res_name);
Adam Lesinski467f1712015-11-16 17:35:44 -0800355}
356
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700357std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700358 ResourceId id) {
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800359 if (!id.is_valid()) {
360 // Exit early and avoid the error logs from AssetManager.
361 return {};
362 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700363 const android::ResTable& table = assets_.getResources(false);
364 Maybe<ResourceName> maybe_name = GetResourceName(table, id);
365 if (!maybe_name) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700366 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700367 }
368
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700369 uint32_t type_spec_flags = 0;
370 table.getResourceFlags(id.id, &type_spec_flags);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700371
372 std::unique_ptr<SymbolTable::Symbol> s;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700373 if (maybe_name.value().type == ResourceType::kAttr) {
374 s = LookupAttributeInTable(table, id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700375 } else {
376 s = util::make_unique<SymbolTable::Symbol>();
377 s->id = id;
Todd Kennedy32512992018-04-25 16:45:59 -0700378 s->is_dynamic = table.isResourceDynamic(id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700379 }
380
381 if (s) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800382 s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700383 return s;
384 }
385 return {};
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700386}
387
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700388std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByReference(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700389 const Reference& ref) {
390 // AssetManager always prefers IDs.
391 if (ref.id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700392 return FindById(ref.id.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700393 } else if (ref.name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700394 return FindByName(ref.name.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700395 }
396 return {};
Adam Lesinski7656554f2016-03-10 21:55:04 -0800397}
398
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700399} // namespace aapt