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:
parent
843125b98a
commit
5293030ba0
@ -112,6 +112,13 @@ public class Account implements Serializable {
|
|||||||
public void refresh(Preferences preferences) {
|
public void refresh(Preferences preferences) {
|
||||||
mPreferences = 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
|
mStoreUri = Utility.base64Decode(preferences.mSharedPreferences.getString(mUuid
|
||||||
+ ".storeUri", null));
|
+ ".storeUri", null));
|
||||||
mLocalStoreUri = preferences.mSharedPreferences.getString(mUuid + ".localStoreUri", 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,
|
mSyncWindow = preferences.mSharedPreferences.getInt(mUuid + KEY_SYNC_WINDOW,
|
||||||
SYNC_WINDOW_USER);
|
SYNC_WINDOW_USER);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
public String getUuid() {
|
||||||
return mUuid;
|
return mUuid;
|
||||||
@ -220,6 +228,12 @@ public class Account implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Preferences preferences) {
|
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(",");
|
String[] uuids = preferences.mSharedPreferences.getString("accountUuids", "").split(",");
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (int i = 0, length = uuids.length; i < length; i++) {
|
for (int i = 0, length = uuids.length; i < length; i++) {
|
||||||
@ -258,10 +272,17 @@ public class Account implements Serializable {
|
|||||||
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void save(Preferences preferences) {
|
public void save(Preferences preferences) {
|
||||||
mPreferences = 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)) {
|
if (!preferences.mSharedPreferences.getString("accountUuids", "").contains(mUuid)) {
|
||||||
/*
|
/*
|
||||||
* When the account is first created we assign it a unique account number. The
|
* 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();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Loading…
Reference in New Issue
Block a user