From 668ec5bd3bd9d5fe6ebf46985eacd3d8d81af937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Mon, 11 Jun 2018 14:11:33 +0200 Subject: [PATCH] AssetManager2: optionally keep non-matching configs AssetManager2 maintains a set of configurations [as specified in the resource blob] compatible with the currently set configuration [as specified via SetConfiguration]. This helps optimize future resource lookups by limiting the set of configurations to iterate over. However, when creating idmaps, all configurations must be considered, including those not compatible with the currently set configuration. Add an optional flag to SetApkAssets to disable the optimization described above. Test: manual (will be tested by upcoming idmap2 implementation) Change-Id: I7526a323ddf90e2f2f49c36e8c110a2cec25357e --- libs/androidfw/AssetManager2.cpp | 8 ++++---- libs/androidfw/include/androidfw/AssetManager2.h | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 9c1629bc36f58..04cc5bb30ade1 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -67,10 +67,10 @@ AssetManager2::AssetManager2() { } bool AssetManager2::SetApkAssets(const std::vector& apk_assets, - bool invalidate_caches) { + bool invalidate_caches, bool filter_incompatible_configs) { apk_assets_ = apk_assets; BuildDynamicRefTable(); - RebuildFilterList(); + RebuildFilterList(filter_incompatible_configs); if (invalidate_caches) { InvalidateCaches(static_cast(-1)); } @@ -825,7 +825,7 @@ uint32_t AssetManager2::GetResourceId(const std::string& resource_name, return 0u; } -void AssetManager2::RebuildFilterList() { +void AssetManager2::RebuildFilterList(bool filter_incompatible_configs) { for (PackageGroup& group : package_groups_) { for (ConfiguredPackage& impl : group.packages_) { // Destroy it. @@ -841,7 +841,7 @@ void AssetManager2::RebuildFilterList() { for (auto iter = spec->types; iter != iter_end; ++iter) { ResTable_config this_config; this_config.copyFromDtoH((*iter)->config); - if (this_config.match(configuration_)) { + if (!filter_incompatible_configs || this_config.match(configuration_)) { group.configurations.push_back(this_config); group.types.push_back(*iter); } diff --git a/libs/androidfw/include/androidfw/AssetManager2.h b/libs/androidfw/include/androidfw/AssetManager2.h index ad31f69404389..2f0ee01639fe9 100644 --- a/libs/androidfw/include/androidfw/AssetManager2.h +++ b/libs/androidfw/include/androidfw/AssetManager2.h @@ -96,7 +96,12 @@ class AssetManager2 { // Only pass invalidate_caches=false when it is known that the structure // change in ApkAssets is due to a safe addition of resources with completely // new resource IDs. - bool SetApkAssets(const std::vector& apk_assets, bool invalidate_caches = true); + // + // Only pass in filter_incompatible_configs=false when you want to load all + // configurations (including incompatible ones) such as when constructing an + // idmap. + bool SetApkAssets(const std::vector& apk_assets, bool invalidate_caches = true, + bool filter_incompatible_configs = true); inline const std::vector GetApkAssets() const { return apk_assets_; @@ -274,7 +279,7 @@ class AssetManager2 { // Triggers the re-construction of lists of types that match the set configuration. // This should always be called when mutating the AssetManager's configuration or ApkAssets set. - void RebuildFilterList(); + void RebuildFilterList(bool filter_incompatible_configs = true); // AssetManager2::GetBag(resid) wraps this function to track which resource ids have already // been seen while traversing bag parents.