From e4aed348657f717df1968904285f5e93772c5000 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 18 May 2014 10:44:40 -0700 Subject: Do synchronized setOnline logic in events thread --- src/github/daneren2005/dsub/service/DownloadService.java | 15 ++++++++++++--- .../dsub/service/DownloadServiceLifecycleSupport.java | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 6c3b2e24..e1891a6d 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -524,14 +524,23 @@ public class DownloadService extends Service { updateJukeboxPlaylist(); } - public synchronized void setOnline(boolean online) { + public void setOnline(final boolean online) { if(online) { mediaRouter.addOfflineProviders(); - checkDownloads(); } else { mediaRouter.removeOfflineProviders(); - clearIncomplete(); } + + lifecycleSupport.post(new Runnable() { + @Override + public void run() { + if(online) { + checkDownloads(); + } else { + clearIncomplete(); + } + } + }); } public synchronized int size() { diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 5e8b0f8b..db69517c 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -261,6 +261,10 @@ public class DownloadServiceLifecycleSupport { FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); } + public void post(Runnable runnable) { + eventHandler.post(runnable); + } + private void deserializeDownloadQueueNow() { State state = FileUtil.deserialize(downloadService, FILENAME_DOWNLOADS_SER, State.class); if (state == null) { -- cgit v1.2.3