Bug 1561245 - Add a null check for the received Intent; r=VladBaicu
authorPetru Lingurar <petru.lingurar@softvision.ro>
Tue, 25 Jun 2019 14:52:48 +0000
changeset 542880 cd51e03eae41569182609d970dafaf6eb62b6f2e
parent 542879 fae033f2ab2dcdfb193d634c8d901ea7532bca3b
child 542881 53b89d516cbce0085e231c9c981fb0cf3747eef1
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu
bugs1561245
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
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);