Use proper lock when accessing the generation registry
We use 'this' for synchronization in NameValueCache but some code
that accesses the generation registry uses 'this' in a different
context ending up syncing on the wrong instance. This is why
sync on this is just a bad idea.
bug:29956424
Change-Id: Ide2d4f07a5f40cb3f0e8f50e4c8de216d15a31ee
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 293eb9b..9c567a9 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1548,7 +1548,7 @@
private IContentProvider lazyGetProvider(ContentResolver cr) {
IContentProvider cp = null;
- synchronized (this) {
+ synchronized (NameValueCache.this) {
cp = mContentProvider;
if (cp == null) {
cp = mContentProvider = cr.acquireProvider(mUri.getAuthority());
@@ -1575,7 +1575,7 @@
public String getStringForUser(ContentResolver cr, String name, final int userHandle) {
final boolean isSelf = (userHandle == UserHandle.myUserId());
if (isSelf) {
- synchronized (this) {
+ synchronized (NameValueCache.this) {
if (mGenerationTracker != null) {
if (mGenerationTracker.isGenerationChanged()) {
if (DEBUG) {
@@ -1608,7 +1608,7 @@
args.putInt(CALL_METHOD_USER_KEY, userHandle);
}
boolean needsGenerationTracker = false;
- synchronized (this) {
+ synchronized (NameValueCache.this) {
if (isSelf && mGenerationTracker == null) {
needsGenerationTracker = true;
if (args == null) {
@@ -1627,7 +1627,7 @@
String value = b.getString(Settings.NameValueTable.VALUE);
// Don't update our cache for reads of other users' data
if (isSelf) {
- synchronized (this) {
+ synchronized (NameValueCache.this) {
if (needsGenerationTracker) {
MemoryIntArray array = b.getParcelable(
CALL_METHOD_TRACK_GENERATION_KEY);
@@ -1644,7 +1644,7 @@
}
mGenerationTracker = new GenerationTracker(array, index,
generation, () -> {
- synchronized (this) {
+ synchronized (NameValueCache.this) {
Log.e(TAG, "Error accessing generation"
+ " tracker - removing");
if (mGenerationTracker != null) {
@@ -1685,7 +1685,7 @@
}
String value = c.moveToNext() ? c.getString(0) : null;
- synchronized (this) {
+ synchronized (NameValueCache.this) {
mValues.put(name, value);
}
if (LOCAL_LOGV) {