blob: fc4c9b537e733561674dcc04daa7cf3fbfa8903f [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 Lesinski76565542016-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 Lesinski76565542016-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());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700197 }
198
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800199 if (name.type == ResourceType::kAttr || name.type == ResourceType::kAttrPrivate) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700200 const ConfigDescription kDefaultConfig;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700201 ResourceConfigValue* config_value = sr.entry->FindValue(kDefaultConfig);
202 if (config_value) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700203 // This resource has an Attribute.
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700204 if (Attribute* attr = ValueCast<Attribute>(config_value->value.get())) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700205 symbol->attribute = std::make_shared<Attribute>(*attr);
206 } else {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700207 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700208 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700209 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700210 }
211 return symbol;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700212}
213
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700214bool AssetManagerSymbolSource::AddAssetPath(const StringPiece& path) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700215 int32_t cookie = 0;
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800216 return assets_.addAssetPath(android::String8(path.data(), path.size()), &cookie);
217}
218
219std::map<size_t, std::string> AssetManagerSymbolSource::GetAssignedPackageIds() const {
220 std::map<size_t, std::string> package_map;
221 const android::ResTable& table = assets_.getResources(false);
222 const size_t package_count = table.getBasePackageCount();
223 for (size_t i = 0; i < package_count; i++) {
224 package_map[table.getBasePackageId(i)] =
225 util::Utf16ToUtf8(android::StringPiece16(table.getBasePackageName(i).string()));
226 }
227 return package_map;
Adam Lesinski64587af2016-02-18 18:33:06 -0800228}
229
Todd Kennedy32512992018-04-25 16:45:59 -0700230bool AssetManagerSymbolSource::IsPackageDynamic(uint32_t packageId) const {
231 return assets_.getResources(false).isPackageDynamic(packageId);
232}
233
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700234static std::unique_ptr<SymbolTable::Symbol> LookupAttributeInTable(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700235 const android::ResTable& table, ResourceId id) {
236 // Try as a bag.
237 const android::ResTable::bag_entry* entry;
238 ssize_t count = table.lockBag(id.id, &entry);
239 if (count < 0) {
240 table.unlockBag(entry);
241 return nullptr;
242 }
243
244 // We found a resource.
Adam Lesinskic744ae82017-05-17 19:28:38 -0700245 std::unique_ptr<SymbolTable::Symbol> s = util::make_unique<SymbolTable::Symbol>(id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700246
247 // Check to see if it is an attribute.
248 for (size_t i = 0; i < (size_t)count; i++) {
249 if (entry[i].map.name.ident == android::ResTable_map::ATTR_TYPE) {
Adam Lesinski73bff1e2017-12-08 16:06:10 -0800250 s->attribute = std::make_shared<Attribute>(entry[i].map.value.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700251 break;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700252 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700253 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700254
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700255 if (s->attribute) {
256 for (size_t i = 0; i < (size_t)count; i++) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700257 const android::ResTable_map& map_entry = entry[i].map;
258 if (Res_INTERNALID(map_entry.name.ident)) {
259 switch (map_entry.name.ident) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700260 case android::ResTable_map::ATTR_MIN:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700261 s->attribute->min_int = static_cast<int32_t>(map_entry.value.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700262 break;
263 case android::ResTable_map::ATTR_MAX:
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700264 s->attribute->max_int = static_cast<int32_t>(map_entry.value.data);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700265 break;
266 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700267 continue;
268 }
269
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700270 android::ResTable::resource_name entry_name;
271 if (!table.getResourceName(map_entry.name.ident, false, &entry_name)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700272 table.unlockBag(entry);
273 return nullptr;
274 }
275
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800276 Maybe<ResourceName> parsed_name = ResourceUtils::ToResourceName(entry_name);
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700277 if (!parsed_name) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700278 return nullptr;
279 }
280
281 Attribute::Symbol symbol;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700282 symbol.symbol.name = parsed_name.value();
283 symbol.symbol.id = ResourceId(map_entry.name.ident);
284 symbol.value = map_entry.value.data;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700285 s->attribute->symbols.push_back(std::move(symbol));
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700286 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700287 }
288 table.unlockBag(entry);
289 return s;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700290}
291
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700292std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByName(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700293 const ResourceName& name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700294 const android::ResTable& table = assets_.getResources(false);
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700295
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700296 const std::u16string package16 = util::Utf8ToUtf16(name.package);
Adam Lesinski93190b72017-11-03 15:20:17 -0700297 const std::u16string type16 = util::Utf8ToUtf16(to_string(name.type));
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700298 const std::u16string entry16 = util::Utf8ToUtf16(name.entry);
Adam Lesinskidc785052017-12-07 15:58:46 -0800299 const std::u16string mangled_entry16 =
300 util::Utf8ToUtf16(NameMangler::MangleEntry(name.package, name.entry));
Adam Lesinskid0f116b2016-07-08 15:00:32 -0700301
Adam Lesinskidc785052017-12-07 15:58:46 -0800302 uint32_t type_spec_flags;
303 ResourceId res_id;
304
305 // There can be mangled resources embedded within other packages. Here we will
306 // look into each package and look-up the mangled name until we find the resource.
307 const size_t count = table.getBasePackageCount();
308 for (size_t i = 0; i < count; i++) {
309 const android::String16 package_name = table.getBasePackageName(i);
310 StringPiece16 real_package16 = package16;
311 StringPiece16 real_entry16 = entry16;
312 std::u16string scratch_entry16;
313 if (StringPiece16(package_name) != package16) {
314 real_entry16 = mangled_entry16;
315 real_package16 = package_name.string();
316 }
317
318 type_spec_flags = 0;
319 res_id = table.identifierForName(real_entry16.data(), real_entry16.size(), type16.data(),
320 type16.size(), real_package16.data(), real_package16.size(),
321 &type_spec_flags);
322 if (res_id.is_valid()) {
323 break;
324 }
325 }
326
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700327 if (!res_id.is_valid()) {
Adam Lesinski64587af2016-02-18 18:33:06 -0800328 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700329 }
330
331 std::unique_ptr<SymbolTable::Symbol> s;
332 if (name.type == ResourceType::kAttr) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700333 s = LookupAttributeInTable(table, res_id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700334 } else {
335 s = util::make_unique<SymbolTable::Symbol>();
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700336 s->id = res_id;
Todd Kennedy32512992018-04-25 16:45:59 -0700337 s->is_dynamic = table.isResourceDynamic(res_id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700338 }
339
340 if (s) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800341 s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700342 return s;
343 }
344 return {};
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700345}
346
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700347static Maybe<ResourceName> GetResourceName(const android::ResTable& table,
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700348 ResourceId id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700349 android::ResTable::resource_name res_name = {};
350 if (!table.getResourceName(id.id, true, &res_name)) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700351 return {};
352 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700353 return ResourceUtils::ToResourceName(res_name);
Adam Lesinski467f1712015-11-16 17:35:44 -0800354}
355
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700356std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindById(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700357 ResourceId id) {
Adam Lesinskib5dc4bd2017-02-22 19:29:29 -0800358 if (!id.is_valid()) {
359 // Exit early and avoid the error logs from AssetManager.
360 return {};
361 }
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700362 const android::ResTable& table = assets_.getResources(false);
363 Maybe<ResourceName> maybe_name = GetResourceName(table, id);
364 if (!maybe_name) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700365 return {};
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700366 }
367
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700368 uint32_t type_spec_flags = 0;
369 table.getResourceFlags(id.id, &type_spec_flags);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700370
371 std::unique_ptr<SymbolTable::Symbol> s;
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700372 if (maybe_name.value().type == ResourceType::kAttr) {
373 s = LookupAttributeInTable(table, id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700374 } else {
375 s = util::make_unique<SymbolTable::Symbol>();
376 s->id = id;
Todd Kennedy32512992018-04-25 16:45:59 -0700377 s->is_dynamic = table.isResourceDynamic(id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700378 }
379
380 if (s) {
Adam Lesinskiceb9b2f2017-02-16 12:05:42 -0800381 s->is_public = (type_spec_flags & android::ResTable_typeSpec::SPEC_PUBLIC) != 0;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700382 return s;
383 }
384 return {};
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700385}
386
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700387std::unique_ptr<SymbolTable::Symbol> AssetManagerSymbolSource::FindByReference(
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700388 const Reference& ref) {
389 // AssetManager always prefers IDs.
390 if (ref.id) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700391 return FindById(ref.id.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700392 } else if (ref.name) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700393 return FindByName(ref.name.value());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700394 }
395 return {};
Adam Lesinski76565542016-03-10 21:55:04 -0800396}
397
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700398} // namespace aapt