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

Commit 6f9d58ac authored by Brad Fitzpatrick's avatar Brad Fitzpatrick
Browse files

Make SharedPreferencesBackupHelper wait for async SharedPreference writes

Fixes a potential race with backups.

Change-Id: I73492c0384091cedd7802109257312387fcd43f9
parent 960b31e3
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app.backup;

import android.app.QueuedWork;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.ParcelFileDescriptor;
@@ -95,6 +96,10 @@ public class SharedPreferencesBackupHelper extends FileBackupHelperBase implemen
            ParcelFileDescriptor newState) {
        Context context = mContext;

        // If a SharedPreference has an outstanding write in flight,
        // wait for it to finish flushing to disk.
        QueuedWork.waitToFinish();

        // make filenames for the prefGroups
        String[] prefGroups = mPrefGroups;
        final int N = prefGroups.length;
@@ -123,4 +128,3 @@ public class SharedPreferencesBackupHelper extends FileBackupHelperBase implemen
        }
    }
}