diff options
author | 2024-01-25 11:07:48 -0800 | |
---|---|---|
committer | 2024-02-10 03:39:59 +0000 | |
commit | 8bd3903dd88a7ff0f5beb76f4a2bfa007857f399 (patch) | |
tree | b043fa2065a9e52d90e13e6286ebec2fd6cce518 /libs/androidfw/AssetManager2.cpp | |
parent | 1f66b73624cc47c7540959fe7df83da9db07ff23 (diff) |
[res] Don't recalculate configuration twice on init
When creating a ResourcesImpl object the native code calls
AssetManager::RebuildFilterList() twice: first with the default
configuration, and later when the actual one gets applied.
This CL introduces a way to skip the first call and ensure that
the second one is 'forced', so it always only calls it with the
final configuration
Bug: 282215580
Test: build + boot + presubmit
Change-Id: I8fd3801b5782c9ca202aaf7b8ae5db59cce83c11
Diffstat (limited to 'libs/androidfw/AssetManager2.cpp')
-rw-r--r-- | libs/androidfw/AssetManager2.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 8748dab581bb..46f636e2ae7f 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -117,6 +117,10 @@ bool AssetManager2::SetApkAssets(ApkAssetsList apk_assets, bool invalidate_cache return true; } +void AssetManager2::PresetApkAssets(ApkAssetsList apk_assets) { + BuildDynamicRefTable(apk_assets); +} + bool AssetManager2::SetApkAssets(std::initializer_list<ApkAssetsPtr> apk_assets, bool invalidate_caches) { return SetApkAssets(ApkAssetsList(apk_assets.begin(), apk_assets.size()), invalidate_caches); @@ -432,13 +436,18 @@ bool AssetManager2::ContainsAllocatedTable() const { return false; } -void AssetManager2::SetConfigurations(std::vector<ResTable_config> configurations) { +void AssetManager2::SetConfigurations(std::vector<ResTable_config> configurations, + bool force_refresh) { int diff = 0; - if (configurations_.size() != configurations.size()) { + if (force_refresh) { diff = -1; } else { - for (int i = 0; i < configurations_.size(); i++) { - diff |= configurations_[i].diff(configurations[i]); + if (configurations_.size() != configurations.size()) { + diff = -1; + } else { + for (int i = 0; i < configurations_.size(); i++) { + diff |= configurations_[i].diff(configurations[i]); + } } } configurations_ = std::move(configurations); @@ -775,8 +784,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry( bool has_locale = false; if (result->config.locale == 0) { if (default_locale_ != 0) { - ResTable_config conf; - conf.locale = default_locale_; + ResTable_config conf = {.locale = default_locale_}; // Since we know conf has a locale and only a locale, match will tell us if that locale // matches has_locale = conf.match(config); |