blob: 8a3d047f6e8dcd3d1b3558c06e22395ad1d0f697 [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
17#include "ConfigDescription.h"
Adam Lesinski769de982015-04-10 19:43:55 -070018#include "NameMangler.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080019#include "ResourceTable.h"
20#include "ResourceValues.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070021#include "ValueVisitor.h"
Adam Lesinskie78fd612015-10-22 12:48:43 -070022
23#include "util/Comparators.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070024#include "util/Util.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080025
26#include <algorithm>
27#include <androidfw/ResourceTypes.h>
28#include <memory>
29#include <string>
30#include <tuple>
31
32namespace aapt {
33
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080034static bool lessThanType(const std::unique_ptr<ResourceTableType>& lhs, ResourceType rhs) {
35 return lhs->type < rhs;
36}
37
Adam Lesinski1ab598f2015-08-14 14:26:04 -070038template <typename T>
39static bool lessThanStructWithName(const std::unique_ptr<T>& lhs,
40 const StringPiece16& rhs) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080041 return lhs->name.compare(0, lhs->name.size(), rhs.data(), rhs.size()) < 0;
42}
43
Adam Lesinski1ab598f2015-08-14 14:26:04 -070044ResourceTablePackage* ResourceTable::findPackage(const StringPiece16& name) {
45 const auto last = packages.end();
46 auto iter = std::lower_bound(packages.begin(), last, name,
47 lessThanStructWithName<ResourceTablePackage>);
48 if (iter != last && name == (*iter)->name) {
49 return iter->get();
50 }
51 return nullptr;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080052}
53
Adam Lesinski1ab598f2015-08-14 14:26:04 -070054ResourceTablePackage* ResourceTable::findPackageById(uint8_t id) {
55 for (auto& package : packages) {
56 if (package->id && package->id.value() == id) {
57 return package.get();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080058 }
59 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070060 return nullptr;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080061}
62
Adam Lesinski9ba47d82015-10-13 11:37:10 -070063ResourceTablePackage* ResourceTable::createPackage(const StringPiece16& name, Maybe<uint8_t> id) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070064 ResourceTablePackage* package = findOrCreatePackage(name);
Adam Lesinski9ba47d82015-10-13 11:37:10 -070065 if (id && !package->id) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070066 package->id = id;
67 return package;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080068 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070069
Adam Lesinski9ba47d82015-10-13 11:37:10 -070070 if (id && package->id && package->id.value() != id.value()) {
71 return nullptr;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070072 }
Adam Lesinski9ba47d82015-10-13 11:37:10 -070073 return package;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080074}
75
Adam Lesinski1ab598f2015-08-14 14:26:04 -070076ResourceTablePackage* ResourceTable::findOrCreatePackage(const StringPiece16& name) {
77 const auto last = packages.end();
78 auto iter = std::lower_bound(packages.begin(), last, name,
79 lessThanStructWithName<ResourceTablePackage>);
80 if (iter != last && name == (*iter)->name) {
81 return iter->get();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080082 }
83
Adam Lesinski1ab598f2015-08-14 14:26:04 -070084 std::unique_ptr<ResourceTablePackage> newPackage = util::make_unique<ResourceTablePackage>();
85 newPackage->name = name.toString();
86 return packages.emplace(iter, std::move(newPackage))->get();
87}
88
89ResourceTableType* ResourceTablePackage::findType(ResourceType type) {
90 const auto last = types.end();
91 auto iter = std::lower_bound(types.begin(), last, type, lessThanType);
92 if (iter != last && (*iter)->type == type) {
93 return iter->get();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080094 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070095 return nullptr;
96}
97
98ResourceTableType* ResourceTablePackage::findOrCreateType(ResourceType type) {
99 const auto last = types.end();
100 auto iter = std::lower_bound(types.begin(), last, type, lessThanType);
101 if (iter != last && (*iter)->type == type) {
102 return iter->get();
103 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800104 return types.emplace(iter, new ResourceTableType(type))->get();
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700105}
106
107ResourceEntry* ResourceTableType::findEntry(const StringPiece16& name) {
108 const auto last = entries.end();
109 auto iter = std::lower_bound(entries.begin(), last, name,
110 lessThanStructWithName<ResourceEntry>);
111 if (iter != last && name == (*iter)->name) {
112 return iter->get();
113 }
114 return nullptr;
115}
116
117ResourceEntry* ResourceTableType::findOrCreateEntry(const StringPiece16& name) {
118 auto last = entries.end();
119 auto iter = std::lower_bound(entries.begin(), last, name,
120 lessThanStructWithName<ResourceEntry>);
121 if (iter != last && name == (*iter)->name) {
122 return iter->get();
123 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800124 return entries.emplace(iter, new ResourceEntry(name))->get();
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700125}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800126
127/**
128 * The default handler for collisions. A return value of -1 means keep the
129 * existing value, 0 means fail, and +1 means take the incoming value.
130 */
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700131int ResourceTable::resolveValueCollision(Value* existing, Value* incoming) {
132 Attribute* existingAttr = valueCast<Attribute>(existing);
133 Attribute* incomingAttr = valueCast<Attribute>(incoming);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800134
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700135 if (!incomingAttr) {
136 if (incoming->isWeak()) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800137 // We're trying to add a weak resource but a resource
138 // already exists. Keep the existing.
139 return -1;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700140 } else if (existing->isWeak()) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800141 // Override the weak resource with the new strong resource.
142 return 1;
143 }
144 // The existing and incoming values are strong, this is an error
145 // if the values are not both attributes.
146 return 0;
147 }
148
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700149 if (!existingAttr) {
150 if (existing->isWeak()) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800151 // The existing value is not an attribute and it is weak,
152 // so take the incoming attribute value.
153 return 1;
154 }
155 // The existing value is not an attribute and it is strong,
156 // so the incoming attribute value is an error.
157 return 0;
158 }
159
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700160 assert(incomingAttr && existingAttr);
161
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800162 //
163 // Attribute specific handling. At this point we know both
164 // values are attributes. Since we can declare and define
165 // attributes all-over, we do special handling to see
166 // which definition sticks.
167 //
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700168 if (existingAttr->typeMask == incomingAttr->typeMask) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800169 // The two attributes are both DECLs, but they are plain attributes
170 // with the same formats.
171 // Keep the strongest one.
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700172 return existingAttr->isWeak() ? 1 : -1;
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800173 }
174
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700175 if (existingAttr->isWeak() && existingAttr->typeMask == android::ResTable_map::TYPE_ANY) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800176 // Any incoming attribute is better than this.
177 return 1;
178 }
179
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700180 if (incomingAttr->isWeak() && incomingAttr->typeMask == android::ResTable_map::TYPE_ANY) {
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800181 // The incoming attribute may be a USE instead of a DECL.
182 // Keep the existing attribute.
183 return -1;
184 }
185 return 0;
186}
187
188static constexpr const char16_t* kValidNameChars = u"._-";
Adam Lesinski330edcd2015-05-04 17:40:56 -0700189static constexpr const char16_t* kValidNameMangledChars = u"._-$";
190
191bool ResourceTable::addResource(const ResourceNameRef& name, const ConfigDescription& config,
Adam Lesinskie78fd612015-10-22 12:48:43 -0700192 std::unique_ptr<Value> value, IDiagnostics* diag) {
Adam Lesinskifb48d292015-11-07 15:52:13 -0800193 return addResourceImpl(name, {}, config, std::move(value), kValidNameChars,
194 resolveValueCollision, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700195}
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800196
197bool ResourceTable::addResource(const ResourceNameRef& name, const ResourceId resId,
Adam Lesinskie78fd612015-10-22 12:48:43 -0700198 const ConfigDescription& config, std::unique_ptr<Value> value,
199 IDiagnostics* diag) {
Adam Lesinskifb48d292015-11-07 15:52:13 -0800200 return addResourceImpl(name, resId, config, std::move(value), kValidNameChars,
201 resolveValueCollision, diag);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700202}
203
204bool ResourceTable::addFileReference(const ResourceNameRef& name, const ConfigDescription& config,
205 const Source& source, const StringPiece16& path,
206 IDiagnostics* diag) {
Adam Lesinskifb48d292015-11-07 15:52:13 -0800207 return addFileReference(name, config, source, path, resolveValueCollision, diag);
208}
209
210bool ResourceTable::addFileReference(const ResourceNameRef& name, const ConfigDescription& config,
211 const Source& source, const StringPiece16& path,
212 std::function<int(Value*,Value*)> conflictResolver,
213 IDiagnostics* diag) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700214 std::unique_ptr<FileReference> fileRef = util::make_unique<FileReference>(
215 stringPool.makeRef(path));
216 fileRef->setSource(source);
Adam Lesinskifb48d292015-11-07 15:52:13 -0800217 return addResourceImpl(name, ResourceId{}, config, std::move(fileRef), kValidNameChars,
218 conflictResolver, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700219}
220
221bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name,
222 const ConfigDescription& config,
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700223 std::unique_ptr<Value> value,
224 IDiagnostics* diag) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700225 return addResourceImpl(name, ResourceId{}, config, std::move(value), kValidNameMangledChars,
Adam Lesinskifb48d292015-11-07 15:52:13 -0800226 resolveValueCollision, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700227}
228
Adam Lesinski9e10ac72015-10-16 14:37:48 -0700229bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name,
230 const ResourceId id,
231 const ConfigDescription& config,
Adam Lesinski9e10ac72015-10-16 14:37:48 -0700232 std::unique_ptr<Value> value,
233 IDiagnostics* diag) {
Adam Lesinskifb48d292015-11-07 15:52:13 -0800234 return addResourceImpl(name, id, config, std::move(value), kValidNameMangledChars,
235 resolveValueCollision, diag);
Adam Lesinski9e10ac72015-10-16 14:37:48 -0700236}
237
Adam Lesinskifb48d292015-11-07 15:52:13 -0800238bool ResourceTable::addResourceImpl(const ResourceNameRef& name,
239 const ResourceId resId,
240 const ConfigDescription& config,
241 std::unique_ptr<Value> value,
242 const char16_t* validChars,
243 std::function<int(Value*,Value*)> conflictResolver,
244 IDiagnostics* diag) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700245 assert(value && "value can't be nullptr");
246 assert(diag && "diagnostics can't be nullptr");
247
Adam Lesinski330edcd2015-05-04 17:40:56 -0700248 auto badCharIter = util::findNonAlphaNumericAndNotInSet(name.entry, validChars);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800249 if (badCharIter != name.entry.end()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700250 diag->error(DiagMessage(value->getSource())
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700251 << "resource '"
252 << name
253 << "' has invalid entry name '"
254 << name.entry
255 << "'. Invalid character '"
256 << StringPiece16(badCharIter, 1)
257 << "'");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800258 return false;
259 }
260
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700261 ResourceTablePackage* package = findOrCreatePackage(name.package);
262 if (resId.isValid() && package->id && package->id.value() != resId.packageId()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700263 diag->error(DiagMessage(value->getSource())
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700264 << "trying to add resource '"
265 << name
266 << "' with ID "
267 << resId
268 << " but package '"
269 << package->name
270 << "' already has ID "
271 << std::hex << (int) package->id.value() << std::dec);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800272 return false;
273 }
274
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700275 ResourceTableType* type = package->findOrCreateType(name.type);
276 if (resId.isValid() && type->id && type->id.value() != resId.typeId()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700277 diag->error(DiagMessage(value->getSource())
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700278 << "trying to add resource '"
279 << name
280 << "' with ID "
281 << resId
282 << " but type '"
283 << type->type
284 << "' already has ID "
285 << std::hex << (int) type->id.value() << std::dec);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800286 return false;
287 }
288
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700289 ResourceEntry* entry = type->findOrCreateEntry(name.entry);
290 if (resId.isValid() && entry->id && entry->id.value() != resId.entryId()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700291 diag->error(DiagMessage(value->getSource())
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700292 << "trying to add resource '"
293 << name
294 << "' with ID "
295 << resId
296 << " but resource already has ID "
297 << ResourceId(package->id.value(), type->id.value(), entry->id.value()));
298 return false;
299 }
300
301 const auto endIter = entry->values.end();
Adam Lesinskib274e352015-11-06 15:14:35 -0800302 auto iter = std::lower_bound(entry->values.begin(), endIter, config, cmp::lessThanConfig);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800303 if (iter == endIter || iter->config != config) {
304 // This resource did not exist before, add it.
Adam Lesinskie78fd612015-10-22 12:48:43 -0700305 entry->values.insert(iter, ResourceConfigValue{ config, std::move(value) });
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800306 } else {
Adam Lesinskifb48d292015-11-07 15:52:13 -0800307 int collisionResult = conflictResolver(iter->value.get(), value.get());
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800308 if (collisionResult > 0) {
309 // Take the incoming value.
Adam Lesinskie78fd612015-10-22 12:48:43 -0700310 iter->value = std::move(value);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800311 } else if (collisionResult == 0) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700312 diag->error(DiagMessage(value->getSource())
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700313 << "duplicate value for resource '" << name << "' "
Adam Lesinskie78fd612015-10-22 12:48:43 -0700314 << "with config '" << config << "'");
315 diag->error(DiagMessage(iter->value->getSource())
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700316 << "resource previously defined here");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800317 return false;
318 }
319 }
320
321 if (resId.isValid()) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700322 package->id = resId.packageId();
323 type->id = resId.typeId();
324 entry->id = resId.entryId();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800325 }
326 return true;
327}
328
Adam Lesinski9e10ac72015-10-16 14:37:48 -0700329bool ResourceTable::setSymbolState(const ResourceNameRef& name, const ResourceId resId,
Adam Lesinskie78fd612015-10-22 12:48:43 -0700330 const Symbol& symbol, IDiagnostics* diag) {
331 return setSymbolStateImpl(name, resId, symbol, kValidNameChars, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700332}
333
Adam Lesinskie78fd612015-10-22 12:48:43 -0700334bool ResourceTable::setSymbolStateAllowMangled(const ResourceNameRef& name,
335 const ResourceId resId,
336 const Symbol& symbol, IDiagnostics* diag) {
337 return setSymbolStateImpl(name, resId, symbol, kValidNameMangledChars, diag);
Adam Lesinski330edcd2015-05-04 17:40:56 -0700338}
339
Adam Lesinski9e10ac72015-10-16 14:37:48 -0700340bool ResourceTable::setSymbolStateImpl(const ResourceNameRef& name, const ResourceId resId,
Adam Lesinskie78fd612015-10-22 12:48:43 -0700341 const Symbol& symbol, const char16_t* validChars,
342 IDiagnostics* diag) {
343 assert(diag && "diagnostics can't be nullptr");
344
Adam Lesinski330edcd2015-05-04 17:40:56 -0700345 auto badCharIter = util::findNonAlphaNumericAndNotInSet(name.entry, validChars);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800346 if (badCharIter != name.entry.end()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700347 diag->error(DiagMessage(symbol.source)
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700348 << "resource '"
349 << name
350 << "' has invalid entry name '"
351 << name.entry
352 << "'. Invalid character '"
353 << StringPiece16(badCharIter, 1)
354 << "'");
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800355 return false;
356 }
357
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700358 ResourceTablePackage* package = findOrCreatePackage(name.package);
359 if (resId.isValid() && package->id && package->id.value() != resId.packageId()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700360 diag->error(DiagMessage(symbol.source)
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700361 << "trying to add resource '"
362 << name
363 << "' with ID "
364 << resId
365 << " but package '"
366 << package->name
367 << "' already has ID "
368 << std::hex << (int) package->id.value() << std::dec);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800369 return false;
370 }
371
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700372 ResourceTableType* type = package->findOrCreateType(name.type);
373 if (resId.isValid() && type->id && type->id.value() != resId.typeId()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700374 diag->error(DiagMessage(symbol.source)
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700375 << "trying to add resource '"
376 << name
377 << "' with ID "
378 << resId
379 << " but type '"
380 << type->type
381 << "' already has ID "
382 << std::hex << (int) type->id.value() << std::dec);
383 return false;
384 }
385
386 ResourceEntry* entry = type->findOrCreateEntry(name.entry);
387 if (resId.isValid() && entry->id && entry->id.value() != resId.entryId()) {
Adam Lesinskie78fd612015-10-22 12:48:43 -0700388 diag->error(DiagMessage(symbol.source)
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700389 << "trying to add resource '"
390 << name
391 << "' with ID "
392 << resId
393 << " but resource already has ID "
394 << ResourceId(package->id.value(), type->id.value(), entry->id.value()));
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800395 return false;
396 }
397
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800398 if (resId.isValid()) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700399 package->id = resId.packageId();
400 type->id = resId.typeId();
401 entry->id = resId.entryId();
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800402 }
Adam Lesinskia6fe3452015-12-09 15:20:52 -0800403
404 // Only mark the type state as public, it doesn't care about being private.
405 if (symbol.state == SymbolState::kPublic) {
406 type->symbolStatus.state = SymbolState::kPublic;
407 }
408
409 if (symbol.state == SymbolState::kUndefined &&
410 entry->symbolStatus.state != SymbolState::kUndefined) {
411 // We can't undefine a symbol (remove its visibility). Ignore.
412 return true;
413 }
414
415 if (symbol.state == SymbolState::kPrivate &&
416 entry->symbolStatus.state == SymbolState::kPublic) {
417 // We can't downgrade public to private. Ignore.
418 return true;
419 }
420
421 entry->symbolStatus = std::move(symbol);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800422 return true;
423}
424
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700425Maybe<ResourceTable::SearchResult>
426ResourceTable::findResource(const ResourceNameRef& name) {
427 ResourceTablePackage* package = findPackage(name.package);
428 if (!package) {
Adam Lesinskica2fc352015-04-03 12:08:26 -0700429 return {};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800430 }
431
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700432 ResourceTableType* type = package->findType(name.type);
433 if (!type) {
Adam Lesinskica2fc352015-04-03 12:08:26 -0700434 return {};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800435 }
436
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700437 ResourceEntry* entry = type->findEntry(name.entry);
438 if (!entry) {
Adam Lesinskica2fc352015-04-03 12:08:26 -0700439 return {};
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800440 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700441 return SearchResult{ package, type, entry };
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800442}
443
444} // namespace aapt