Fix race condition while changing the system locale
Bug: 6128216 Change-Id: Ie153e3eb18feeb97aada6a7708075f5152f11999
This commit is contained in:
parent
fc50a41078
commit
7769b76fc9
1 changed files with 7 additions and 5 deletions
|
@ -168,12 +168,14 @@ public class LocaleUtils {
|
|||
* @param newLocale the locale to change to.
|
||||
* @return the old locale.
|
||||
*/
|
||||
public static Locale setSystemLocale(final Resources res, final Locale newLocale) {
|
||||
public static synchronized Locale setSystemLocale(final Resources res, final Locale newLocale) {
|
||||
final Configuration conf = res.getConfiguration();
|
||||
final Locale saveLocale = conf.locale;
|
||||
final Locale oldLocale = conf.locale;
|
||||
if (newLocale != null && !newLocale.equals(oldLocale)) {
|
||||
conf.locale = newLocale;
|
||||
res.updateConfiguration(conf, res.getDisplayMetrics());
|
||||
return saveLocale;
|
||||
}
|
||||
return oldLocale;
|
||||
}
|
||||
|
||||
private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
|
||||
|
|
Loading…
Reference in a new issue