Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aaa9e862 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Fix race condition while changing the system locale"

parents 5bf11402 7769b76f
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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>();