Merge "Ensure the generation is not changed before put value to cache"

This commit is contained in:
Treehugger Robot
2017-08-28 19:42:11 +00:00
committed by Gerrit Code Review

View File

@@ -1734,6 +1734,10 @@ public final class Settings {
return true;
}
public int getCurrentGeneration() {
return mCurrentGeneration;
}
private int readCurrentGeneration() {
try {
return mArray.get(mIndex);
@@ -1836,6 +1840,7 @@ public final class Settings {
public String getStringForUser(ContentResolver cr, String name, final int userHandle) {
final boolean isSelf = (userHandle == UserHandle.myUserId());
int currentGeneration = -1;
if (isSelf) {
synchronized (NameValueCache.this) {
if (mGenerationTracker != null) {
@@ -1849,6 +1854,9 @@ public final class Settings {
} else if (mValues.containsKey(name)) {
return mValues.get(name);
}
if (mGenerationTracker != null) {
currentGeneration = mGenerationTracker.getCurrentGeneration();
}
}
}
} else {
@@ -1939,7 +1947,10 @@ public final class Settings {
});
}
}
mValues.put(name, value);
if (mGenerationTracker != null && currentGeneration ==
mGenerationTracker.getCurrentGeneration()) {
mValues.put(name, value);
}
}
} else {
if (LOCAL_LOGV) Log.i(TAG, "call-query of user " + userHandle
@@ -1980,7 +1991,10 @@ public final class Settings {
String value = c.moveToNext() ? c.getString(0) : null;
synchronized (NameValueCache.this) {
mValues.put(name, value);
if(mGenerationTracker != null &&
currentGeneration == mGenerationTracker.getCurrentGeneration()) {
mValues.put(name, value);
}
}
if (LOCAL_LOGV) {
Log.v(TAG, "cache miss [" + mUri.getLastPathSegment() + "]: " +