From 556f043b68b6b19091fe3057cfd42b13dc961365 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 6 Mar 2014 16:00:13 -0800 Subject: #168 Get rid of check thread, instead cover all cases that might need to update --- .../daneren2005/dsub/service/DownloadService.java | 8 +++++++- .../dsub/service/DownloadServiceLifecycleSupport.java | 18 ------------------ 2 files changed, 7 insertions(+), 19 deletions(-) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index a5d687ee..79094024 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -165,7 +165,6 @@ public class DownloadService extends Service { } }); audioSessionId = mediaPlayer.getAudioSessionId(); - Log.d(TAG, "id: " + audioSessionId); try { Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); @@ -520,6 +519,7 @@ public class DownloadService extends Service { public synchronized void setOnline(boolean online) { if(online) { mediaRouter.addOfflineProviders(); + checkDownloads(); } else { mediaRouter.removeOfflineProviders(); clearIncomplete(); @@ -781,6 +781,7 @@ public class DownloadService extends Service { proxy.stop(); proxy = null; } + checkDownloads(); } /** Plays or resumes the playback, depending on the current player state. */ @@ -1169,6 +1170,10 @@ public class DownloadService extends Service { Util.hidePlayingNotification(this, this, handler); } + if(remoteState == RemoteControlState.LOCAL) { + checkDownloads(); + } + if(routeId != null) { handler.post(new Runnable() { @Override @@ -1402,6 +1407,7 @@ public class DownloadService extends Service { bufferTask.start(); } } + checkDownloads(); } } }); diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 0194de82..37eaae62 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -21,8 +21,6 @@ package github.daneren2005.dsub.service; import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.atomic.AtomicBoolean; @@ -57,7 +55,6 @@ public class DownloadServiceLifecycleSupport { private final DownloadService downloadService; private Looper eventLooper; private Handler eventHandler; - private ScheduledExecutorService executorService; private BroadcastReceiver headsetEventReceiver; private BroadcastReceiver ejectEventReceiver; private PhoneStateListener phoneStateListener; @@ -102,20 +99,6 @@ public class DownloadServiceLifecycleSupport { } public void onCreate() { - Runnable downloadChecker = new Runnable() { - @Override - public void run() { - try { - downloadService.checkDownloads(); - } catch (Throwable x) { - Log.e(TAG, "checkDownloads() failed.", x); - } - } - }; - - executorService = Executors.newSingleThreadScheduledExecutor(); - executorService.scheduleWithFixedDelay(downloadChecker, 5, 5, TimeUnit.SECONDS); - new Thread(new Runnable() { @Override public void run() { @@ -225,7 +208,6 @@ public class DownloadServiceLifecycleSupport { } public void onDestroy() { - executorService.shutdown(); eventLooper.quit(); serializeDownloadQueueNow(); downloadService.unregisterReceiver(ejectEventReceiver); -- cgit v1.2.3