From 00a7ec139a8e10d08f438365478a2e6c84a5c593 Mon Sep 17 00:00:00 2001 From: Petru Lingurar Date: Tue, 25 Jun 2019 14:52:48 +0000 Subject: [PATCH] Bug 1561245 - Add a null check for the received Intent; r=VladBaicu According to the documentation - https://developer.android.com/reference/android/app/Service.html "The Intent supplied to Context.startService(Intent) may be null if the service is being restarted after its process has gone away, and it had previously returned anything except START_STICKY_COMPATIBILITY." We will ignore the case when the system restarts our Service as we only expect it to be properly started by us, in the event of a crash. Differential Revision: https://phabricator.services.mozilla.com/D35790 --HG-- extra : moz-landing-system : lando --- .../base/java/org/mozilla/gecko/CrashHandlerService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java b/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java index fc7c0e3817bb..12300ee77f9f 100644 --- a/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java +++ b/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.provider.Settings; +import android.support.annotation.Nullable; import android.util.Log; import org.mozilla.gecko.notifications.NotificationHelper; @@ -22,8 +23,12 @@ public class CrashHandlerService extends Service { private static final int ANDROID_Q = 29; @Override - public int onStartCommand(Intent intent, int flags, int startId) { - if (ACTION_STOP.equals(intent.getAction())) { + public int onStartCommand(@Nullable Intent intent, int flags, int startId) { + if (intent == null) { + // no-op + // The Intent may be null if the service is being restarted after its process has gone away, + // and it had previously returned anything except START_STICKY_COMPATIBILITY. + } else if (ACTION_STOP.equals(intent.getAction())) { dismissNotification(); } else { // Notify GeckoApp that we've crashed, so it can react appropriately during the next start.