Merge pull request #5705 from ByteHamster/shutdown-download-service

Shutdown download executors properly
This commit is contained in:
ByteHamster 2022-02-08 22:25:15 +01:00 committed by GitHub
commit a61c8567f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Binder;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.text.TextUtils; import android.text.TextUtils;
@ -88,18 +87,11 @@ public class DownloadService extends Service {
private ScheduledFuture<?> downloadPostFuture; private ScheduledFuture<?> downloadPostFuture;
private final ScheduledThreadPoolExecutor notificationUpdateExecutor; private final ScheduledThreadPoolExecutor notificationUpdateExecutor;
private static DownloaderFactory downloaderFactory = new DefaultDownloaderFactory(); private static DownloaderFactory downloaderFactory = new DefaultDownloaderFactory();
private final IBinder binder = new LocalBinder();
private ConnectionStateMonitor connectionMonitor; private ConnectionStateMonitor connectionMonitor;
private class LocalBinder extends Binder {
public DownloadService getService() {
return DownloadService.this;
}
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return binder; return null;
} }
public DownloadService() { public DownloadService() {
@ -264,9 +256,9 @@ public class DownloadService extends Service {
EventBus.getDefault().postSticky(DownloadEvent.refresh(Collections.emptyList())); EventBus.getDefault().postSticky(DownloadEvent.refresh(Collections.emptyList()));
cancelNotificationUpdater(); cancelNotificationUpdater();
downloadHandleExecutor.shutdown(); downloadEnqueueExecutor.shutdownNow();
downloadEnqueueExecutor.shutdown(); downloadHandleExecutor.shutdownNow();
notificationUpdateExecutor.shutdown(); notificationUpdateExecutor.shutdownNow();
if (downloadPostFuture != null) { if (downloadPostFuture != null) {
downloadPostFuture.cancel(true); downloadPostFuture.cancel(true);
} }
@ -401,6 +393,9 @@ public class DownloadService extends Service {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.d(TAG, "cancelDownloadReceiver: " + intent.getAction()); Log.d(TAG, "cancelDownloadReceiver: " + intent.getAction());
if (!isRunning) {
return;
}
if (TextUtils.equals(intent.getAction(), ACTION_CANCEL_DOWNLOAD)) { if (TextUtils.equals(intent.getAction(), ACTION_CANCEL_DOWNLOAD)) {
String url = intent.getStringExtra(EXTRA_DOWNLOAD_URL); String url = intent.getStringExtra(EXTRA_DOWNLOAD_URL);
if (url == null) { if (url == null) {