Bug 1550291 - Ensure we save CRASHED status to be able to restore previous tabs; r=AndreiLazar, a=RyanVM, l10n=flod
authorPetru Lingurar <petru.lingurar@softvision.ro>
Thu, 13 Jun 2019 13:26:57 +0000
changeset 536942 9ac627048305775d78799ea022d269d18d593262
parent 536941 22cfa63e856377c0b7f502d194d4b17dc0c3acc9
child 536943 abf322efc723897624040ad5e48519845b821bd1
child 536959 f1c2cfb45429b1fe877e7c84bf69aeb4b06c51b7
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)
reviewersAndreiLazar, RyanVM
bugs1550291
milestone68.0
Bug 1550291 - Ensure we save CRASHED status to be able to restore previous tabs; r=AndreiLazar, a=RyanVM, l10n=flod Default app behavior for when a crash occurs involves starting an Activity that lets users submit a crash report and maybe provide additional info. In the event of a crash we want to restore for the user all previous tabs, this Activity being the component that saves the CRASHED status that will trigger the restore process. On Android Q, when a crash notification is posted but ignored by the user, upon starting the app would not know it crashed and it would not try restoring tabs. Executing the "save CRASHED status" logic whenever a crash occurs, irrespective of if we'll show the Activity or just post a notification ensures users will always have their previous tabs restored. Differential Revision: https://phabricator.services.mozilla.com/D34826
mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java
mobile/android/base/java/org/mozilla/gecko/CrashReporterActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/CrashHandlerService.java
@@ -3,29 +3,42 @@ 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.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())) {
             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);
+            }
+
             intent.setClass(this, CrashReporterActivity.class);
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
             if (AppConstants.Versions.feature29Plus) {
                 startCrashHandling(intent);
             } else {
                 startActivity(intent);
 
--- a/mobile/android/base/java/org/mozilla/gecko/CrashReporterActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/CrashReporterActivity.java
@@ -199,24 +199,16 @@ public class CrashReporterActivity exten
                     new TelemetryCrashPingBuilder(crashId, clientId, mExtrasStringMap);
                 final TelemetryDispatcher dispatcher = new TelemetryDispatcher(profileDir.getPath(), profileName);
                 dispatcher.queuePingForUpload(this, pingBuilder);
             }
         } catch (GeckoProfileDirectories.NoMozillaDirectoryException | IOException e) {
             Log.e(LOGTAG, "Cannot send the crash ping: ", e);
         }
 
-        // 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);
-        }
-
         final CheckBox allowContactCheckBox = (CheckBox) findViewById(R.id.allow_contact);
         final CheckBox includeUrlCheckBox = (CheckBox) findViewById(R.id.include_url);
         final CheckBox sendReportCheckBox = (CheckBox) findViewById(R.id.send_report);
         final EditText commentsEditText = (EditText) findViewById(R.id.comment);
         final EditText emailEditText = (EditText) findViewById(R.id.email);
 
         // Load CrashReporterActivity preferences to avoid redundant user input.
         SharedPreferences prefs = GeckoSharedPrefs.forCrashReporter(this);