diff --git a/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java b/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java index ab798de11..127445e52 100644 --- a/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java +++ b/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java @@ -66,20 +66,20 @@ public class InstallManagerService extends Service { * matching the {@link App}s in {@code ACTIVE_APPS}. The key is the download URL, as * in {@link Apk#getUrl()} or {@code urlString}. */ - private static final HashMap ACTIVE_APKS = new HashMap(3); + private static final HashMap ACTIVE_APKS = new HashMap<>(3); /** * The collection of {@link App}s that are actively going through this whole process, * matching the {@link Apk}s in {@code ACTIVE_APKS}. The key is the * {@code packageName} of the app. */ - private static final HashMap ACTIVE_APPS = new HashMap(3); + private static final HashMap ACTIVE_APPS = new HashMap<>(3); /** * The array of active {@link BroadcastReceiver}s for each active APK. The key is the * download URL, as in {@link Apk#getUrl()} or {@code urlString}. */ - private final HashMap receivers = new HashMap(3); + private final HashMap receivers = new HashMap<>(3); /** * Get the app name based on a {@code urlString} key. The app name needs @@ -91,7 +91,7 @@ public class InstallManagerService extends Service { *

* TODO delete me once InstallerService exists */ - private static final HashMap TEMP_HACK_APP_NAMES = new HashMap(3); + private static final HashMap TEMP_HACK_APP_NAMES = new HashMap<>(3); private LocalBroadcastManager localBroadcastManager; private NotificationManager notificationManager; diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index a85d311ab..8dc833d29 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -30,6 +30,7 @@ import android.os.Looper; import android.os.Message; import android.os.PatternMatcher; import android.os.Process; +import android.support.v4.content.IntentCompat; import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; import android.util.Log; @@ -109,14 +110,14 @@ public class DownloaderService extends Service { } @Override - public void onStart(Intent intent, int startId) { - super.onStart(intent, startId); + public int onStartCommand(Intent intent, int flags, int startId) { Utils.debugLog(TAG, "Received Intent for downloading: " + intent + " (with a startId of " + startId + ")"); String uriString = intent.getDataString(); if (uriString == null) { Log.e(TAG, "Received Intent with no URI: " + intent); - return; + return START_STICKY; } + if (ACTION_CANCEL.equals(intent.getAction())) { Utils.debugLog(TAG, "Cancelling download of " + uriString); Integer whatToRemove = uriString.hashCode(); @@ -139,26 +140,21 @@ public class DownloaderService extends Service { } else { Log.e(TAG, "Received Intent with unknown action: " + intent); } + + return START_REDELIVER_INTENT; // if killed before completion, retry Intent } public static PendingIntent getCancelPendingIntent(Context context, String urlString) { Intent cancelIntent = new Intent(context.getApplicationContext(), DownloaderService.class) .setData(Uri.parse(urlString)) .setAction(ACTION_CANCEL) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK); return PendingIntent.getService(context.getApplicationContext(), urlString.hashCode(), cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT); } - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - Utils.debugLog(TAG, "onStartCommand " + intent); - onStart(intent, startId); - return START_REDELIVER_INTENT; // if killed before completion, retry Intent - } - @Override public void onDestroy() { Utils.debugLog(TAG, "Destroying downloader service. Will move to background and stop our Looper.");