diff options
author | 2025-03-13 23:28:37 -0700 | |
---|---|---|
committer | 2025-03-14 02:33:20 -0700 | |
commit | bcdcae5f629a5efca2ff0e0726f16eb5ffb13cf5 (patch) | |
tree | a0aae97eebe168873fb63e12e90794fb0959d74b | |
parent | 42557184519ae8b57f74fce21ff3de002e1794d3 (diff) |
Filter duplicate language code and script in system locale restoration
The new system language design restricts multiple country/region locales
for the same language code. Therefore, the system language restoration
flow must apply the same restriction.
Bug: 403442408
Test: run the test
Flag: EXEMPT bugfix
Change-Id: I1287483fdb56a00029ae1b03c86425361d4cdd1d
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java | 17 | ||||
-rw-r--r-- | packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java | 6 |
2 files changed, 21 insertions, 2 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java index ed11e12c32ff..2273b4f81eea 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java @@ -54,6 +54,7 @@ import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManage import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; @@ -650,6 +651,10 @@ public class SettingsHelper { * e.g. current locale "en-US,zh-CN" and backup locale "ja-JP,zh-Hans-CN,en-US" are merged to * "en-US,zh-CN,ja-JP". * + * - Same language codes and scripts are dropped. + * e.g. current locale "en-US, zh-Hans-TW" and backup locale "en-UK, en-GB, zh-Hans-HK" are + * merged to "en-US, zh-Hans-TW". + * * - Unsupported locales are dropped. * e.g. current locale "en-US" and backup locale "ja-JP,zh-CN" but the supported locales * are "en-US,zh-CN", the merged locale list is "en-US,zh-CN". @@ -683,13 +688,23 @@ public class SettingsHelper { filtered.add(locale); } + final HashSet<String> existingLanguageAndScript = new HashSet<>(); for (int i = 0; i < restore.size(); i++) { final Locale restoredLocaleWithExtension = copyExtensionToTargetLocale(restoredLocale, getFilteredLocale(restore.get(i), allLocales)); + if (restoredLocaleWithExtension != null) { - filtered.add(restoredLocaleWithExtension); + String language = restoredLocaleWithExtension.getLanguage(); + String script = restoredLocaleWithExtension.getScript(); + + String restoredLanguageAndScript = + script == null ? language : language + "-" + script; + if (existingLanguageAndScript.add(restoredLanguageAndScript)) { + filtered.add(restoredLocaleWithExtension); + } } } + if (filtered.size() == current.size()) { return current; // Nothing added to current locale list. } diff --git a/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java b/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java index 40654b0e2f37..48c778542d66 100644 --- a/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java +++ b/packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java @@ -388,7 +388,11 @@ public class SettingsHelperTest { LocaleList.forLanguageTags("zh-Hant-TW"), // current new String[] { "fa-Arab-AF-u-nu-latn", "zh-Hant-TW" })); // supported - + assertEquals(LocaleList.forLanguageTags("en-US,zh-Hans-TW"), + SettingsHelper.resolveLocales( + LocaleList.forLanguageTags("en-UK,en-GB,zh-Hans-HK"), // restore + LocaleList.forLanguageTags("en-US,zh-Hans-TW"), // current + new String[] { "en-US,zh-Hans-TW,en-UK,en-GB,zh-Hans-HK" })); // supported } @Test |