Only modify and query downloads array in main thread

This fixes a ConcurrentModificationException if the thread that queues downloads (database IO)
adds the item to the downloads list and the notification updater queries the downloads list at
the same time.
This commit is contained in:
ByteHamster 2020-01-03 22:50:27 +01:00
parent 29a8a5e5aa
commit 3e8c1ee117

View File

@ -477,13 +477,13 @@ public class DownloadService extends Service {
&& isEnqueued(request, itemsEnqueued)) {
request.setMediaEnqueued(true);
}
downloads.add(downloader);
downloadExecutor.submit(downloader);
postDownloaders();
handler.post(() -> {
downloads.add(downloader);
downloadExecutor.submit(downloader);
postDownloaders();
});
}
queryDownloads();
handler.post(this::queryDownloads);
}
private static boolean isEnqueued(@NonNull DownloadRequest request,