diff options
author | satok <satok@google.com> | 2012-05-08 14:45:09 +0900 |
---|---|---|
committer | satok <satok@google.com> | 2012-05-08 14:45:09 +0900 |
commit | e52eb4e289bf8d7b04582803b0d0f9ab7399c1af (patch) | |
tree | e304262c5c84fc1c49498e2e26d2e8987b726cb4 /core/java/android/view/inputmethod | |
parent | c33208fe72662fd89b75e996dbd495237a0021d4 (diff) | |
download | frameworks_base-e52eb4e289bf8d7b04582803b0d0f9ab7399c1af.zip frameworks_base-e52eb4e289bf8d7b04582803b0d0f9ab7399c1af.tar.gz frameworks_base-e52eb4e289bf8d7b04582803b0d0f9ab7399c1af.tar.bz2 |
Make InputMethodSubtype thread safe
Bug: 6327800
Change-Id: I549d1ec377793e918800d919b39fd8f4b6f0db41
Diffstat (limited to 'core/java/android/view/inputmethod')
-rw-r--r-- | core/java/android/view/inputmethod/InputMethodSubtype.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodSubtype.java b/core/java/android/view/inputmethod/InputMethodSubtype.java index c22750e..b7c94a3 100644 --- a/core/java/android/view/inputmethod/InputMethodSubtype.java +++ b/core/java/android/view/inputmethod/InputMethodSubtype.java @@ -58,7 +58,7 @@ public final class InputMethodSubtype implements Parcelable { private final String mSubtypeLocale; private final String mSubtypeMode; private final String mSubtypeExtraValue; - private HashMap<String, String> mExtraValueHashMapCache; + private volatile HashMap<String, String> mExtraValueHashMapCache; /** * Constructor. @@ -237,18 +237,22 @@ public final class InputMethodSubtype implements Parcelable { private HashMap<String, String> getExtraValueHashMap() { if (mExtraValueHashMapCache == null) { - mExtraValueHashMapCache = new HashMap<String, String>(); - final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); - final int N = pairs.length; - for (int i = 0; i < N; ++i) { - final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); - if (pair.length == 1) { - mExtraValueHashMapCache.put(pair[0], null); - } else if (pair.length > 1) { - if (pair.length > 2) { - Slog.w(TAG, "ExtraValue has two or more '='s"); + synchronized(this) { + if (mExtraValueHashMapCache == null) { + mExtraValueHashMapCache = new HashMap<String, String>(); + final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); + final int N = pairs.length; + for (int i = 0; i < N; ++i) { + final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); + if (pair.length == 1) { + mExtraValueHashMapCache.put(pair[0], null); + } else if (pair.length > 1) { + if (pair.length > 2) { + Slog.w(TAG, "ExtraValue has two or more '='s"); + } + mExtraValueHashMapCache.put(pair[0], pair[1]); + } } - mExtraValueHashMapCache.put(pair[0], pair[1]); } } } |