Return a copy of the downloads.

This should prevent any IndexOutOfBounds errors

fixes AntennaPod/AntennaPod#968
This commit is contained in:
Tom Hennen 2015-06-27 09:25:24 -04:00
parent e332df4af5
commit d4fb1b0968
1 changed files with 5 additions and 2 deletions

View File

@ -243,7 +243,7 @@ public class DownloadService extends Service {
handler = new Handler();
newMediaFiles = Collections.synchronizedList(new ArrayList<Long>());
reportQueue = Collections.synchronizedList(new ArrayList<DownloadStatus>());
downloads = new ArrayList<Downloader>();
downloads = Collections.synchronizedList(new ArrayList<Downloader>());
numberOfDownloads = new AtomicInteger(0);
IntentFilter cancelDownloadReceiverFilter = new IntentFilter();
@ -1246,7 +1246,10 @@ public class DownloadService extends Service {
}
public List<Downloader> getDownloads() {
return downloads;
// return a copy of downloads, but the copy doesn't need to be synchronized.
synchronized (downloads) {
return new ArrayList<Downloader>(downloads);
}
}
}