diff options
author | 2025-03-17 17:00:04 -0700 | |
---|---|---|
committer | 2025-03-17 18:12:06 -0700 | |
commit | 2e609b19a6ed19403ce7a5330058d290a6312cba (patch) | |
tree | c8df592d772599e02246541df0ca694c8cad41de /libs/androidfw | |
parent | ab6139120fd01b792519e5e800e735f46cd83d45 (diff) |
[res] Minor code cleanups
- try with resources
- use a reference for non-optional argument instead of a pointer
Test: unit tests
Flag: EXEMPT minor refactoring
Change-Id: I365b8fc2058b01edd6dd6bd7d3a131af4834d98c
Diffstat (limited to 'libs/androidfw')
-rw-r--r-- | libs/androidfw/AssetManager2.cpp | 4 | ||||
-rw-r--r-- | libs/androidfw/ResourceTypes.cpp | 16 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/ResourceTypes.h | 5 |
3 files changed, 13 insertions, 12 deletions
diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index 714f6e41ff05..e09ab5fd1643 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -879,10 +879,10 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry( // if we don't have a result yet if (!final_result || // or this config is better before the locale than the existing result - result->config.isBetterThanBeforeLocale(final_result->config, desired_config) || + result->config.isBetterThanBeforeLocale(final_result->config, *desired_config) || // or the existing config isn't better before locale and this one specifies a locale // whereas the existing one doesn't - (!final_result->config.isBetterThanBeforeLocale(result->config, desired_config) + (!final_result->config.isBetterThanBeforeLocale(result->config, *desired_config) && has_locale && !final_has_locale)) { final_result = result.value(); final_overlaid = overlaid; diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 8ecd6ba9b253..6ec605c2ced5 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -2615,16 +2615,14 @@ bool ResTable_config::isLocaleBetterThan(const ResTable_config& o, } bool ResTable_config::isBetterThanBeforeLocale(const ResTable_config& o, - const ResTable_config* requested) const { - if (requested) { - if (imsi || o.imsi) { - if ((mcc != o.mcc) && requested->mcc) { - return (mcc); - } + const ResTable_config& requested) const { + if (imsi || o.imsi) { + if ((mcc != o.mcc) && requested.mcc) { + return mcc; + } - if ((mnc != o.mnc) && requested->mnc) { - return (mnc); - } + if ((mnc != o.mnc) && requested.mnc) { + return mnc; } } return false; diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h index 63b28da075cd..bd72d3741460 100644 --- a/libs/androidfw/include/androidfw/ResourceTypes.h +++ b/libs/androidfw/include/androidfw/ResourceTypes.h @@ -1416,7 +1416,10 @@ struct ResTable_config // match the requested configuration at all. bool isLocaleBetterThan(const ResTable_config& o, const ResTable_config* requested) const; - bool isBetterThanBeforeLocale(const ResTable_config& o, const ResTable_config* requested) const; + // The first part of isBetterThan() that only compares the fields that are higher priority than + // the locale. Use it when you need to do custom locale matching to filter out the configs prior + // to that. + bool isBetterThanBeforeLocale(const ResTable_config& o, const ResTable_config& requested) const; String8 toString() const; |