From e00958a5f80e93a4b6ca29b48a20441cd1e323d2 Mon Sep 17 00:00:00 2001 From: Jeremy Meyer Date: Wed, 19 Feb 2025 16:55:19 -0800 Subject: Log locale changes from AssetManager2.cpp Test: automated Bug: 392255526 Flag: EXEMPT bugfix Change-Id: Ibde9ebc2f00e5046e3778d59f8b919e0262a8e9a --- libs/androidfw/AssetManager2.cpp | 68 +++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) (limited to 'libs/androidfw/AssetManager2.cpp') 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 #include #include +#include #include #include "android-base/logging.h" @@ -64,7 +65,7 @@ base::expected 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 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 configurations, bool force_refresh) { int diff = 0; @@ -455,6 +474,17 @@ void AssetManager2::SetConfigurations(std::span 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 configura } } +void AssetManager2::SetDefaultLocale(std::optional 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 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 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 AssetManager2::GetResourceId( base::expected 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 -- cgit v1.2.3-59-g8ed1b