From 7769b76fc997c2afea169668ff1eee9d158b74f9 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 29 Mar 2012 14:36:45 +0900 Subject: [PATCH] Fix race condition while changing the system locale Bug: 6128216 Change-Id: Ie153e3eb18feeb97aada6a7708075f5152f11999 --- .../com/android/inputmethod/latin/LocaleUtils.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java index e05b47cb7..cf60089c5 100644 --- a/java/src/com/android/inputmethod/latin/LocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java @@ -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; - conf.locale = newLocale; - res.updateConfiguration(conf, res.getDisplayMetrics()); - return saveLocale; + final Locale oldLocale = conf.locale; + if (newLocale != null && !newLocale.equals(oldLocale)) { + conf.locale = newLocale; + res.updateConfiguration(conf, res.getDisplayMetrics()); + } + return oldLocale; } private static final HashMap sLocaleCache = new HashMap();