Skip to content

Commit 05f5236

Browse files
satok16Android (Google) Code Review
authored andcommitted
Merge "Make InputMethodSubtype thread safe" into jb-dev
2 parents faf5b16 + e52eb4e commit 05f5236

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

core/java/android/view/inputmethod/InputMethodSubtype.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public final class InputMethodSubtype implements Parcelable {
5858
private final String mSubtypeLocale;
5959
private final String mSubtypeMode;
6060
private final String mSubtypeExtraValue;
61-
private HashMap<String, String> mExtraValueHashMapCache;
61+
private volatile HashMap<String, String> mExtraValueHashMapCache;
6262

6363
/**
6464
* Constructor.
@@ -237,18 +237,22 @@ public CharSequence getDisplayName(
237237

238238
private HashMap<String, String> getExtraValueHashMap() {
239239
if (mExtraValueHashMapCache == null) {
240-
mExtraValueHashMapCache = new HashMap<String, String>();
241-
final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR);
242-
final int N = pairs.length;
243-
for (int i = 0; i < N; ++i) {
244-
final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR);
245-
if (pair.length == 1) {
246-
mExtraValueHashMapCache.put(pair[0], null);
247-
} else if (pair.length > 1) {
248-
if (pair.length > 2) {
249-
Slog.w(TAG, "ExtraValue has two or more '='s");
240+
synchronized(this) {
241+
if (mExtraValueHashMapCache == null) {
242+
mExtraValueHashMapCache = new HashMap<String, String>();
243+
final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR);
244+
final int N = pairs.length;
245+
for (int i = 0; i < N; ++i) {
246+
final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR);
247+
if (pair.length == 1) {
248+
mExtraValueHashMapCache.put(pair[0], null);
249+
} else if (pair.length > 1) {
250+
if (pair.length > 2) {
251+
Slog.w(TAG, "ExtraValue has two or more '='s");
252+
}
253+
mExtraValueHashMapCache.put(pair[0], pair[1]);
254+
}
250255
}
251-
mExtraValueHashMapCache.put(pair[0], pair[1]);
252256
}
253257
}
254258
}

0 commit comments

Comments
 (0)