diff options
author | 2025-02-19 16:55:19 -0800 | |
---|---|---|
committer | 2025-02-21 11:42:20 -0800 | |
commit | e00958a5f80e93a4b6ca29b48a20441cd1e323d2 (patch) | |
tree | 547675d1020385ed3ca6ee96e7a27c7f18b6c8b0 /libs/androidfw | |
parent | b281da207c5b7f57dcc1ac696b95a378e922bd53 (diff) |
Log locale changes from AssetManager2.cpp
Test: automated
Bug: 392255526
Flag: EXEMPT bugfix
Change-Id: Ibde9ebc2f00e5046e3778d59f8b919e0262a8e9a
Diffstat (limited to 'libs/androidfw')
-rw-r--r-- | libs/androidfw/AssetManager2.cpp | 68 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/AssetManager2.h | 7 |
2 files changed, 63 insertions, 12 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 7a51c20f7672..714f6e41ff05 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -23,6 +23,7 @@ #include <map> #include <set> #include <span> +#include <sstream> #include <utility> #include "android-base/logging.h" @@ -64,7 +65,7 @@ base::expected<EntryValue, IOError> GetEntryValue( return table_entry->value(); } -} // namespace +} // namespace struct FindEntryResult { // The cookie representing the ApkAssets in which the value resides. @@ -441,6 +442,24 @@ bool AssetManager2::ContainsAllocatedTable() const { return false; } +static std::string ConfigVecToString(std::span<const ResTable_config> configurations) { + std::stringstream ss; + ss << "["; + bool first = true; + for (const auto& config : configurations) { + if (!first) { + ss << ","; + } + char out[RESTABLE_MAX_LOCALE_LEN] = {}; + config.getBcp47Locale(out); + ss << out; + first = false; + } + ss << "]"; + return ss.str(); +} + + void AssetManager2::SetConfigurations(std::span<const ResTable_config> configurations, bool force_refresh) { int diff = 0; @@ -455,6 +474,17 @@ void AssetManager2::SetConfigurations(std::span<const ResTable_config> configura } } } + + // Log the locale list change to investigate b/392255526 + if (diff & ConfigDescription::CONFIG_LOCALE) { + auto oldstr = ConfigVecToString(configurations_); + auto newstr = ConfigVecToString(configurations); + if (oldstr != newstr) { + LOG(INFO) << "AssetManager2(" << this << ") locale list changing from " + << oldstr << " to " << newstr; + } + } + configurations_.clear(); for (auto&& config : configurations) { configurations_.emplace_back(config); @@ -465,6 +495,28 @@ void AssetManager2::SetConfigurations(std::span<const ResTable_config> configura } } +void AssetManager2::SetDefaultLocale(std::optional<ResTable_config> default_locale) { + int diff = 0; + if (default_locale_ && default_locale) { + diff = default_locale_->diff(default_locale.value()); + } else if (default_locale_ || default_locale) { + diff = -1; + } + if (diff & ConfigDescription::CONFIG_LOCALE) { + char old_loc[RESTABLE_MAX_LOCALE_LEN] = {}; + char new_loc[RESTABLE_MAX_LOCALE_LEN] = {}; + if (default_locale_) { + default_locale_->getBcp47Locale(old_loc); + } + if (default_locale) { + default_locale->getBcp47Locale(new_loc); + } + LOG(INFO) << "AssetManager2(" << this << ") default locale changing from '" + << old_loc << "' to '" << new_loc << "'"; + } + default_locale_ = default_locale; +} + void AssetManager2::SetOverlayConstraints(int32_t display_id, int32_t device_id) { bool changed = false; if (display_id_ != display_id) { @@ -735,7 +787,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry( ConfigDescription best_frro_config; Res_value best_frro_value; bool frro_found = false; - for (const auto& [config, value] : overlay_entry.GetInlineValue()) { + for(const auto& [config, value] : overlay_entry.GetInlineValue()) { if ((!frro_found || config.isBetterThan(best_frro_config, desired_config)) && config.match(*desired_config)) { frro_found = true; @@ -814,11 +866,11 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry( bool has_locale = false; if (result->config.locale == 0) { - if (default_locale_ != 0) { - 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); + // The default_locale_ is the locale used for any resources with no locale in the config + if (default_locale_) { + // Since we know default_locale_ has a locale and only a locale, match will tell us if that + // locale matches + has_locale = default_locale_->match(config); } } else { has_locale = true; @@ -1505,7 +1557,7 @@ base::expected<uint32_t, NullOrIOError> AssetManager2::GetResourceId( base::expected<uint32_t, NullOrIOError> resid = package->FindEntryByName(type16, entry16); if (UNLIKELY(IsIOError(resid))) { return base::unexpected(resid.error()); - } + } if (!resid.has_value() && kAttr16 == type16) { // Private attributes in libraries (such as the framework) are sometimes encoded diff --git a/libs/androidfw/include/androidfw/AssetManager2.h b/libs/androidfw/include/androidfw/AssetManager2.h index a47fe6a7f50d..b0179524f6cd 100644 --- a/libs/androidfw/include/androidfw/AssetManager2.h +++ b/libs/androidfw/include/androidfw/AssetManager2.h @@ -21,6 +21,7 @@ #include <array> #include <limits> +#include <optional> #include <set> #include <span> #include <unordered_map> @@ -167,9 +168,7 @@ class AssetManager2 { return configurations_; } - inline void SetDefaultLocale(uint32_t default_locale) { - default_locale_ = default_locale; - } + void SetDefaultLocale(const std::optional<ResTable_config> default_locale); void SetOverlayConstraints(int32_t display_id, int32_t device_id); @@ -481,7 +480,7 @@ class AssetManager2 { // without taking too much memory. std::array<uint8_t, std::numeric_limits<uint8_t>::max() + 1> package_ids_ = {}; - uint32_t default_locale_ = 0; + std::optional<ResTable_config> default_locale_; // The current configurations set for this AssetManager. When this changes, cached resources // may need to be purged. |