Change locale comparison API

Bug: 209729853
Test: atest AppLocaleDetailsTest
Change-Id: I1568fe9474e473ac6d3fb81dcf9edf9ba7434e85
This commit is contained in:
allenwtsu
2021-12-17 01:11:35 +08:00
parent e2f4baed0b
commit 03711a8ed4
2 changed files with 32 additions and 2 deletions

View File

@@ -237,18 +237,28 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
mSuggestedLocales.add(appLocale);
}
// 2nd locale in suggested languages group.
if (simLocale != null && !simLocale.equals(appLocale)) {
if (simLocale != null && !compareLocale(simLocale, appLocale)) {
mSuggestedLocales.add(simLocale);
}
// Other locales in suggested languages group.
for (int i = 0; i < currentSystemLocales.size(); i++) {
Locale locale = currentSystemLocales.get(i);
if (!locale.equals(appLocale) && !locale.equals(simLocale)) {
if (!compareLocale(locale, appLocale) && !compareLocale(locale, simLocale)) {
mSuggestedLocales.add(locale);
}
}
}
static boolean compareLocale(Locale source, Locale target) {
if (source == null && target == null) {
return true;
} else if (source != null && target != null) {
return LocaleList.matchesLanguageAndScript(source, target);
} else {
return false;
}
}
@VisibleForTesting
void handleSupportedLocales() {
//TODO Waiting for PackageManager api