diff --git a/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java b/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java index 1f817f03e..cea679d9f 100644 --- a/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java +++ b/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java @@ -47,6 +47,9 @@ public class CleanCacheService extends IntentService { @Override protected void onHandleIntent(Intent intent) { + if (intent == null) { + return; + } Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); Utils.clearOldFiles(Utils.getApkCacheDir(this), Preferences.get().getKeepCacheTime()); deleteStrayIndexFiles(); diff --git a/app/src/main/java/org/fdroid/fdroid/UpdateService.java b/app/src/main/java/org/fdroid/fdroid/UpdateService.java index bfe7f1ff8..be0565afa 100644 --- a/app/src/main/java/org/fdroid/fdroid/UpdateService.java +++ b/app/src/main/java/org/fdroid/fdroid/UpdateService.java @@ -313,8 +313,12 @@ public class UpdateService extends IntentService { Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); final long startTime = System.currentTimeMillis(); - String address = intent.getStringExtra(EXTRA_ADDRESS); - boolean manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false); + boolean manualUpdate = false; + String address = null; + if (intent != null) { + address = intent.getStringExtra(EXTRA_ADDRESS); + manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false); + } try { // See if it's time to actually do anything yet... 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 8dc833d29..d3e7e6e90 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -33,7 +33,6 @@ import android.os.Process; import android.support.v4.content.IntentCompat; import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; -import android.util.Log; import org.fdroid.fdroid.ProgressListener; import org.fdroid.fdroid.Utils; @@ -46,9 +45,14 @@ import java.net.URL; /** * DownloaderService is a service that handles asynchronous download requests * (expressed as {@link Intent}s) on demand. Clients send download requests - * through {@link android.content.Context#startService(Intent)} calls; the - * service is started as needed, handles each Intent in turn using a worker - * thread, and stops itself when it runs out of work. + * through {@link #queue(Context, String)} calls. The + * service is started as needed, it handles each {@code Intent} using a worker + * thread, and stops itself when it runs out of work. Requests can be canceled + * using {@link #cancel(Context, String)}. If this service is killed during + * operation, it will receive the queued {@link #queue(Context, String)} and + * {@link #cancel(Context, String)} requests again due to + * {@link Service#START_REDELIVER_INTENT}. Bad requests will be ignored, + * including on restart after killing via {@link Service#START_NOT_STICKY}. *

* This "work queue processor" pattern is commonly used to offload tasks * from an application's main thread. The DownloaderService class exists to @@ -112,10 +116,15 @@ public class DownloaderService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { Utils.debugLog(TAG, "Received Intent for downloading: " + intent + " (with a startId of " + startId + ")"); + + if (intent == null) { + return START_NOT_STICKY; + } + String uriString = intent.getDataString(); if (uriString == null) { - Log.e(TAG, "Received Intent with no URI: " + intent); - return START_STICKY; + Utils.debugLog(TAG, "Received Intent with no URI: " + intent); + return START_NOT_STICKY; } if (ACTION_CANCEL.equals(intent.getAction())) { @@ -128,7 +137,7 @@ public class DownloaderService extends Service { } else if (isActive(uriString)) { downloader.cancelDownload(); } else { - Log.e(TAG, "ACTION_CANCEL called on something not queued or running (expected to find message with ID of " + whatToRemove + " in queue)."); + Utils.debugLog(TAG, "ACTION_CANCEL called on something not queued or running (expected to find message with ID of " + whatToRemove + " in queue)."); } } else if (ACTION_QUEUE.equals(intent.getAction())) { Message msg = serviceHandler.obtainMessage(); @@ -138,7 +147,7 @@ public class DownloaderService extends Service { serviceHandler.sendMessage(msg); Utils.debugLog(TAG, "Queued download of " + uriString); } else { - Log.e(TAG, "Received Intent with unknown action: " + intent); + Utils.debugLog(TAG, "Received Intent with unknown action: " + intent); } return START_REDELIVER_INTENT; // if killed before completion, retry Intent diff --git a/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java b/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java index 3bf597d8f..69a41761d 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -56,6 +56,10 @@ public class WifiStateChangeService extends IntentService { @Override protected void onHandleIntent(Intent intent) { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST); + if (intent == null) { + Utils.debugLog(TAG, "received null Intent, ignoring"); + return; + } Utils.debugLog(TAG, "WiFi change service started, clearing info about wifi state until we have figured it out again."); NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); @@ -188,7 +192,11 @@ public class WifiStateChangeService extends IntentService { private void setIpInfoFromNetworkInterface() { try { - for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements();) { + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + if (networkInterfaces == null) { + return; + } + while (networkInterfaces.hasMoreElements()) { NetworkInterface netIf = networkInterfaces.nextElement(); for (Enumeration inetAddresses = netIf.getInetAddresses(); inetAddresses.hasMoreElements();) {