blob: 2c6be41052e8425d8b0d4ccf4272740412585ee0 [file] [log] [blame]
Adam Lesinski7ad11102016-10-28 16:39:15 -07001/*
2 * Copyright (C) 2016 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#define ATRACE_TAG ATRACE_TAG_RESOURCES
18
19#include "androidfw/AssetManager2.h"
20
y57cd1952018-04-12 14:26:23 -070021#include <algorithm>
Adam Lesinski30080e22017-10-16 16:18:09 -070022#include <iterator>
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -070023#include <map>
Winson2f3669b2019-01-11 11:28:34 -080024#include <set>
Adam Lesinski0c405242017-01-13 20:47:26 -080025
Adam Lesinski7ad11102016-10-28 16:39:15 -070026#include "android-base/logging.h"
27#include "android-base/stringprintf.h"
Ryan Mitchellfe50d732019-12-19 16:12:35 -080028#include "androidfw/DynamicLibManager.h"
Ryan Mitchell8a891d82019-07-01 09:48:23 -070029#include "androidfw/ResourceUtils.h"
Ryan Mitchell31b11052019-06-13 13:47:26 -070030#include "androidfw/Util.h"
Adam Lesinski7ad11102016-10-28 16:39:15 -070031#include "utils/ByteOrder.h"
32#include "utils/Trace.h"
33
34#ifdef _WIN32
35#ifdef ERROR
36#undef ERROR
37#endif
38#endif
39
40namespace android {
41
Adam Lesinskibebfcc42018-02-12 14:27:46 -080042struct FindEntryResult {
43 // A pointer to the resource table entry for this resource.
44 // If the size of the entry is > sizeof(ResTable_entry), it can be cast to
45 // a ResTable_map_entry and processed as a bag/map.
Ryan Mitchell8a891d82019-07-01 09:48:23 -070046 ResTable_entry_handle entry;
Adam Lesinskibebfcc42018-02-12 14:27:46 -080047
48 // The configuration for which the resulting entry was defined. This is already swapped to host
49 // endianness.
50 ResTable_config config;
51
52 // The bitmask of configuration axis with which the resource value varies.
53 uint32_t type_flags;
54
55 // The dynamic package ID map for the package from which this resource came from.
56 const DynamicRefTable* dynamic_ref_table;
57
Ryan Mitchell8a891d82019-07-01 09:48:23 -070058 // The package name of the resource.
59 const std::string* package_name;
60
Adam Lesinskibebfcc42018-02-12 14:27:46 -080061 // The string pool reference to the type's name. This uses a different string pool than
62 // the global string pool, but this is hidden from the caller.
63 StringPoolRef type_string_ref;
64
65 // The string pool reference to the entry's name. This uses a different string pool than
66 // the global string pool, but this is hidden from the caller.
67 StringPoolRef entry_string_ref;
68};
69
Ryan Mitchellfe50d732019-12-19 16:12:35 -080070AssetManager2::AssetManager2() : dynamic_lib_manager_(std::make_unique<DynamicLibManager>()) {
71 memset(&configuration_, 0, sizeof(configuration_));
72}
73
74AssetManager2::AssetManager2(DynamicLibManager* dynamic_lib_manager)
75 : dynamic_lib_manager_(dynamic_lib_manager) {
Adam Lesinski970bd8d2017-09-25 13:21:55 -070076 memset(&configuration_, 0, sizeof(configuration_));
77}
Adam Lesinski7ad11102016-10-28 16:39:15 -070078
79bool AssetManager2::SetApkAssets(const std::vector<const ApkAssets*>& apk_assets,
Mårten Kongstad668ec5b2018-06-11 14:11:33 +020080 bool invalidate_caches, bool filter_incompatible_configs) {
Adam Lesinski7ad11102016-10-28 16:39:15 -070081 apk_assets_ = apk_assets;
Adam Lesinskida431a22016-12-29 16:08:16 -050082 BuildDynamicRefTable();
Mårten Kongstad668ec5b2018-06-11 14:11:33 +020083 RebuildFilterList(filter_incompatible_configs);
Adam Lesinski7ad11102016-10-28 16:39:15 -070084 if (invalidate_caches) {
85 InvalidateCaches(static_cast<uint32_t>(-1));
86 }
87 return true;
88}
89
Adam Lesinskida431a22016-12-29 16:08:16 -050090void AssetManager2::BuildDynamicRefTable() {
91 package_groups_.clear();
92 package_ids_.fill(0xff);
93
Ryan Mitchellfe50d732019-12-19 16:12:35 -080094 // Overlay resources are not directly referenced by an application so their resource ids
95 // can change throughout the application's lifetime. Assign overlay package ids last.
96 std::vector<const ApkAssets*> sorted_apk_assets(apk_assets_);
97 std::stable_partition(sorted_apk_assets.begin(), sorted_apk_assets.end(), [](const ApkAssets* a) {
98 return !a->IsOverlay();
99 });
100
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700101 std::unordered_map<std::string, uint8_t> apk_assets_package_ids;
Ryan Mitchellfe50d732019-12-19 16:12:35 -0800102 std::unordered_map<std::string, uint8_t> package_name_package_ids;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700103
Ryan Mitchellfe50d732019-12-19 16:12:35 -0800104 // Assign stable package ids to application packages.
105 uint8_t next_available_package_id = 0U;
106 for (const auto& apk_assets : sorted_apk_assets) {
107 for (const auto& package : apk_assets->GetLoadedArsc()->GetPackages()) {
108 uint8_t package_id = package->GetPackageId();
109 if (package->IsOverlay()) {
110 package_id = GetDynamicLibManager()->FindUnassignedId(next_available_package_id);
111 next_available_package_id = package_id + 1;
112 } else if (package->IsDynamic()) {
113 package_id = GetDynamicLibManager()->GetAssignedId(package->GetPackageName());
Adam Lesinskida431a22016-12-29 16:08:16 -0500114 }
115
Ryan Mitchellfe50d732019-12-19 16:12:35 -0800116 // Map the path of the apk assets to the package id of its first loaded package.
117 apk_assets_package_ids[apk_assets->GetPath()] = package_id;
118
119 // Map the package name of the package to the first loaded package with that package id.
120 package_name_package_ids[package->GetPackageName()] = package_id;
121 }
122 }
123
124 const int apk_assets_count = apk_assets_.size();
125 for (int i = 0; i < apk_assets_count; i++) {
126 const auto& apk_assets = apk_assets_[i];
127 for (const auto& package : apk_assets->GetLoadedArsc()->GetPackages()) {
128 const auto package_id_entry = package_name_package_ids.find(package->GetPackageName());
129 CHECK(package_id_entry != package_name_package_ids.end())
130 << "no package id assgined to package " << package->GetPackageName();
131 const uint8_t package_id = package_id_entry->second;
132
Adam Lesinskida431a22016-12-29 16:08:16 -0500133 // Add the mapping for package ID to index if not present.
134 uint8_t idx = package_ids_[package_id];
135 if (idx == 0xff) {
136 package_ids_[package_id] = idx = static_cast<uint8_t>(package_groups_.size());
137 package_groups_.push_back({});
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700138
139 if (apk_assets->IsOverlay()) {
140 // The target package must precede the overlay package in the apk assets paths in order
141 // to take effect.
142 const auto& loaded_idmap = apk_assets->GetLoadedIdmap();
143 auto target_package_iter = apk_assets_package_ids.find(loaded_idmap->TargetApkPath());
144 if (target_package_iter != apk_assets_package_ids.end()) {
145 const uint8_t target_package_id = target_package_iter->second;
146 const uint8_t target_idx = package_ids_[target_package_id];
147 CHECK(target_idx != 0xff) << "overlay added to apk_assets_package_ids but does not"
148 << " have an assigned package group";
149
150 PackageGroup& target_package_group = package_groups_[target_idx];
151
Ryan Mitchellfe50d732019-12-19 16:12:35 -0800152 // Create a special dynamic reference table for the overlay to rewrite references to
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700153 // overlay resources as references to the target resources they overlay.
154 auto overlay_table = std::make_shared<OverlayDynamicRefTable>(
155 loaded_idmap->GetOverlayDynamicRefTable(target_package_id));
156 package_groups_.back().dynamic_ref_table = overlay_table;
157
158 // Add the overlay resource map to the target package's set of overlays.
159 target_package_group.overlays_.push_back(
160 ConfiguredOverlay{loaded_idmap->GetTargetResourcesMap(target_package_id,
161 overlay_table.get()),
162 static_cast<ApkAssetsCookie>(i)});
163 }
164 }
165
166 DynamicRefTable* ref_table = package_groups_.back().dynamic_ref_table.get();
167 ref_table->mAssignedPackageId = package_id;
168 ref_table->mAppAsLib = package->IsDynamic() && package->GetPackageId() == 0x7f;
Adam Lesinskida431a22016-12-29 16:08:16 -0500169 }
170 PackageGroup* package_group = &package_groups_[idx];
171
172 // Add the package and to the set of packages with the same ID.
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800173 package_group->packages_.push_back(ConfiguredPackage{package.get(), {}});
Adam Lesinskida431a22016-12-29 16:08:16 -0500174 package_group->cookies_.push_back(static_cast<ApkAssetsCookie>(i));
175
176 // Add the package name -> build time ID mappings.
177 for (const DynamicPackageEntry& entry : package->GetDynamicPackageMap()) {
178 String16 package_name(entry.package_name.c_str(), entry.package_name.size());
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700179 package_group->dynamic_ref_table->mEntries.replaceValueFor(
Adam Lesinskida431a22016-12-29 16:08:16 -0500180 package_name, static_cast<uint8_t>(entry.package_id));
181 }
182 }
183 }
184
185 // Now assign the runtime IDs so that we have a build-time to runtime ID map.
186 const auto package_groups_end = package_groups_.end();
187 for (auto iter = package_groups_.begin(); iter != package_groups_end; ++iter) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800188 const std::string& package_name = iter->packages_[0].loaded_package_->GetPackageName();
Adam Lesinskida431a22016-12-29 16:08:16 -0500189 for (auto iter2 = package_groups_.begin(); iter2 != package_groups_end; ++iter2) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700190 iter2->dynamic_ref_table->addMapping(String16(package_name.c_str(), package_name.size()),
191 iter->dynamic_ref_table->mAssignedPackageId);
Adam Lesinskida431a22016-12-29 16:08:16 -0500192 }
193 }
194}
195
196void AssetManager2::DumpToLog() const {
197 base::ScopedLogSeverity _log(base::INFO);
198
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800199 LOG(INFO) << base::StringPrintf("AssetManager2(this=%p)", this);
200
Adam Lesinskida431a22016-12-29 16:08:16 -0500201 std::string list;
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800202 for (const auto& apk_assets : apk_assets_) {
203 base::StringAppendF(&list, "%s,", apk_assets->GetPath().c_str());
204 }
205 LOG(INFO) << "ApkAssets: " << list;
206
207 list = "";
Adam Lesinskida431a22016-12-29 16:08:16 -0500208 for (size_t i = 0; i < package_ids_.size(); i++) {
209 if (package_ids_[i] != 0xff) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800210 base::StringAppendF(&list, "%02x -> %d, ", (int)i, package_ids_[i]);
Adam Lesinskida431a22016-12-29 16:08:16 -0500211 }
212 }
213 LOG(INFO) << "Package ID map: " << list;
214
Adam Lesinski0dd36992018-01-25 15:38:38 -0800215 for (const auto& package_group: package_groups_) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800216 list = "";
217 for (const auto& package : package_group.packages_) {
218 const LoadedPackage* loaded_package = package.loaded_package_;
219 base::StringAppendF(&list, "%s(%02x%s), ", loaded_package->GetPackageName().c_str(),
220 loaded_package->GetPackageId(),
221 (loaded_package->IsDynamic() ? " dynamic" : ""));
222 }
223 LOG(INFO) << base::StringPrintf("PG (%02x): ",
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700224 package_group.dynamic_ref_table->mAssignedPackageId)
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800225 << list;
Ryan Mitchell5db396d2018-11-05 15:56:15 -0800226
227 for (size_t i = 0; i < 256; i++) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700228 if (package_group.dynamic_ref_table->mLookupTable[i] != 0) {
Ryan Mitchell5db396d2018-11-05 15:56:15 -0800229 LOG(INFO) << base::StringPrintf(" e[0x%02x] -> 0x%02x", (uint8_t) i,
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700230 package_group.dynamic_ref_table->mLookupTable[i]);
Ryan Mitchell5db396d2018-11-05 15:56:15 -0800231 }
232 }
Adam Lesinskida431a22016-12-29 16:08:16 -0500233 }
234}
Adam Lesinski7ad11102016-10-28 16:39:15 -0700235
236const ResStringPool* AssetManager2::GetStringPoolForCookie(ApkAssetsCookie cookie) const {
237 if (cookie < 0 || static_cast<size_t>(cookie) >= apk_assets_.size()) {
238 return nullptr;
239 }
240 return apk_assets_[cookie]->GetLoadedArsc()->GetStringPool();
241}
242
Adam Lesinskida431a22016-12-29 16:08:16 -0500243const DynamicRefTable* AssetManager2::GetDynamicRefTableForPackage(uint32_t package_id) const {
244 if (package_id >= package_ids_.size()) {
245 return nullptr;
246 }
247
248 const size_t idx = package_ids_[package_id];
249 if (idx == 0xff) {
250 return nullptr;
251 }
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700252 return package_groups_[idx].dynamic_ref_table.get();
Adam Lesinskida431a22016-12-29 16:08:16 -0500253}
254
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700255std::shared_ptr<const DynamicRefTable> AssetManager2::GetDynamicRefTableForCookie(
256 ApkAssetsCookie cookie) const {
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800257 for (const PackageGroup& package_group : package_groups_) {
258 for (const ApkAssetsCookie& package_cookie : package_group.cookies_) {
259 if (package_cookie == cookie) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700260 return package_group.dynamic_ref_table;
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800261 }
262 }
263 }
264 return nullptr;
265}
266
Mårten Kongstadc92c4dd2019-02-05 01:29:59 +0100267const std::unordered_map<std::string, std::string>*
268 AssetManager2::GetOverlayableMapForPackage(uint32_t package_id) const {
269
270 if (package_id >= package_ids_.size()) {
271 return nullptr;
272 }
273
274 const size_t idx = package_ids_[package_id];
275 if (idx == 0xff) {
276 return nullptr;
277 }
278
279 const PackageGroup& package_group = package_groups_[idx];
280 if (package_group.packages_.size() == 0) {
281 return nullptr;
282 }
283
284 const auto loaded_package = package_group.packages_[0].loaded_package_;
285 return &loaded_package->GetOverlayableMap();
286}
287
Ryan Mitchell2e394222019-08-28 12:10:51 -0700288bool AssetManager2::GetOverlayablesToString(const android::StringPiece& package_name,
289 std::string* out) const {
290 uint8_t package_id = 0U;
291 for (const auto& apk_assets : apk_assets_) {
292 const LoadedArsc* loaded_arsc = apk_assets->GetLoadedArsc();
293 if (loaded_arsc == nullptr) {
294 continue;
295 }
296
297 const auto& loaded_packages = loaded_arsc->GetPackages();
298 if (loaded_packages.empty()) {
299 continue;
300 }
301
302 const auto& loaded_package = loaded_packages[0];
303 if (loaded_package->GetPackageName() == package_name) {
304 package_id = GetAssignedPackageId(loaded_package.get());
305 break;
306 }
307 }
308
309 if (package_id == 0U) {
310 ANDROID_LOG(ERROR) << base::StringPrintf("No package with name '%s", package_name.data());
311 return false;
312 }
313
314 const size_t idx = package_ids_[package_id];
315 if (idx == 0xff) {
316 return false;
317 }
318
319 std::string output;
320 for (const ConfiguredPackage& package : package_groups_[idx].packages_) {
321 const LoadedPackage* loaded_package = package.loaded_package_;
322 for (auto it = loaded_package->begin(); it != loaded_package->end(); it++) {
323 const OverlayableInfo* info = loaded_package->GetOverlayableInfo(*it);
324 if (info != nullptr) {
325 ResourceName res_name;
326 if (!GetResourceName(*it, &res_name)) {
327 ANDROID_LOG(ERROR) << base::StringPrintf(
328 "Unable to retrieve name of overlayable resource 0x%08x", *it);
329 return false;
330 }
331
332 const std::string name = ToFormattedResourceString(&res_name);
333 output.append(base::StringPrintf(
334 "resource='%s' overlayable='%s' actor='%s' policy='0x%08x'\n",
335 name.c_str(), info->name.c_str(), info->actor.c_str(), info->policy_flags));
336 }
337 }
338 }
339
340 *out = std::move(output);
341 return true;
342}
343
Adam Lesinski7ad11102016-10-28 16:39:15 -0700344void AssetManager2::SetConfiguration(const ResTable_config& configuration) {
345 const int diff = configuration_.diff(configuration);
346 configuration_ = configuration;
347
348 if (diff) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800349 RebuildFilterList();
Adam Lesinski7ad11102016-10-28 16:39:15 -0700350 InvalidateCaches(static_cast<uint32_t>(diff));
351 }
352}
353
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700354std::set<std::string> AssetManager2::GetNonSystemOverlayPaths() const {
355 std::set<std::string> non_system_overlays;
Adam Lesinski0c405242017-01-13 20:47:26 -0800356 for (const PackageGroup& package_group : package_groups_) {
Ryan Mitchell449a54f2018-11-30 15:22:31 -0800357 bool found_system_package = false;
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800358 for (const ConfiguredPackage& package : package_group.packages_) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700359 if (package.loaded_package_->IsSystem()) {
Ryan Mitchell449a54f2018-11-30 15:22:31 -0800360 found_system_package = true;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700361 break;
362 }
363 }
364
365 if (!found_system_package) {
366 for (const ConfiguredOverlay& overlay : package_group.overlays_) {
367 non_system_overlays.insert(apk_assets_[overlay.cookie]->GetPath());
368 }
369 }
370 }
371
372 return non_system_overlays;
373}
374
375std::set<ResTable_config> AssetManager2::GetResourceConfigurations(bool exclude_system,
376 bool exclude_mipmap) const {
377 ATRACE_NAME("AssetManager::GetResourceConfigurations");
378 const auto non_system_overlays =
379 (exclude_system) ? GetNonSystemOverlayPaths() : std::set<std::string>();
380
381 std::set<ResTable_config> configurations;
382 for (const PackageGroup& package_group : package_groups_) {
383 for (size_t i = 0; i < package_group.packages_.size(); i++) {
384 const ConfiguredPackage& package = package_group.packages_[i];
385 if (exclude_system && package.loaded_package_->IsSystem()) {
Adam Lesinski0c405242017-01-13 20:47:26 -0800386 continue;
387 }
Ryan Mitchell449a54f2018-11-30 15:22:31 -0800388
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700389 auto apk_assets = apk_assets_[package_group.cookies_[i]];
390 if (exclude_system && apk_assets->IsOverlay()
391 && non_system_overlays.find(apk_assets->GetPath()) == non_system_overlays.end()) {
392 // Exclude overlays that target system resources.
Ryan Mitchell449a54f2018-11-30 15:22:31 -0800393 continue;
394 }
395
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800396 package.loaded_package_->CollectConfigurations(exclude_mipmap, &configurations);
Adam Lesinski0c405242017-01-13 20:47:26 -0800397 }
398 }
399 return configurations;
400}
401
402std::set<std::string> AssetManager2::GetResourceLocales(bool exclude_system,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800403 bool merge_equivalent_languages) const {
404 ATRACE_NAME("AssetManager::GetResourceLocales");
Adam Lesinski0c405242017-01-13 20:47:26 -0800405 std::set<std::string> locales;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700406 const auto non_system_overlays =
407 (exclude_system) ? GetNonSystemOverlayPaths() : std::set<std::string>();
408
Adam Lesinski0c405242017-01-13 20:47:26 -0800409 for (const PackageGroup& package_group : package_groups_) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700410 for (size_t i = 0; i < package_group.packages_.size(); i++) {
411 const ConfiguredPackage& package = package_group.packages_[i];
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800412 if (exclude_system && package.loaded_package_->IsSystem()) {
Adam Lesinski0c405242017-01-13 20:47:26 -0800413 continue;
414 }
Ryan Mitchell449a54f2018-11-30 15:22:31 -0800415
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700416 auto apk_assets = apk_assets_[package_group.cookies_[i]];
417 if (exclude_system && apk_assets->IsOverlay()
418 && non_system_overlays.find(apk_assets->GetPath()) == non_system_overlays.end()) {
419 // Exclude overlays that target system resources.
Ryan Mitchell449a54f2018-11-30 15:22:31 -0800420 continue;
421 }
422
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800423 package.loaded_package_->CollectLocales(merge_equivalent_languages, &locales);
Adam Lesinski0c405242017-01-13 20:47:26 -0800424 }
425 }
426 return locales;
427}
428
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800429std::unique_ptr<Asset> AssetManager2::Open(const std::string& filename,
430 Asset::AccessMode mode) const {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700431 const std::string new_path = "assets/" + filename;
432 return OpenNonAsset(new_path, mode);
433}
434
435std::unique_ptr<Asset> AssetManager2::Open(const std::string& filename, ApkAssetsCookie cookie,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800436 Asset::AccessMode mode) const {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700437 const std::string new_path = "assets/" + filename;
438 return OpenNonAsset(new_path, cookie, mode);
439}
440
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800441std::unique_ptr<AssetDir> AssetManager2::OpenDir(const std::string& dirname) const {
442 ATRACE_NAME("AssetManager::OpenDir");
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800443
444 std::string full_path = "assets/" + dirname;
445 std::unique_ptr<SortedVector<AssetDir::FileInfo>> files =
446 util::make_unique<SortedVector<AssetDir::FileInfo>>();
447
448 // Start from the back.
449 for (auto iter = apk_assets_.rbegin(); iter != apk_assets_.rend(); ++iter) {
450 const ApkAssets* apk_assets = *iter;
Mårten Kongstaddbf343b2019-02-21 07:54:18 +0100451 if (apk_assets->IsOverlay()) {
452 continue;
453 }
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800454
455 auto func = [&](const StringPiece& name, FileType type) {
456 AssetDir::FileInfo info;
457 info.setFileName(String8(name.data(), name.size()));
458 info.setFileType(type);
459 info.setSourceName(String8(apk_assets->GetPath().c_str()));
460 files->add(info);
461 };
462
463 if (!apk_assets->ForEachFile(full_path, func)) {
464 return {};
465 }
466 }
467
468 std::unique_ptr<AssetDir> asset_dir = util::make_unique<AssetDir>();
469 asset_dir->setFileList(files.release());
470 return asset_dir;
471}
472
Adam Lesinski7ad11102016-10-28 16:39:15 -0700473// Search in reverse because that's how we used to do it and we need to preserve behaviour.
474// This is unfortunate, because ClassLoaders delegate to the parent first, so the order
475// is inconsistent for split APKs.
476std::unique_ptr<Asset> AssetManager2::OpenNonAsset(const std::string& filename,
477 Asset::AccessMode mode,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800478 ApkAssetsCookie* out_cookie) const {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700479 for (int32_t i = apk_assets_.size() - 1; i >= 0; i--) {
Mårten Kongstaddbf343b2019-02-21 07:54:18 +0100480 // Prevent RRO from modifying assets and other entries accessed by file
481 // path. Explicitly asking for a path in a given package (denoted by a
482 // cookie) is still OK.
483 if (apk_assets_[i]->IsOverlay()) {
484 continue;
485 }
486
Adam Lesinski7ad11102016-10-28 16:39:15 -0700487 std::unique_ptr<Asset> asset = apk_assets_[i]->Open(filename, mode);
488 if (asset) {
489 if (out_cookie != nullptr) {
490 *out_cookie = i;
491 }
492 return asset;
493 }
494 }
495
496 if (out_cookie != nullptr) {
497 *out_cookie = kInvalidCookie;
498 }
499 return {};
500}
501
502std::unique_ptr<Asset> AssetManager2::OpenNonAsset(const std::string& filename,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800503 ApkAssetsCookie cookie,
504 Asset::AccessMode mode) const {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700505 if (cookie < 0 || static_cast<size_t>(cookie) >= apk_assets_.size()) {
506 return {};
507 }
508 return apk_assets_[cookie]->Open(filename, mode);
509}
510
511ApkAssetsCookie AssetManager2::FindEntry(uint32_t resid, uint16_t density_override,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800512 bool /*stop_at_first_match*/,
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800513 bool ignore_configuration,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800514 FindEntryResult* out_entry) const {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700515 if (resource_resolution_logging_enabled_) {
516 // Clear the last logged resource resolution.
517 ResetResourceResolution();
518 last_resolution_.resid = resid;
519 }
520
Adam Lesinski7ad11102016-10-28 16:39:15 -0700521 // Might use this if density_override != 0.
522 ResTable_config density_override_config;
523
524 // Select our configuration or generate a density override configuration.
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800525 const ResTable_config* desired_config = &configuration_;
Adam Lesinski7ad11102016-10-28 16:39:15 -0700526 if (density_override != 0 && density_override != configuration_.density) {
527 density_override_config = configuration_;
528 density_override_config.density = density_override;
529 desired_config = &density_override_config;
530 }
531
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700532 // Retrieve the package group from the package id of the resource id.
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800533 if (!is_valid_resid(resid)) {
Adam Lesinskida431a22016-12-29 16:08:16 -0500534 LOG(ERROR) << base::StringPrintf("Invalid ID 0x%08x.", resid);
535 return kInvalidCookie;
536 }
537
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800538 const uint32_t package_id = get_package_id(resid);
539 const uint8_t type_idx = get_type_id(resid) - 1;
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800540 const uint16_t entry_idx = get_entry_id(resid);
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700541 uint8_t package_idx = package_ids_[package_id];
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800542 if (package_idx == 0xff) {
Ryan Mitchell2fe23472019-02-27 09:43:01 -0800543 ANDROID_LOG(ERROR) << base::StringPrintf("No package ID %02x found for ID 0x%08x.",
544 package_id, resid);
Adam Lesinskida431a22016-12-29 16:08:16 -0500545 return kInvalidCookie;
546 }
547
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800548 const PackageGroup& package_group = package_groups_[package_idx];
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700549 ApkAssetsCookie cookie = FindEntryInternal(package_group, type_idx, entry_idx, *desired_config,
550 false /* stop_at_first_match */,
551 ignore_configuration, out_entry);
552 if (UNLIKELY(cookie == kInvalidCookie)) {
553 return kInvalidCookie;
554 }
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800555
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700556 if (!apk_assets_[cookie]->IsLoader()) {
557 for (const auto& id_map : package_group.overlays_) {
558 auto overlay_entry = id_map.overlay_res_maps_.Lookup(resid);
559 if (!overlay_entry) {
560 // No id map entry exists for this target resource.
561 continue;
562 }
563
564 if (overlay_entry.IsTableEntry()) {
565 // The target resource is overlaid by an inline value not represented by a resource.
566 out_entry->entry = overlay_entry.GetTableEntry();
567 out_entry->dynamic_ref_table = id_map.overlay_res_maps_.GetOverlayDynamicRefTable();
568 cookie = id_map.cookie;
569 continue;
570 }
571
572 FindEntryResult overlay_result;
573 ApkAssetsCookie overlay_cookie = FindEntry(overlay_entry.GetResourceId(), density_override,
574 false /* stop_at_first_match */,
575 ignore_configuration, &overlay_result);
576 if (UNLIKELY(overlay_cookie == kInvalidCookie)) {
577 continue;
578 }
579
580 if (!overlay_result.config.isBetterThan(out_entry->config, desired_config)
581 && overlay_result.config.compare(out_entry->config) != 0) {
582 // The configuration of the entry for the overlay must be equal to or better than the target
583 // configuration to be chosen as the better value.
584 continue;
585 }
586
587 cookie = overlay_cookie;
588 out_entry->entry = std::move(overlay_result.entry);
589 out_entry->config = overlay_result.config;
590 out_entry->dynamic_ref_table = id_map.overlay_res_maps_.GetOverlayDynamicRefTable();
591 if (resource_resolution_logging_enabled_) {
592 last_resolution_.steps.push_back(
593 Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result.config.toString(),
594 &package_group.packages_[0].loaded_package_->GetPackageName()});
595 }
596 }
597 }
598
599 if (resource_resolution_logging_enabled_) {
600 last_resolution_.cookie = cookie;
601 last_resolution_.type_string_ref = out_entry->type_string_ref;
602 last_resolution_.entry_string_ref = out_entry->entry_string_ref;
603 }
604
605 return cookie;
606}
607
608ApkAssetsCookie AssetManager2::FindEntryInternal(const PackageGroup& package_group,
609 uint8_t type_idx, uint16_t entry_idx,
610 const ResTable_config& desired_config,
611 bool /*stop_at_first_match*/,
612 bool ignore_configuration,
613 FindEntryResult* out_entry) const {
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800614 ApkAssetsCookie best_cookie = kInvalidCookie;
615 const LoadedPackage* best_package = nullptr;
616 const ResTable_type* best_type = nullptr;
617 const ResTable_config* best_config = nullptr;
618 ResTable_config best_config_copy;
619 uint32_t best_offset = 0u;
620 uint32_t type_flags = 0u;
621
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700622 Resolution::Step::Type resolution_type = Resolution::Step::Type::NO_ENTRY;
Winson2f3669b2019-01-11 11:28:34 -0800623 std::vector<Resolution::Step> resolution_steps;
624
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800625 // If desired_config is the same as the set configuration, then we can use our filtered list
626 // and we don't need to match the configurations, since they already matched.
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700627 const bool use_fast_path = !ignore_configuration && &desired_config == &configuration_;
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800628
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700629 const size_t package_count = package_group.packages_.size();
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800630 for (size_t pi = 0; pi < package_count; pi++) {
631 const ConfiguredPackage& loaded_package_impl = package_group.packages_[pi];
632 const LoadedPackage* loaded_package = loaded_package_impl.loaded_package_;
633 ApkAssetsCookie cookie = package_group.cookies_[pi];
634
635 // If the type IDs are offset in this package, we need to take that into account when searching
636 // for a type.
637 const TypeSpec* type_spec = loaded_package->GetTypeSpecByTypeIndex(type_idx);
638 if (UNLIKELY(type_spec == nullptr)) {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700639 continue;
640 }
641
Winson9947f1e2019-08-16 10:20:39 -0700642 // If the package is an overlay or custom loader,
643 // then even configurations that are the same MUST be chosen.
Winson9947f1e2019-08-16 10:20:39 -0700644 const bool package_is_loader = loaded_package->IsCustomLoader();
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700645 type_flags |= type_spec->GetFlagsForEntryIndex(entry_idx);
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800646
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800647 if (use_fast_path) {
Winson2f3669b2019-01-11 11:28:34 -0800648 const FilteredConfigGroup& filtered_group = loaded_package_impl.filtered_configs_[type_idx];
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800649 const std::vector<ResTable_config>& candidate_configs = filtered_group.configurations;
650 const size_t type_count = candidate_configs.size();
651 for (uint32_t i = 0; i < type_count; i++) {
652 const ResTable_config& this_config = candidate_configs[i];
653
654 // We can skip calling ResTable_config::match() because we know that all candidate
655 // configurations that do NOT match have been filtered-out.
Winson2f3669b2019-01-11 11:28:34 -0800656 if (best_config == nullptr) {
657 resolution_type = Resolution::Step::Type::INITIAL;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700658 } else if (this_config.isBetterThan(*best_config, &desired_config)) {
659 resolution_type = (package_is_loader) ? Resolution::Step::Type::BETTER_MATCH_LOADER
660 : Resolution::Step::Type::BETTER_MATCH;
661 } else if (package_is_loader && this_config.compare(*best_config) == 0) {
662 resolution_type = Resolution::Step::Type::OVERLAID_LOADER;
Winson2f3669b2019-01-11 11:28:34 -0800663 } else {
Winson9947f1e2019-08-16 10:20:39 -0700664 if (resource_resolution_logging_enabled_) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700665 resolution_type = (package_is_loader) ? Resolution::Step::Type::SKIPPED_LOADER
666 : Resolution::Step::Type::SKIPPED;
Winson9947f1e2019-08-16 10:20:39 -0700667 resolution_steps.push_back(Resolution::Step{resolution_type,
668 this_config.toString(),
669 &loaded_package->GetPackageName()});
670 }
Winson2f3669b2019-01-11 11:28:34 -0800671 continue;
672 }
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800673
Winson2f3669b2019-01-11 11:28:34 -0800674 // The configuration matches and is better than the previous selection.
675 // Find the entry value if it exists for this configuration.
676 const ResTable_type* type = filtered_group.types[i];
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700677 const uint32_t offset = LoadedPackage::GetEntryOffset(type, entry_idx);
Winson2f3669b2019-01-11 11:28:34 -0800678 if (offset == ResTable_type::NO_ENTRY) {
Winson9947f1e2019-08-16 10:20:39 -0700679 if (resource_resolution_logging_enabled_) {
680 if (package_is_loader) {
681 resolution_type = Resolution::Step::Type::NO_ENTRY_LOADER;
682 } else {
683 resolution_type = Resolution::Step::Type::NO_ENTRY;
684 }
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700685 resolution_steps.push_back(Resolution::Step{resolution_type,
Winson9947f1e2019-08-16 10:20:39 -0700686 this_config.toString(),
687 &loaded_package->GetPackageName()});
688 }
Winson2f3669b2019-01-11 11:28:34 -0800689 continue;
690 }
691
692 best_cookie = cookie;
693 best_package = loaded_package;
694 best_type = type;
695 best_config = &this_config;
696 best_offset = offset;
697
698 if (resource_resolution_logging_enabled_) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700699 last_resolution_.steps.push_back(Resolution::Step{resolution_type,
700 this_config.toString(),
701 &loaded_package->GetPackageName()});
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800702 }
703 }
704 } else {
705 // This is the slower path, which doesn't use the filtered list of configurations.
706 // Here we must read the ResTable_config from the mmapped APK, convert it to host endianness
707 // and fill in any new fields that did not exist when the APK was compiled.
708 // Furthermore when selecting configurations we can't just record the pointer to the
709 // ResTable_config, we must copy it.
710 const auto iter_end = type_spec->types + type_spec->type_count;
711 for (auto iter = type_spec->types; iter != iter_end; ++iter) {
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800712 ResTable_config this_config{};
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800713
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800714 if (!ignore_configuration) {
715 this_config.copyFromDtoH((*iter)->config);
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700716 if (!this_config.match(desired_config)) {
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800717 continue;
718 }
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800719
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800720 if (best_config == nullptr) {
721 resolution_type = Resolution::Step::Type::INITIAL;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700722 } else if (this_config.isBetterThan(*best_config, &desired_config)) {
723 resolution_type = (package_is_loader) ? Resolution::Step::Type::BETTER_MATCH_LOADER
724 : Resolution::Step::Type::BETTER_MATCH;
725 } else if (package_is_loader && this_config.compare(*best_config) == 0) {
726 resolution_type = Resolution::Step::Type::OVERLAID_LOADER;
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800727 } else {
728 continue;
729 }
Winson2f3669b2019-01-11 11:28:34 -0800730 }
731
732 // The configuration matches and is better than the previous selection.
733 // Find the entry value if it exists for this configuration.
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700734 const uint32_t offset = LoadedPackage::GetEntryOffset(*iter, entry_idx);
Winson2f3669b2019-01-11 11:28:34 -0800735 if (offset == ResTable_type::NO_ENTRY) {
736 continue;
737 }
738
739 best_cookie = cookie;
740 best_package = loaded_package;
741 best_type = *iter;
742 best_config_copy = this_config;
743 best_config = &best_config_copy;
744 best_offset = offset;
745
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800746 if (ignore_configuration) {
747 // Any configuration will suffice, so break.
748 break;
749 }
750
Winson2f3669b2019-01-11 11:28:34 -0800751 if (resource_resolution_logging_enabled_) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700752 last_resolution_.steps.push_back(Resolution::Step{resolution_type,
753 this_config.toString(),
754 &loaded_package->GetPackageName()});
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800755 }
Adam Lesinski7ad11102016-10-28 16:39:15 -0700756 }
757 }
758 }
759
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800760 if (UNLIKELY(best_cookie == kInvalidCookie)) {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700761 return kInvalidCookie;
762 }
763
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800764 const ResTable_entry* best_entry = LoadedPackage::GetEntryFromOffset(best_type, best_offset);
765 if (UNLIKELY(best_entry == nullptr)) {
766 return kInvalidCookie;
767 }
768
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700769 out_entry->entry = ResTable_entry_handle::unmanaged(best_entry);
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800770 out_entry->config = *best_config;
771 out_entry->type_flags = type_flags;
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700772 out_entry->package_name = &best_package->GetPackageName();
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800773 out_entry->type_string_ref = StringPoolRef(best_package->GetTypeStringPool(), best_type->id - 1);
774 out_entry->entry_string_ref =
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700775 StringPoolRef(best_package->GetKeyStringPool(), best_entry->key.index);
776 out_entry->dynamic_ref_table = package_group.dynamic_ref_table.get();
Winson2f3669b2019-01-11 11:28:34 -0800777
Adam Lesinskida431a22016-12-29 16:08:16 -0500778 return best_cookie;
Adam Lesinski7ad11102016-10-28 16:39:15 -0700779}
780
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700781void AssetManager2::ResetResourceResolution() const {
782 last_resolution_.cookie = kInvalidCookie;
783 last_resolution_.resid = 0;
784 last_resolution_.steps.clear();
785 last_resolution_.type_string_ref = StringPoolRef();
786 last_resolution_.entry_string_ref = StringPoolRef();
787}
788
Winson2f3669b2019-01-11 11:28:34 -0800789void AssetManager2::SetResourceResolutionLoggingEnabled(bool enabled) {
790 resource_resolution_logging_enabled_ = enabled;
Winson2f3669b2019-01-11 11:28:34 -0800791 if (!enabled) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700792 ResetResourceResolution();
Winson2f3669b2019-01-11 11:28:34 -0800793 }
794}
795
796std::string AssetManager2::GetLastResourceResolution() const {
797 if (!resource_resolution_logging_enabled_) {
798 LOG(ERROR) << "Must enable resource resolution logging before getting path.";
799 return std::string();
800 }
801
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700802 auto cookie = last_resolution_.cookie;
Winson2f3669b2019-01-11 11:28:34 -0800803 if (cookie == kInvalidCookie) {
804 LOG(ERROR) << "AssetManager hasn't resolved a resource to read resolution path.";
805 return std::string();
806 }
807
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700808 uint32_t resid = last_resolution_.resid;
809 std::vector<Resolution::Step>& steps = last_resolution_.steps;
Winson2f3669b2019-01-11 11:28:34 -0800810
811 ResourceName resource_name;
812 std::string resource_name_string;
813
814 const LoadedPackage* package =
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700815 apk_assets_[cookie]->GetLoadedArsc()->GetPackageById(get_package_id(resid));
Winson2f3669b2019-01-11 11:28:34 -0800816
817 if (package != nullptr) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700818 ToResourceName(last_resolution_.type_string_ref,
819 last_resolution_.entry_string_ref,
Ryan Mitchell741e96f2019-01-23 16:56:51 -0800820 package->GetPackageName(),
Winson2f3669b2019-01-11 11:28:34 -0800821 &resource_name);
822 resource_name_string = ToFormattedResourceString(&resource_name);
823 }
824
825 std::stringstream log_stream;
826 log_stream << base::StringPrintf("Resolution for 0x%08x ", resid)
827 << resource_name_string
828 << "\n\tFor config -"
829 << configuration_.toString();
830
831 std::string prefix;
832 for (Resolution::Step step : steps) {
833 switch (step.type) {
834 case Resolution::Step::Type::INITIAL:
835 prefix = "Found initial";
836 break;
837 case Resolution::Step::Type::BETTER_MATCH:
838 prefix = "Found better";
839 break;
Winson9947f1e2019-08-16 10:20:39 -0700840 case Resolution::Step::Type::BETTER_MATCH_LOADER:
841 prefix = "Found better in loader";
842 break;
Winson2f3669b2019-01-11 11:28:34 -0800843 case Resolution::Step::Type::OVERLAID:
844 prefix = "Overlaid";
845 break;
Winson9947f1e2019-08-16 10:20:39 -0700846 case Resolution::Step::Type::OVERLAID_LOADER:
847 prefix = "Overlaid by loader";
848 break;
849 case Resolution::Step::Type::SKIPPED:
850 prefix = "Skipped";
851 break;
852 case Resolution::Step::Type::SKIPPED_LOADER:
853 prefix = "Skipped loader";
854 break;
855 case Resolution::Step::Type::NO_ENTRY:
856 prefix = "No entry";
857 break;
858 case Resolution::Step::Type::NO_ENTRY_LOADER:
859 prefix = "No entry for loader";
860 break;
Winson2f3669b2019-01-11 11:28:34 -0800861 }
862
863 if (!prefix.empty()) {
864 log_stream << "\n\t" << prefix << ": " << *step.package_name;
865
866 if (!step.config_name.isEmpty()) {
867 log_stream << " -" << step.config_name;
868 }
869 }
870 }
871
872 return log_stream.str();
873}
874
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800875bool AssetManager2::GetResourceName(uint32_t resid, ResourceName* out_name) const {
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700876 FindEntryResult entry;
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800877 ApkAssetsCookie cookie = FindEntry(resid, 0u /* density_override */,
878 true /* stop_at_first_match */,
879 true /* ignore_configuration */, &entry);
Adam Lesinski7ad11102016-10-28 16:39:15 -0700880 if (cookie == kInvalidCookie) {
881 return false;
882 }
883
Winson2f3669b2019-01-11 11:28:34 -0800884 return ToResourceName(entry.type_string_ref,
885 entry.entry_string_ref,
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700886 *entry.package_name,
Winson2f3669b2019-01-11 11:28:34 -0800887 out_name);
Adam Lesinski7ad11102016-10-28 16:39:15 -0700888}
889
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800890bool AssetManager2::GetResourceFlags(uint32_t resid, uint32_t* out_flags) const {
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700891 FindEntryResult entry;
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800892 ApkAssetsCookie cookie = FindEntry(resid, 0u /* density_override */,
893 false /* stop_at_first_match */,
894 true /* ignore_configuration */, &entry);
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700895 if (cookie != kInvalidCookie) {
896 *out_flags = entry.type_flags;
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800897 return true;
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700898 }
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800899 return false;
Adam Lesinski7ad11102016-10-28 16:39:15 -0700900}
901
902ApkAssetsCookie AssetManager2::GetResource(uint32_t resid, bool may_be_bag,
903 uint16_t density_override, Res_value* out_value,
904 ResTable_config* out_selected_config,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800905 uint32_t* out_flags) const {
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700906 FindEntryResult entry;
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800907 ApkAssetsCookie cookie = FindEntry(resid, density_override, false /* stop_at_first_match */,
908 false /* ignore_configuration */, &entry);
Adam Lesinski7ad11102016-10-28 16:39:15 -0700909 if (cookie == kInvalidCookie) {
910 return kInvalidCookie;
911 }
912
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700913 const ResTable_entry* table_entry = *entry.entry;
914 if (dtohs(table_entry->flags) & ResTable_entry::FLAG_COMPLEX) {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700915 if (!may_be_bag) {
916 LOG(ERROR) << base::StringPrintf("Resource %08x is a complex map type.", resid);
Adam Lesinski0c405242017-01-13 20:47:26 -0800917 return kInvalidCookie;
Adam Lesinski7ad11102016-10-28 16:39:15 -0700918 }
Adam Lesinski0c405242017-01-13 20:47:26 -0800919
920 // Create a reference since we can't represent this complex type as a Res_value.
921 out_value->dataType = Res_value::TYPE_REFERENCE;
922 out_value->data = resid;
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800923 *out_selected_config = entry.config;
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700924 *out_flags = entry.type_flags;
Adam Lesinski0c405242017-01-13 20:47:26 -0800925 return cookie;
Adam Lesinski7ad11102016-10-28 16:39:15 -0700926 }
927
928 const Res_value* device_value = reinterpret_cast<const Res_value*>(
Ryan Mitchell8a891d82019-07-01 09:48:23 -0700929 reinterpret_cast<const uint8_t*>(table_entry) + dtohs(table_entry->size));
Adam Lesinski7ad11102016-10-28 16:39:15 -0700930 out_value->copyFrom_dtoh(*device_value);
Adam Lesinskida431a22016-12-29 16:08:16 -0500931
932 // Convert the package ID to the runtime assigned package ID.
933 entry.dynamic_ref_table->lookupResourceValue(out_value);
934
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800935 *out_selected_config = entry.config;
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700936 *out_flags = entry.type_flags;
Adam Lesinski7ad11102016-10-28 16:39:15 -0700937 return cookie;
938}
939
Adam Lesinski0c405242017-01-13 20:47:26 -0800940ApkAssetsCookie AssetManager2::ResolveReference(ApkAssetsCookie cookie, Res_value* in_out_value,
941 ResTable_config* in_out_selected_config,
942 uint32_t* in_out_flags,
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800943 uint32_t* out_last_reference) const {
Adam Lesinski0c405242017-01-13 20:47:26 -0800944 constexpr const int kMaxIterations = 20;
945
Adam Lesinski0c405242017-01-13 20:47:26 -0800946 for (size_t iteration = 0u; in_out_value->dataType == Res_value::TYPE_REFERENCE &&
947 in_out_value->data != 0u && iteration < kMaxIterations;
948 iteration++) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -0800949 *out_last_reference = in_out_value->data;
Adam Lesinski0c405242017-01-13 20:47:26 -0800950 uint32_t new_flags = 0u;
951 cookie = GetResource(in_out_value->data, true /*may_be_bag*/, 0u /*density_override*/,
952 in_out_value, in_out_selected_config, &new_flags);
953 if (cookie == kInvalidCookie) {
954 return kInvalidCookie;
955 }
956 if (in_out_flags != nullptr) {
957 *in_out_flags |= new_flags;
958 }
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -0800959 if (*out_last_reference == in_out_value->data) {
Adam Lesinski0c405242017-01-13 20:47:26 -0800960 // This reference can't be resolved, so exit now and let the caller deal with it.
961 return cookie;
962 }
963 }
964 return cookie;
965}
966
Aurimas Liutikas8f004c82019-01-17 17:20:10 -0800967const std::vector<uint32_t> AssetManager2::GetBagResIdStack(uint32_t resid) {
968 auto cached_iter = cached_bag_resid_stacks_.find(resid);
969 if (cached_iter != cached_bag_resid_stacks_.end()) {
970 return cached_iter->second;
971 } else {
972 auto found_resids = std::vector<uint32_t>();
973 GetBag(resid, found_resids);
974 // Cache style stacks if they are not already cached.
975 cached_bag_resid_stacks_[resid] = found_resids;
976 return found_resids;
977 }
978}
979
Adam Lesinski7ad11102016-10-28 16:39:15 -0700980const ResolvedBag* AssetManager2::GetBag(uint32_t resid) {
y57cd1952018-04-12 14:26:23 -0700981 auto found_resids = std::vector<uint32_t>();
Aurimas Liutikas8f004c82019-01-17 17:20:10 -0800982 auto bag = GetBag(resid, found_resids);
983
984 // Cache style stacks if they are not already cached.
985 auto cached_iter = cached_bag_resid_stacks_.find(resid);
986 if (cached_iter == cached_bag_resid_stacks_.end()) {
987 cached_bag_resid_stacks_[resid] = found_resids;
988 }
989 return bag;
y57cd1952018-04-12 14:26:23 -0700990}
991
992const ResolvedBag* AssetManager2::GetBag(uint32_t resid, std::vector<uint32_t>& child_resids) {
Adam Lesinski7ad11102016-10-28 16:39:15 -0700993 auto cached_iter = cached_bags_.find(resid);
994 if (cached_iter != cached_bags_.end()) {
995 return cached_iter->second.get();
996 }
997
Adam Lesinski1a1e9c22017-10-13 15:45:34 -0700998 FindEntryResult entry;
Ryan Mitchella55dc2e2019-01-24 10:58:23 -0800999 ApkAssetsCookie cookie = FindEntry(resid, 0u /* density_override */,
1000 false /* stop_at_first_match */,
1001 false /* ignore_configuration */,
1002 &entry);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001003 if (cookie == kInvalidCookie) {
1004 return nullptr;
1005 }
1006
1007 // Check that the size of the entry header is at least as big as
1008 // the desired ResTable_map_entry. Also verify that the entry
1009 // was intended to be a map.
Ryan Mitchell8a891d82019-07-01 09:48:23 -07001010 const ResTable_entry* table_entry = *entry.entry;
1011 if (dtohs(table_entry->size) < sizeof(ResTable_map_entry) ||
1012 (dtohs(table_entry->flags) & ResTable_entry::FLAG_COMPLEX) == 0) {
Adam Lesinski7ad11102016-10-28 16:39:15 -07001013 // Not a bag, nothing to do.
1014 return nullptr;
1015 }
1016
Ryan Mitchell8a891d82019-07-01 09:48:23 -07001017 const ResTable_map_entry* map = reinterpret_cast<const ResTable_map_entry*>(table_entry);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001018 const ResTable_map* map_entry =
1019 reinterpret_cast<const ResTable_map*>(reinterpret_cast<const uint8_t*>(map) + map->size);
1020 const ResTable_map* const map_entry_end = map_entry + dtohl(map->count);
1021
y57cd1952018-04-12 14:26:23 -07001022 // Keep track of ids that have already been seen to prevent infinite loops caused by circular
1023 // dependencies between bags
1024 child_resids.push_back(resid);
1025
Adam Lesinskida431a22016-12-29 16:08:16 -05001026 uint32_t parent_resid = dtohl(map->parent.ident);
y57cd1952018-04-12 14:26:23 -07001027 if (parent_resid == 0 || std::find(child_resids.begin(), child_resids.end(), parent_resid)
1028 != child_resids.end()) {
1029 // There is no parent or that a circular dependency exist, meaning there is nothing to
1030 // inherit and we can do a simple copy of the entries in the map.
Adam Lesinski7ad11102016-10-28 16:39:15 -07001031 const size_t entry_count = map_entry_end - map_entry;
1032 util::unique_cptr<ResolvedBag> new_bag{reinterpret_cast<ResolvedBag*>(
1033 malloc(sizeof(ResolvedBag) + (entry_count * sizeof(ResolvedBag::Entry))))};
1034 ResolvedBag::Entry* new_entry = new_bag->entries;
1035 for (; map_entry != map_entry_end; ++map_entry) {
Adam Lesinskida431a22016-12-29 16:08:16 -05001036 uint32_t new_key = dtohl(map_entry->name.ident);
Adam Lesinski929d6512017-01-16 19:11:19 -08001037 if (!is_internal_resid(new_key)) {
Adam Lesinskida431a22016-12-29 16:08:16 -05001038 // Attributes, arrays, etc don't have a resource id as the name. They specify
1039 // other data, which would be wrong to change via a lookup.
1040 if (entry.dynamic_ref_table->lookupResourceId(&new_key) != NO_ERROR) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001041 LOG(ERROR) << base::StringPrintf("Failed to resolve key 0x%08x in bag 0x%08x.", new_key,
1042 resid);
Adam Lesinskida431a22016-12-29 16:08:16 -05001043 return nullptr;
1044 }
1045 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001046 new_entry->cookie = cookie;
Adam Lesinskida431a22016-12-29 16:08:16 -05001047 new_entry->key = new_key;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001048 new_entry->key_pool = nullptr;
1049 new_entry->type_pool = nullptr;
Aurimas Liutikasd42a6702018-11-15 15:48:28 -08001050 new_entry->style = resid;
Adam Lesinski30080e22017-10-16 16:18:09 -07001051 new_entry->value.copyFrom_dtoh(map_entry->value);
1052 status_t err = entry.dynamic_ref_table->lookupResourceValue(&new_entry->value);
1053 if (err != NO_ERROR) {
1054 LOG(ERROR) << base::StringPrintf(
1055 "Failed to resolve value t=0x%02x d=0x%08x for key 0x%08x.", new_entry->value.dataType,
1056 new_entry->value.data, new_key);
1057 return nullptr;
1058 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001059 ++new_entry;
1060 }
Adam Lesinski1a1e9c22017-10-13 15:45:34 -07001061 new_bag->type_spec_flags = entry.type_flags;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001062 new_bag->entry_count = static_cast<uint32_t>(entry_count);
1063 ResolvedBag* result = new_bag.get();
1064 cached_bags_[resid] = std::move(new_bag);
1065 return result;
1066 }
1067
Adam Lesinskida431a22016-12-29 16:08:16 -05001068 // In case the parent is a dynamic reference, resolve it.
1069 entry.dynamic_ref_table->lookupResourceId(&parent_resid);
1070
Adam Lesinski7ad11102016-10-28 16:39:15 -07001071 // Get the parent and do a merge of the keys.
y57cd1952018-04-12 14:26:23 -07001072 const ResolvedBag* parent_bag = GetBag(parent_resid, child_resids);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001073 if (parent_bag == nullptr) {
1074 // Failed to get the parent that should exist.
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001075 LOG(ERROR) << base::StringPrintf("Failed to find parent 0x%08x of bag 0x%08x.", parent_resid,
1076 resid);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001077 return nullptr;
1078 }
1079
Adam Lesinski7ad11102016-10-28 16:39:15 -07001080 // Create the max possible entries we can make. Once we construct the bag,
1081 // we will realloc to fit to size.
1082 const size_t max_count = parent_bag->entry_count + dtohl(map->count);
George Burgess IV09b119f2017-07-25 15:00:04 -07001083 util::unique_cptr<ResolvedBag> new_bag{reinterpret_cast<ResolvedBag*>(
1084 malloc(sizeof(ResolvedBag) + (max_count * sizeof(ResolvedBag::Entry))))};
Adam Lesinski7ad11102016-10-28 16:39:15 -07001085 ResolvedBag::Entry* new_entry = new_bag->entries;
1086
1087 const ResolvedBag::Entry* parent_entry = parent_bag->entries;
1088 const ResolvedBag::Entry* const parent_entry_end = parent_entry + parent_bag->entry_count;
1089
1090 // The keys are expected to be in sorted order. Merge the two bags.
1091 while (map_entry != map_entry_end && parent_entry != parent_entry_end) {
Adam Lesinskida431a22016-12-29 16:08:16 -05001092 uint32_t child_key = dtohl(map_entry->name.ident);
Adam Lesinski929d6512017-01-16 19:11:19 -08001093 if (!is_internal_resid(child_key)) {
Adam Lesinskida431a22016-12-29 16:08:16 -05001094 if (entry.dynamic_ref_table->lookupResourceId(&child_key) != NO_ERROR) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001095 LOG(ERROR) << base::StringPrintf("Failed to resolve key 0x%08x in bag 0x%08x.", child_key,
1096 resid);
Adam Lesinskida431a22016-12-29 16:08:16 -05001097 return nullptr;
1098 }
1099 }
1100
Adam Lesinski7ad11102016-10-28 16:39:15 -07001101 if (child_key <= parent_entry->key) {
1102 // Use the child key if it comes before the parent
1103 // or is equal to the parent (overrides).
1104 new_entry->cookie = cookie;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001105 new_entry->key = child_key;
1106 new_entry->key_pool = nullptr;
1107 new_entry->type_pool = nullptr;
Adam Lesinski30080e22017-10-16 16:18:09 -07001108 new_entry->value.copyFrom_dtoh(map_entry->value);
Aurimas Liutikasd42a6702018-11-15 15:48:28 -08001109 new_entry->style = resid;
Adam Lesinski30080e22017-10-16 16:18:09 -07001110 status_t err = entry.dynamic_ref_table->lookupResourceValue(&new_entry->value);
1111 if (err != NO_ERROR) {
1112 LOG(ERROR) << base::StringPrintf(
1113 "Failed to resolve value t=0x%02x d=0x%08x for key 0x%08x.", new_entry->value.dataType,
1114 new_entry->value.data, child_key);
1115 return nullptr;
1116 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001117 ++map_entry;
1118 } else {
1119 // Take the parent entry as-is.
1120 memcpy(new_entry, parent_entry, sizeof(*new_entry));
1121 }
1122
1123 if (child_key >= parent_entry->key) {
1124 // Move to the next parent entry if we used it or it was overridden.
1125 ++parent_entry;
1126 }
1127 // Increment to the next entry to fill.
1128 ++new_entry;
1129 }
1130
1131 // Finish the child entries if they exist.
1132 while (map_entry != map_entry_end) {
Adam Lesinskida431a22016-12-29 16:08:16 -05001133 uint32_t new_key = dtohl(map_entry->name.ident);
Adam Lesinski929d6512017-01-16 19:11:19 -08001134 if (!is_internal_resid(new_key)) {
Adam Lesinskida431a22016-12-29 16:08:16 -05001135 if (entry.dynamic_ref_table->lookupResourceId(&new_key) != NO_ERROR) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001136 LOG(ERROR) << base::StringPrintf("Failed to resolve key 0x%08x in bag 0x%08x.", new_key,
1137 resid);
Adam Lesinskida431a22016-12-29 16:08:16 -05001138 return nullptr;
1139 }
1140 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001141 new_entry->cookie = cookie;
Adam Lesinskida431a22016-12-29 16:08:16 -05001142 new_entry->key = new_key;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001143 new_entry->key_pool = nullptr;
1144 new_entry->type_pool = nullptr;
Adam Lesinski30080e22017-10-16 16:18:09 -07001145 new_entry->value.copyFrom_dtoh(map_entry->value);
Aurimas Liutikasd42a6702018-11-15 15:48:28 -08001146 new_entry->style = resid;
Adam Lesinski30080e22017-10-16 16:18:09 -07001147 status_t err = entry.dynamic_ref_table->lookupResourceValue(&new_entry->value);
1148 if (err != NO_ERROR) {
1149 LOG(ERROR) << base::StringPrintf("Failed to resolve value t=0x%02x d=0x%08x for key 0x%08x.",
1150 new_entry->value.dataType, new_entry->value.data, new_key);
1151 return nullptr;
1152 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001153 ++map_entry;
1154 ++new_entry;
1155 }
1156
1157 // Finish the parent entries if they exist.
1158 if (parent_entry != parent_entry_end) {
1159 // Take the rest of the parent entries as-is.
1160 const size_t num_entries_to_copy = parent_entry_end - parent_entry;
1161 memcpy(new_entry, parent_entry, num_entries_to_copy * sizeof(*new_entry));
1162 new_entry += num_entries_to_copy;
1163 }
1164
1165 // Resize the resulting array to fit.
1166 const size_t actual_count = new_entry - new_bag->entries;
1167 if (actual_count != max_count) {
George Burgess IV09b119f2017-07-25 15:00:04 -07001168 new_bag.reset(reinterpret_cast<ResolvedBag*>(realloc(
1169 new_bag.release(), sizeof(ResolvedBag) + (actual_count * sizeof(ResolvedBag::Entry)))));
Adam Lesinski7ad11102016-10-28 16:39:15 -07001170 }
1171
Adam Lesinski1a1e9c22017-10-13 15:45:34 -07001172 // Combine flags from the parent and our own bag.
1173 new_bag->type_spec_flags = entry.type_flags | parent_bag->type_spec_flags;
George Burgess IV09b119f2017-07-25 15:00:04 -07001174 new_bag->entry_count = static_cast<uint32_t>(actual_count);
1175 ResolvedBag* result = new_bag.get();
1176 cached_bags_[resid] = std::move(new_bag);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001177 return result;
1178}
1179
Adam Lesinski929d6512017-01-16 19:11:19 -08001180static bool Utf8ToUtf16(const StringPiece& str, std::u16string* out) {
1181 ssize_t len =
1182 utf8_to_utf16_length(reinterpret_cast<const uint8_t*>(str.data()), str.size(), false);
1183 if (len < 0) {
1184 return false;
1185 }
1186 out->resize(static_cast<size_t>(len));
1187 utf8_to_utf16(reinterpret_cast<const uint8_t*>(str.data()), str.size(), &*out->begin(),
1188 static_cast<size_t>(len + 1));
1189 return true;
1190}
1191
Adam Lesinski0c405242017-01-13 20:47:26 -08001192uint32_t AssetManager2::GetResourceId(const std::string& resource_name,
1193 const std::string& fallback_type,
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001194 const std::string& fallback_package) const {
Adam Lesinski929d6512017-01-16 19:11:19 -08001195 StringPiece package_name, type, entry;
1196 if (!ExtractResourceName(resource_name, &package_name, &type, &entry)) {
1197 return 0u;
1198 }
1199
1200 if (entry.empty()) {
1201 return 0u;
1202 }
1203
1204 if (package_name.empty()) {
1205 package_name = fallback_package;
1206 }
1207
1208 if (type.empty()) {
1209 type = fallback_type;
1210 }
1211
1212 std::u16string type16;
1213 if (!Utf8ToUtf16(type, &type16)) {
1214 return 0u;
1215 }
1216
1217 std::u16string entry16;
1218 if (!Utf8ToUtf16(entry, &entry16)) {
1219 return 0u;
1220 }
1221
1222 const StringPiece16 kAttr16 = u"attr";
1223 const static std::u16string kAttrPrivate16 = u"^attr-private";
1224
1225 for (const PackageGroup& package_group : package_groups_) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001226 for (const ConfiguredPackage& package_impl : package_group.packages_) {
1227 const LoadedPackage* package = package_impl.loaded_package_;
Adam Lesinski929d6512017-01-16 19:11:19 -08001228 if (package_name != package->GetPackageName()) {
1229 // All packages in the same group are expected to have the same package name.
1230 break;
1231 }
1232
1233 uint32_t resid = package->FindEntryByName(type16, entry16);
1234 if (resid == 0u && kAttr16 == type16) {
1235 // Private attributes in libraries (such as the framework) are sometimes encoded
1236 // under the type '^attr-private' in order to leave the ID space of public 'attr'
1237 // free for future additions. Check '^attr-private' for the same name.
1238 resid = package->FindEntryByName(kAttrPrivate16, entry16);
1239 }
1240
1241 if (resid != 0u) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -07001242 return fix_package_id(resid, package_group.dynamic_ref_table->mAssignedPackageId);
Adam Lesinski929d6512017-01-16 19:11:19 -08001243 }
1244 }
1245 }
Adam Lesinski0c405242017-01-13 20:47:26 -08001246 return 0u;
1247}
1248
Mårten Kongstad668ec5b2018-06-11 14:11:33 +02001249void AssetManager2::RebuildFilterList(bool filter_incompatible_configs) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001250 for (PackageGroup& group : package_groups_) {
1251 for (ConfiguredPackage& impl : group.packages_) {
1252 // Destroy it.
1253 impl.filtered_configs_.~ByteBucketArray();
1254
1255 // Re-create it.
1256 new (&impl.filtered_configs_) ByteBucketArray<FilteredConfigGroup>();
1257
1258 // Create the filters here.
1259 impl.loaded_package_->ForEachTypeSpec([&](const TypeSpec* spec, uint8_t type_index) {
1260 FilteredConfigGroup& group = impl.filtered_configs_.editItemAt(type_index);
1261 const auto iter_end = spec->types + spec->type_count;
1262 for (auto iter = spec->types; iter != iter_end; ++iter) {
1263 ResTable_config this_config;
1264 this_config.copyFromDtoH((*iter)->config);
Mårten Kongstad668ec5b2018-06-11 14:11:33 +02001265 if (!filter_incompatible_configs || this_config.match(configuration_)) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001266 group.configurations.push_back(this_config);
1267 group.types.push_back(*iter);
1268 }
1269 }
1270 });
1271 }
1272 }
1273}
1274
Adam Lesinski7ad11102016-10-28 16:39:15 -07001275void AssetManager2::InvalidateCaches(uint32_t diff) {
Ryan Mitchell2c4d8742019-03-04 09:41:00 -08001276 cached_bag_resid_stacks_.clear();
1277
Adam Lesinski7ad11102016-10-28 16:39:15 -07001278 if (diff == 0xffffffffu) {
1279 // Everything must go.
1280 cached_bags_.clear();
1281 return;
1282 }
1283
1284 // Be more conservative with what gets purged. Only if the bag has other possible
1285 // variations with respect to what changed (diff) should we remove it.
1286 for (auto iter = cached_bags_.cbegin(); iter != cached_bags_.cend();) {
1287 if (diff & iter->second->type_spec_flags) {
1288 iter = cached_bags_.erase(iter);
1289 } else {
1290 ++iter;
1291 }
1292 }
1293}
1294
Ryan Mitchell2e394222019-08-28 12:10:51 -07001295uint8_t AssetManager2::GetAssignedPackageId(const LoadedPackage* package) const {
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001296 for (auto& package_group : package_groups_) {
1297 for (auto& package2 : package_group.packages_) {
1298 if (package2.loaded_package_ == package) {
Ryan Mitchell8a891d82019-07-01 09:48:23 -07001299 return package_group.dynamic_ref_table->mAssignedPackageId;
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001300 }
1301 }
1302 }
1303 return 0;
1304}
1305
Ryan Mitchellfe50d732019-12-19 16:12:35 -08001306DynamicLibManager* AssetManager2::GetDynamicLibManager() const {
1307 auto dynamic_lib_manager =
1308 std::get_if<std::unique_ptr<DynamicLibManager>>(&dynamic_lib_manager_);
1309 if (dynamic_lib_manager) {
1310 return (*dynamic_lib_manager).get();
1311 } else {
1312 return *std::get_if<DynamicLibManager*>(&dynamic_lib_manager_);
1313 }
1314}
1315
Adam Lesinski30080e22017-10-16 16:18:09 -07001316std::unique_ptr<Theme> AssetManager2::NewTheme() {
1317 return std::unique_ptr<Theme>(new Theme(this));
1318}
1319
1320Theme::Theme(AssetManager2* asset_manager) : asset_manager_(asset_manager) {
1321}
1322
1323Theme::~Theme() = default;
1324
1325namespace {
1326
1327struct ThemeEntry {
1328 ApkAssetsCookie cookie;
1329 uint32_t type_spec_flags;
1330 Res_value value;
1331};
1332
1333struct ThemeType {
1334 int entry_count;
1335 ThemeEntry entries[0];
1336};
1337
1338constexpr size_t kTypeCount = std::numeric_limits<uint8_t>::max() + 1;
1339
1340} // namespace
1341
1342struct Theme::Package {
1343 // Each element of Type will be a dynamically sized object
1344 // allocated to have the entries stored contiguously with the Type.
1345 std::array<util::unique_cptr<ThemeType>, kTypeCount> types;
1346};
Adam Lesinski7ad11102016-10-28 16:39:15 -07001347
1348bool Theme::ApplyStyle(uint32_t resid, bool force) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001349 ATRACE_NAME("Theme::ApplyStyle");
Adam Lesinski7ad11102016-10-28 16:39:15 -07001350
1351 const ResolvedBag* bag = asset_manager_->GetBag(resid);
1352 if (bag == nullptr) {
1353 return false;
1354 }
1355
1356 // Merge the flags from this style.
1357 type_spec_flags_ |= bag->type_spec_flags;
1358
Adam Lesinski30080e22017-10-16 16:18:09 -07001359 int last_type_idx = -1;
1360 int last_package_idx = -1;
1361 Package* last_package = nullptr;
1362 ThemeType* last_type = nullptr;
1363
1364 // Iterate backwards, because each bag is sorted in ascending key ID order, meaning we will only
1365 // need to perform one resize per type.
1366 using reverse_bag_iterator = std::reverse_iterator<const ResolvedBag::Entry*>;
1367 const auto bag_iter_end = reverse_bag_iterator(begin(bag));
1368 for (auto bag_iter = reverse_bag_iterator(end(bag)); bag_iter != bag_iter_end; ++bag_iter) {
Adam Lesinski7ad11102016-10-28 16:39:15 -07001369 const uint32_t attr_resid = bag_iter->key;
1370
Adam Lesinski30080e22017-10-16 16:18:09 -07001371 // If the resource ID passed in is not a style, the key can be some other identifier that is not
1372 // a resource ID. We should fail fast instead of operating with strange resource IDs.
Adam Lesinski929d6512017-01-16 19:11:19 -08001373 if (!is_valid_resid(attr_resid)) {
Adam Lesinski7ad11102016-10-28 16:39:15 -07001374 return false;
1375 }
1376
Adam Lesinski30080e22017-10-16 16:18:09 -07001377 // We don't use the 0-based index for the type so that we can avoid doing ID validation
1378 // upon lookup. Instead, we keep space for the type ID 0 in our data structures. Since
1379 // the construction of this type is guarded with a resource ID check, it will never be
1380 // populated, and querying type ID 0 will always fail.
1381 const int package_idx = get_package_id(attr_resid);
1382 const int type_idx = get_type_id(attr_resid);
1383 const int entry_idx = get_entry_id(attr_resid);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001384
Adam Lesinski30080e22017-10-16 16:18:09 -07001385 if (last_package_idx != package_idx) {
1386 std::unique_ptr<Package>& package = packages_[package_idx];
1387 if (package == nullptr) {
1388 package.reset(new Package());
Adam Lesinski7ad11102016-10-28 16:39:15 -07001389 }
Adam Lesinski30080e22017-10-16 16:18:09 -07001390 last_package_idx = package_idx;
1391 last_package = package.get();
1392 last_type_idx = -1;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001393 }
Adam Lesinski30080e22017-10-16 16:18:09 -07001394
1395 if (last_type_idx != type_idx) {
1396 util::unique_cptr<ThemeType>& type = last_package->types[type_idx];
1397 if (type == nullptr) {
1398 // Allocate enough memory to contain this entry_idx. Since we're iterating in reverse over
1399 // a sorted list of attributes, this shouldn't be resized again during this method call.
1400 type.reset(reinterpret_cast<ThemeType*>(
1401 calloc(sizeof(ThemeType) + (entry_idx + 1) * sizeof(ThemeEntry), 1)));
1402 type->entry_count = entry_idx + 1;
1403 } else if (entry_idx >= type->entry_count) {
1404 // Reallocate the memory to contain this entry_idx. Since we're iterating in reverse over
1405 // a sorted list of attributes, this shouldn't be resized again during this method call.
1406 const int new_count = entry_idx + 1;
1407 type.reset(reinterpret_cast<ThemeType*>(
1408 realloc(type.release(), sizeof(ThemeType) + (new_count * sizeof(ThemeEntry)))));
1409
1410 // Clear out the newly allocated space (which isn't zeroed).
1411 memset(type->entries + type->entry_count, 0,
1412 (new_count - type->entry_count) * sizeof(ThemeEntry));
1413 type->entry_count = new_count;
1414 }
1415 last_type_idx = type_idx;
1416 last_type = type.get();
1417 }
1418
1419 ThemeEntry& entry = last_type->entries[entry_idx];
1420 if (force || (entry.value.dataType == Res_value::TYPE_NULL &&
1421 entry.value.data != Res_value::DATA_NULL_EMPTY)) {
Adam Lesinski7ad11102016-10-28 16:39:15 -07001422 entry.cookie = bag_iter->cookie;
1423 entry.type_spec_flags |= bag->type_spec_flags;
1424 entry.value = bag_iter->value;
1425 }
1426 }
1427 return true;
1428}
1429
1430ApkAssetsCookie Theme::GetAttribute(uint32_t resid, Res_value* out_value,
1431 uint32_t* out_flags) const {
Adam Lesinski30080e22017-10-16 16:18:09 -07001432 int cnt = 20;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001433
1434 uint32_t type_spec_flags = 0u;
1435
Adam Lesinski30080e22017-10-16 16:18:09 -07001436 do {
1437 const int package_idx = get_package_id(resid);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001438 const Package* package = packages_[package_idx].get();
Adam Lesinski30080e22017-10-16 16:18:09 -07001439 if (package != nullptr) {
1440 // The themes are constructed with a 1-based type ID, so no need to decrement here.
1441 const int type_idx = get_type_id(resid);
1442 const ThemeType* type = package->types[type_idx].get();
1443 if (type != nullptr) {
1444 const int entry_idx = get_entry_id(resid);
1445 if (entry_idx < type->entry_count) {
1446 const ThemeEntry& entry = type->entries[entry_idx];
1447 type_spec_flags |= entry.type_spec_flags;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001448
Adam Lesinski30080e22017-10-16 16:18:09 -07001449 if (entry.value.dataType == Res_value::TYPE_ATTRIBUTE) {
1450 if (cnt > 0) {
1451 cnt--;
1452 resid = entry.value.data;
1453 continue;
1454 }
1455 return kInvalidCookie;
1456 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001457
Adam Lesinski30080e22017-10-16 16:18:09 -07001458 // @null is different than @empty.
1459 if (entry.value.dataType == Res_value::TYPE_NULL &&
1460 entry.value.data != Res_value::DATA_NULL_EMPTY) {
1461 return kInvalidCookie;
1462 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001463
Adam Lesinski30080e22017-10-16 16:18:09 -07001464 *out_value = entry.value;
Adam Lesinskida431a22016-12-29 16:08:16 -05001465 *out_flags = type_spec_flags;
Adam Lesinski30080e22017-10-16 16:18:09 -07001466 return entry.cookie;
Adam Lesinskida431a22016-12-29 16:08:16 -05001467 }
Adam Lesinskida431a22016-12-29 16:08:16 -05001468 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001469 }
Adam Lesinski30080e22017-10-16 16:18:09 -07001470 break;
1471 } while (true);
Adam Lesinski7ad11102016-10-28 16:39:15 -07001472 return kInvalidCookie;
1473}
1474
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -08001475ApkAssetsCookie Theme::ResolveAttributeReference(ApkAssetsCookie cookie, Res_value* in_out_value,
1476 ResTable_config* in_out_selected_config,
1477 uint32_t* in_out_type_spec_flags,
Adam Lesinskibebfcc42018-02-12 14:27:46 -08001478 uint32_t* out_last_ref) const {
Adam Lesinskid1ecd7a2017-01-23 12:58:11 -08001479 if (in_out_value->dataType == Res_value::TYPE_ATTRIBUTE) {
1480 uint32_t new_flags;
1481 cookie = GetAttribute(in_out_value->data, in_out_value, &new_flags);
1482 if (cookie == kInvalidCookie) {
1483 return kInvalidCookie;
1484 }
1485
1486 if (in_out_type_spec_flags != nullptr) {
1487 *in_out_type_spec_flags |= new_flags;
1488 }
1489 }
1490 return asset_manager_->ResolveReference(cookie, in_out_value, in_out_selected_config,
1491 in_out_type_spec_flags, out_last_ref);
1492}
1493
Adam Lesinski7ad11102016-10-28 16:39:15 -07001494void Theme::Clear() {
1495 type_spec_flags_ = 0u;
1496 for (std::unique_ptr<Package>& package : packages_) {
1497 package.reset();
1498 }
1499}
1500
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001501void Theme::SetTo(const Theme& o) {
Adam Lesinski7ad11102016-10-28 16:39:15 -07001502 if (this == &o) {
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001503 return;
Adam Lesinski7ad11102016-10-28 16:39:15 -07001504 }
1505
Adam Lesinski7ad11102016-10-28 16:39:15 -07001506 type_spec_flags_ = o.type_spec_flags_;
1507
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001508 if (asset_manager_ == o.asset_manager_) {
1509 // The theme comes from the same asset manager so all theme data can be copied exactly
1510 for (size_t p = 0; p < packages_.size(); p++) {
1511 const Package *package = o.packages_[p].get();
1512 if (package == nullptr) {
1513 // The other theme doesn't have this package, clear ours.
1514 packages_[p].reset();
Adam Lesinski7ad11102016-10-28 16:39:15 -07001515 continue;
1516 }
1517
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001518 if (packages_[p] == nullptr) {
1519 // The other theme has this package, but we don't. Make one.
1520 packages_[p].reset(new Package());
1521 }
1522
1523 for (size_t t = 0; t < package->types.size(); t++) {
1524 const ThemeType *type = package->types[t].get();
1525 if (type == nullptr) {
1526 // The other theme doesn't have this type, clear ours.
1527 packages_[p]->types[t].reset();
1528 continue;
1529 }
1530
1531 // Create a new type and update it to theirs.
1532 const size_t type_alloc_size = sizeof(ThemeType) + (type->entry_count * sizeof(ThemeEntry));
1533 void *copied_data = malloc(type_alloc_size);
1534 memcpy(copied_data, type, type_alloc_size);
1535 packages_[p]->types[t].reset(reinterpret_cast<ThemeType *>(copied_data));
1536 }
1537 }
1538 } else {
1539 std::map<ApkAssetsCookie, ApkAssetsCookie> src_to_dest_asset_cookies;
1540 typedef std::map<int, int> SourceToDestinationRuntimePackageMap;
1541 std::map<ApkAssetsCookie, SourceToDestinationRuntimePackageMap> src_asset_cookie_id_map;
1542
Ryan Mitchell93bca972019-03-08 17:26:28 -08001543 // Determine which ApkAssets are loaded in both theme AssetManagers.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001544 std::vector<const ApkAssets*> src_assets = o.asset_manager_->GetApkAssets();
1545 for (size_t i = 0; i < src_assets.size(); i++) {
1546 const ApkAssets* src_asset = src_assets[i];
1547
1548 std::vector<const ApkAssets*> dest_assets = asset_manager_->GetApkAssets();
1549 for (size_t j = 0; j < dest_assets.size(); j++) {
1550 const ApkAssets* dest_asset = dest_assets[j];
1551
Ryan Mitchell93bca972019-03-08 17:26:28 -08001552 // Map the runtime package of the source apk asset to the destination apk asset.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001553 if (src_asset->GetPath() == dest_asset->GetPath()) {
1554 const std::vector<std::unique_ptr<const LoadedPackage>>& src_packages =
1555 src_asset->GetLoadedArsc()->GetPackages();
1556 const std::vector<std::unique_ptr<const LoadedPackage>>& dest_packages =
1557 dest_asset->GetLoadedArsc()->GetPackages();
1558
1559 SourceToDestinationRuntimePackageMap package_map;
1560
1561 // The source and destination package should have the same number of packages loaded in
1562 // the same order.
1563 const size_t N = src_packages.size();
1564 CHECK(N == dest_packages.size())
1565 << " LoadedArsc " << src_asset->GetPath() << " differs number of packages.";
1566 for (size_t p = 0; p < N; p++) {
1567 auto& src_package = src_packages[p];
1568 auto& dest_package = dest_packages[p];
1569 CHECK(src_package->GetPackageName() == dest_package->GetPackageName())
1570 << " Package " << src_package->GetPackageName() << " differs in load order.";
1571
1572 int src_package_id = o.asset_manager_->GetAssignedPackageId(src_package.get());
1573 int dest_package_id = asset_manager_->GetAssignedPackageId(dest_package.get());
1574 package_map[src_package_id] = dest_package_id;
1575 }
1576
Ryan Mitchell93bca972019-03-08 17:26:28 -08001577 src_to_dest_asset_cookies.insert(std::make_pair(i, j));
1578 src_asset_cookie_id_map.insert(std::make_pair(i, package_map));
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001579 break;
1580 }
1581 }
1582 }
1583
Ryan Mitchell93bca972019-03-08 17:26:28 -08001584 // Reset the data in the destination theme.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001585 for (size_t p = 0; p < packages_.size(); p++) {
1586 if (packages_[p] != nullptr) {
1587 packages_[p].reset();
1588 }
1589 }
1590
1591 for (size_t p = 0; p < packages_.size(); p++) {
1592 const Package *package = o.packages_[p].get();
1593 if (package == nullptr) {
1594 continue;
1595 }
1596
1597 for (size_t t = 0; t < package->types.size(); t++) {
1598 const ThemeType *type = package->types[t].get();
1599 if (type == nullptr) {
1600 continue;
1601 }
1602
1603 for (size_t e = 0; e < type->entry_count; e++) {
1604 const ThemeEntry &entry = type->entries[e];
1605 if (entry.value.dataType == Res_value::TYPE_NULL &&
1606 entry.value.data != Res_value::DATA_NULL_EMPTY) {
1607 continue;
1608 }
1609
Ryan Mitchell93bca972019-03-08 17:26:28 -08001610 bool is_reference = (entry.value.dataType == Res_value::TYPE_ATTRIBUTE
1611 || entry.value.dataType == Res_value::TYPE_REFERENCE
1612 || entry.value.dataType == Res_value::TYPE_DYNAMIC_ATTRIBUTE
1613 || entry.value.dataType == Res_value::TYPE_DYNAMIC_REFERENCE)
1614 && entry.value.data != 0x0;
Ryan Mitchellb85d9b22018-11-19 12:11:38 -08001615
Ryan Mitchell93bca972019-03-08 17:26:28 -08001616 // If the attribute value represents an attribute or reference, the package id of the
1617 // value needs to be rewritten to the package id of the value in the destination.
1618 uint32_t attribute_data = entry.value.data;
1619 if (is_reference) {
1620 // Determine the package id of the reference in the destination AssetManager.
Ryan Mitchellb85d9b22018-11-19 12:11:38 -08001621 auto value_package_map = src_asset_cookie_id_map.find(entry.cookie);
1622 if (value_package_map == src_asset_cookie_id_map.end()) {
1623 continue;
1624 }
1625
1626 auto value_dest_package = value_package_map->second.find(
1627 get_package_id(entry.value.data));
1628 if (value_dest_package == value_package_map->second.end()) {
1629 continue;
1630 }
1631
Ryan Mitchell93bca972019-03-08 17:26:28 -08001632 attribute_data = fix_package_id(entry.value.data, value_dest_package->second);
1633 }
1634
1635 // Find the cookie of the value in the destination. If the source apk is not loaded in the
1636 // destination, only copy resources that do not reference resources in the source.
1637 ApkAssetsCookie data_dest_cookie;
1638 auto value_dest_cookie = src_to_dest_asset_cookies.find(entry.cookie);
1639 if (value_dest_cookie != src_to_dest_asset_cookies.end()) {
1640 data_dest_cookie = value_dest_cookie->second;
1641 } else {
1642 if (is_reference || entry.value.dataType == Res_value::TYPE_STRING) {
1643 continue;
1644 } else {
1645 data_dest_cookie = 0x0;
1646 }
Ryan Mitchellb85d9b22018-11-19 12:11:38 -08001647 }
1648
1649 // The package id of the attribute needs to be rewritten to the package id of the
Ryan Mitchell93bca972019-03-08 17:26:28 -08001650 // attribute in the destination.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001651 int attribute_dest_package_id = p;
1652 if (attribute_dest_package_id != 0x01) {
Ryan Mitchell93bca972019-03-08 17:26:28 -08001653 // Find the cookie of the attribute resource id in the source AssetManager
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001654 FindEntryResult attribute_entry_result;
1655 ApkAssetsCookie attribute_cookie =
Ryan Mitchella55dc2e2019-01-24 10:58:23 -08001656 o.asset_manager_->FindEntry(make_resid(p, t, e), 0 /* density_override */ ,
1657 true /* stop_at_first_match */,
1658 true /* ignore_configuration */,
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001659 &attribute_entry_result);
1660
Ryan Mitchell93bca972019-03-08 17:26:28 -08001661 // Determine the package id of the attribute in the destination AssetManager.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001662 auto attribute_package_map = src_asset_cookie_id_map.find(attribute_cookie);
1663 if (attribute_package_map == src_asset_cookie_id_map.end()) {
1664 continue;
1665 }
1666 auto attribute_dest_package = attribute_package_map->second.find(
1667 attribute_dest_package_id);
1668 if (attribute_dest_package == attribute_package_map->second.end()) {
1669 continue;
1670 }
1671 attribute_dest_package_id = attribute_dest_package->second;
1672 }
1673
Ryan Mitchell93bca972019-03-08 17:26:28 -08001674 // Lazily instantiate the destination package.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001675 std::unique_ptr<Package>& dest_package = packages_[attribute_dest_package_id];
1676 if (dest_package == nullptr) {
1677 dest_package.reset(new Package());
1678 }
1679
Ryan Mitchell93bca972019-03-08 17:26:28 -08001680 // Lazily instantiate and resize the destination type.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001681 util::unique_cptr<ThemeType>& dest_type = dest_package->types[t];
1682 if (dest_type == nullptr || dest_type->entry_count < type->entry_count) {
1683 const size_t type_alloc_size = sizeof(ThemeType)
1684 + (type->entry_count * sizeof(ThemeEntry));
1685 void* dest_data = malloc(type_alloc_size);
1686 memset(dest_data, 0, type->entry_count * sizeof(ThemeEntry));
1687
Ryan Mitchell93bca972019-03-08 17:26:28 -08001688 // Copy the existing destination type values if the type is resized.
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001689 if (dest_type != nullptr) {
1690 memcpy(dest_data, type, sizeof(ThemeType)
1691 + (dest_type->entry_count * sizeof(ThemeEntry)));
1692 }
1693
1694 dest_type.reset(reinterpret_cast<ThemeType *>(dest_data));
1695 dest_type->entry_count = type->entry_count;
1696 }
1697
Ryan Mitchell93bca972019-03-08 17:26:28 -08001698 dest_type->entries[e].cookie = data_dest_cookie;
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001699 dest_type->entries[e].value.dataType = entry.value.dataType;
Ryan Mitchell93bca972019-03-08 17:26:28 -08001700 dest_type->entries[e].value.data = attribute_data;
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001701 dest_type->entries[e].type_spec_flags = entry.type_spec_flags;
1702 }
1703 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001704 }
1705 }
Ryan Mitchellb3ae42e2018-10-16 12:48:38 -07001706}
1707
1708void Theme::Dump() const {
1709 base::ScopedLogSeverity _log(base::INFO);
1710 LOG(INFO) << base::StringPrintf("Theme(this=%p, AssetManager2=%p)", this, asset_manager_);
1711
1712 for (int p = 0; p < packages_.size(); p++) {
1713 auto& package = packages_[p];
1714 if (package == nullptr) {
1715 continue;
1716 }
1717
1718 for (int t = 0; t < package->types.size(); t++) {
1719 auto& type = package->types[t];
1720 if (type == nullptr) {
1721 continue;
1722 }
1723
1724 for (int e = 0; e < type->entry_count; e++) {
1725 auto& entry = type->entries[e];
1726 if (entry.value.dataType == Res_value::TYPE_NULL &&
1727 entry.value.data != Res_value::DATA_NULL_EMPTY) {
1728 continue;
1729 }
1730
1731 LOG(INFO) << base::StringPrintf(" entry(0x%08x)=(0x%08x) type=(0x%02x), cookie(%d)",
1732 make_resid(p, t, e), entry.value.data,
1733 entry.value.dataType, entry.cookie);
1734 }
1735 }
1736 }
Adam Lesinski7ad11102016-10-28 16:39:15 -07001737}
1738
1739} // namespace android