Bug 1561245 - Add a null check for the received Intent; r=VladBaicu, a=jcristau
authorPetru Lingurar <petru.lingurar@softvision.ro>
Tue, 25 Jun 2019 14:52:48 +0000
changeset 537089 7d0117af32b0b354696f1510a772c2e43d338968
parent 537088 e2c7cdfea423496e97071cd8791cc5d9f060e22c
child 537090 a9beb454bd6cfd5bb1045d5d255e07bc54acd5d2
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu, jcristau
bugs1561245
milestone68.0
Bug 1561245 - Add a null check for the received Intent; r=VladBaicu, a=jcristau 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
mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java
--- a/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java
@@ -3,32 +3,37 @@ package org.mozilla.gecko;
 import android.annotation.TargetApi;
 import android.app.Notification;
 import android.app.PendingIntent;
 import android.app.Service;
 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;
 
 import java.io.File;
 import java.io.IOException;
 
 public class CrashHandlerService extends Service {
     private static final String LOGTAG = "CrashHandlerService";
     private static final String ACTION_STOP = "action_stop";
     // Build.VERSION_CODES.Q placeholder. While Android Q is in Beta it shares API 28 with Android P.
     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.
             try {
                 File crashFlag = new File(GeckoProfileDirectories.getMozillaDirectory(this), "CRASHED");
                 crashFlag.createNewFile();
             } catch (GeckoProfileDirectories.NoMozillaDirectoryException | IOException e) {
                 Log.e(LOGTAG, "Cannot set crash flag: ", e);