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

Commit 9bdc35b2 authored by Rich Cannings's avatar Rich Cannings Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Make a copy of data stored in LockSettingsStorage cache" into pi-dev

parents 157f05eb 567f2357
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
@@ -49,6 +48,7 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@@ -808,7 +808,7 @@ class LockSettingsStorage {
        }

        byte[] peekFile(String fileName) {
            return (byte[]) peek(CacheKey.TYPE_FILE, fileName, -1 /* userId */);
            return copyOf((byte[]) peek(CacheKey.TYPE_FILE, fileName, -1 /* userId */));
        }

        boolean hasFile(String fileName) {
@@ -816,11 +816,11 @@ class LockSettingsStorage {
        }

        void putFile(String key, byte[] value) {
            put(CacheKey.TYPE_FILE, key, value, -1 /* userId */);
            put(CacheKey.TYPE_FILE, key, copyOf(value), -1 /* userId */);
        }

        void putFileIfUnchanged(String key, byte[] value, int version) {
            putIfUnchanged(CacheKey.TYPE_FILE, key, value, -1 /* userId */, version);
            putIfUnchanged(CacheKey.TYPE_FILE, key, copyOf(value), -1 /* userId */, version);
        }

        void setFetched(int userId) {
@@ -868,6 +868,10 @@ class LockSettingsStorage {
            mVersion++;
        }

        private byte[] copyOf(byte[] data) {
            return data != null ? Arrays.copyOf(data, data.length) : null;
        }

        synchronized void purgePath(String path) {
            for (int i = mCache.size() - 1; i >= 0; i--) {
                CacheKey entry = mCache.keyAt(i);