Ensure the generation is not changed before put value to cache

It may get old value from mValues, so check the generation
is not changed before update cache

Bug: https://issuetracker.google.com/issues/64995655
Test: Build
Change-Id: Ia7ae18baa269d0590e36f186e2f14b0bfbab3504
Signed-off-by: xulicheng <xulicheng@xiaomi.com>
This commit is contained in:
xulicheng
2017-08-24 11:29:03 +08:00
committed by LiCheng Xu
parent 3b166fba8a
commit a5db9b42ea

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() + "]: " +