From c862eb0bd3a0bead563f7a52b1a0ca61967f11d9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 18 May 2016 20:03:08 +0200 Subject: [PATCH] safely handle nulls that start InstallManagerService For some odd reason, something is sending a URL to be downloaded that then results in a null Apk instance. My first guess was because it was being canceled, but the interrupted receiver is not even registered yet. My second thought is that something is sending a download and cancel Intent at the same time. In any case, its something to keep in mind when reworking InstallManagerService once InstallerService comes along. closes #660 https://gitlab.com/fdroid/fdroidclient/issues/660 --- .../fdroid/installer/InstallManagerService.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 4c65692e0..322f8ab0e 100644 --- a/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java +++ b/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java @@ -15,7 +15,7 @@ import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; -import android.util.Log; +import android.widget.Toast; import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.R; @@ -135,12 +135,23 @@ public class InstallManagerService extends Service { Utils.debugLog(TAG, "onStartCommand " + intent); if (!ACTION_INSTALL.equals(intent.getAction())) { - Log.i(TAG, "Ignoring " + intent + " as it is not an " + ACTION_INSTALL + " intent"); + Utils.debugLog(TAG, "Ignoring " + intent + " as it is not an " + ACTION_INSTALL + " intent"); return START_NOT_STICKY; } String urlString = intent.getDataString(); + if (TextUtils.isEmpty(urlString)) { + Utils.debugLog(TAG, "empty urlString, nothing to do"); + return START_NOT_STICKY; + } + Apk apk = ACTIVE_APKS.get(urlString); + if (apk == null) { + Utils.debugLog(TAG, urlString + " is not in ACTIVE_APKS, why are we trying to download it?"); + Toast.makeText(this, urlString + " failed with an imcomplete download request!", + Toast.LENGTH_LONG).show(); + return START_NOT_STICKY; + } Notification notification = createNotification(intent.getDataString(), apk).build(); notificationManager.notify(urlString.hashCode(), notification);