am ba2f4f84: Merge "Fix a concurrency bug."

* commit 'ba2f4f84cab1e5910968b93e26f1c2f08c8642b3':
  Fix a concurrency bug.
main
Jean Chalard 2013-08-02 04:33:13 -07:00 committed by Android Git Automerger
commit 9cd592c210
1 changed files with 27 additions and 14 deletions

View File

@ -27,12 +27,14 @@ import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
import com.android.inputmethod.latin.utils.DebugLogUtils;
import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.RunInLocale;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.locks.ReentrantLock;
public final class Settings implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = Settings.class.getSimpleName();
@ -94,6 +96,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
private Resources mRes;
private SharedPreferences mPrefs;
private SettingsValues mSettingsValues;
private final ReentrantLock mSettingsValuesLock = new ReentrantLock();
private static final Settings sInstance = new Settings();
@ -121,6 +124,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
mSettingsValuesLock.lock();
try {
if (mSettingsValues == null) {
// TODO: Introduce a static function to register this class and ensure that
// loadSettings must be called before "onSharedPreferenceChanged" is called.
@ -128,9 +133,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return;
}
loadSettings(mSettingsValues.mLocale, mSettingsValues.mInputAttributes);
} finally {
mSettingsValuesLock.unlock();
}
}
public void loadSettings(final Locale locale, final InputAttributes inputAttributes) {
mSettingsValuesLock.lock();
try {
final SharedPreferences prefs = mPrefs;
final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
@Override
@ -139,6 +149,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
}
};
mSettingsValues = job.runInLocale(mRes, locale);
} finally {
mSettingsValuesLock.unlock();
}
}
// TODO: Remove this method and add proxy method to SettingsValues.