Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd850641 authored by Svet Ganov's avatar Svet Ganov Committed by The Android Automerger
Browse files

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
parent 60e8ddee
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -1548,7 +1548,7 @@ public final class Settings {

        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 final class Settings {
        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 @@ public final class Settings {
                        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 @@ public final class Settings {
                        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 @@ public final class Settings {
                                        }
                                        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 @@ public final class Settings {
                }

                String value = c.moveToNext() ? c.getString(0) : null;
                synchronized (this) {
                synchronized (NameValueCache.this) {
                    mValues.put(name, value);
                }
                if (LOCAL_LOGV) {