Using persisted item storage for install queue.

Shared prefs are loaded during startup and should avoid large objects

Change-Id: Ibb5c8307dbccb9414b42454825e6c3c2a972efa6
This commit is contained in:
Sunny Goyal
2020-08-12 14:38:23 -07:00
parent a92c26b161
commit 104c9d1206
3 changed files with 74 additions and 148 deletions

View File

@@ -68,8 +68,7 @@ public class PersistedItemArray<T extends ItemInfo> {
*/
@WorkerThread
public void write(Context context, List<T> items) {
AtomicFile file = new AtomicFile(context.getFileStreamPath(mFileName));
AtomicFile file = getFile(context);
FileOutputStream fos;
try {
fos = file.startWrite();
@@ -124,9 +123,7 @@ public class PersistedItemArray<T extends ItemInfo> {
@WorkerThread
public List<T> read(Context context, ItemFactory<T> factory, LongFunction<UserHandle> userFn) {
List<T> result = new ArrayList<>();
AtomicFile file = new AtomicFile(context.getFileStreamPath(mFileName));
try (FileInputStream fis = file.openRead()) {
try (FileInputStream fis = getFile(context).openRead()) {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new InputStreamReader(fis, StandardCharsets.UTF_8));
@@ -166,6 +163,13 @@ public class PersistedItemArray<T extends ItemInfo> {
return result;
}
/**
* Returns the underlying file used for persisting data
*/
public AtomicFile getFile(Context context) {
return new AtomicFile(context.getFileStreamPath(mFileName));
}
/**
* Interface to create an ItemInfo during parsing
*/