diff options
author | Narayan Kamath <narayan@google.com> | 2014-07-30 15:42:25 +0100 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2014-08-01 13:32:12 +0100 |
commit | 11bfc2261f653f1b3154b88bf692241dbd6fc477 (patch) | |
tree | 192d246362758808344450b528b4b8c01358177b /packages/SettingsProvider/src/com/android/providers/settings | |
parent | 3f1ddf83a4faba3dec71ed7eebe1835f4685cf60 (diff) | |
download | frameworks_base-11bfc2261f653f1b3154b88bf692241dbd6fc477.zip frameworks_base-11bfc2261f653f1b3154b88bf692241dbd6fc477.tar.gz frameworks_base-11bfc2261f653f1b3154b88bf692241dbd6fc477.tar.bz2 |
Don't assume languages are 2 letter codes.
Also, note that this method never worked. Locale
settings were stored with underscores (like Locale.toString)
but matched against AssetManager.getLocales() which
returned language-tag like output.
bug: 10090157
(cherry picked from commit fd138cd81a689ff46e6ae90e46adcdc53f3c5442)
Change-Id: Ifc81ac902c297387dba8c40aba0656e18af57c86
Diffstat (limited to 'packages/SettingsProvider/src/com/android/providers/settings')
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java index dd7a828..91199c1 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java @@ -190,33 +190,34 @@ public class SettingsHelper { String localeString = loc.getLanguage(); String country = loc.getCountry(); if (!TextUtils.isEmpty(country)) { - localeString += "_" + country; + localeString += "-" + country; } return localeString.getBytes(); } /** - * Sets the locale specified. Input data is the equivalent of "ll_cc".getBytes(), where - * "ll" is the language code and "cc" is the country code. + * Sets the locale specified. Input data is the byte representation of a + * BCP-47 language tag. For backwards compatibility, strings of the form + * {@code ll_CC} are also accepted, where {@code ll} is a two letter language + * code and {@code CC} is a two letter country code. + * * @param data the locale string in bytes. */ void setLocaleData(byte[] data, int size) { // Check if locale was set by the user: Configuration conf = mContext.getResources().getConfiguration(); - Locale loc = conf.locale; // TODO: The following is not working as intended because the network is forcing a locale // change after registering. Need to find some other way to detect if the user manually // changed the locale if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard final String[] availableLocales = mContext.getAssets().getLocales(); - String localeCode = new String(data, 0, size); - String language = new String(data, 0, 2); - String country = size > 4 ? new String(data, 3, 2) : ""; - loc = null; + // Replace "_" with "-" to deal with older backups. + String localeCode = new String(data, 0, size).replace('_', '-'); + Locale loc = null; for (int i = 0; i < availableLocales.length; i++) { if (availableLocales[i].equals(localeCode)) { - loc = new Locale(language, country); + loc = Locale.forLanguageTag(localeCode); break; } } |