AI 148333: Evidence from failures, and inspection of source, leads me to believe

that SharedPreferences has some non-thread-safe paths.  As a quick,
  brute-force workaround, I'm putting a global lock around our use of it.
  This is a bit inefficient, but cases of multiple threads writing to it
  should be very rare.
  Note, we don't have an explicit test for this (I will think about
  finding a way to write one), but the evidence of this failure is that
  after some amount of activity in the Email app, we see corruption in
  the string mSenderUri.
  BUG=1822859

Automated import of CL 148333
This commit is contained in:
Andy Stadler 2009-05-05 16:32:33 -07:00 committed by The Android Open Source Project
parent 843125b98a
commit 5293030ba0

View File

@ -112,6 +112,13 @@ public class Account implements Serializable {
public void refresh(Preferences preferences) {
mPreferences = preferences;
/**
* Note: Until we have resolved the potential for synchronization failures in
* SharedPreferences, we're going to do a global lock around the read and write
* functions.
*/
synchronized (Account.class) {
mStoreUri = Utility.base64Decode(preferences.mSharedPreferences.getString(mUuid
+ ".storeUri", null));
mLocalStoreUri = preferences.mSharedPreferences.getString(mUuid + ".localStoreUri", null);
@ -158,6 +165,7 @@ public class Account implements Serializable {
mSyncWindow = preferences.mSharedPreferences.getInt(mUuid + KEY_SYNC_WINDOW,
SYNC_WINDOW_USER);
}
}
public String getUuid() {
return mUuid;
@ -220,6 +228,12 @@ public class Account implements Serializable {
}
public void delete(Preferences preferences) {
/**
* Note: Until we have resolved the potential for synchronization failures in
* SharedPreferences, we're going to do a global lock around the read and write
* functions.
*/
synchronized (Account.class) {
String[] uuids = preferences.mSharedPreferences.getString("accountUuids", "").split(",");
StringBuffer sb = new StringBuffer();
for (int i = 0, length = uuids.length; i < length; i++) {
@ -258,10 +272,17 @@ public class Account implements Serializable {
editor.commit();
}
}
public void save(Preferences preferences) {
mPreferences = preferences;
/**
* Note: Until we have resolved the potential for synchronization failures in
* SharedPreferences, we're going to do a global lock around the read and write
* functions.
*/
synchronized (Account.class) {
if (!preferences.mSharedPreferences.getString("accountUuids", "").contains(mUuid)) {
/*
* When the account is first created we assign it a unique account number. The
@ -325,6 +346,7 @@ public class Account implements Serializable {
editor.commit();
}
}
@Override
public String toString() {