Bug 1501449 - Terminate the JVM immediately after CrashReporterService finishes to prevent ANR. r=rbarker, a=pascalc FENNEC_63_0_2_BUILD1 FENNEC_63_0_2_RELEASE
authorPetru Lingurar <petru.lingurar@softvision.ro>
Fri, 26 Oct 2018 14:18:40 +0000
changeset 492975 805f775f35e2
parent 492974 3acb6478c0ab
child 492976 3366ed045ba1
push id1844
push userryanvm@gmail.com
push dateMon, 05 Nov 2018 15:21:08 +0000
treeherdermozilla-release@805f775f35e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker, pascalc
bugs1501449
milestone63.0.2
Bug 1501449 - Terminate the JVM immediately after CrashReporterService finishes to prevent ANR. r=rbarker, a=pascalc This service is started as a foreground service. But because it does little work it doesn't post a Notification to bug the user unneededly. Although all it's work is done in < 5 seconds, after them passing the ActivityManager will post an ANR error to logcat because we aren't calling Service.startForeground() and actually posting a Notification. Although nothing gets through to the user this errors are registered in the Google Play console. To prevent them we terminate the currently running JVM immedately after CrashReporterService's work is completed, which is under those ~5 seconds. The call for this is put into onUnbind() because in my tests if that call is put at the end of onHandleWork() the JVM would be shutdown before the JobScheduler would have had the chance to unbind and so after some time the service would be binded again, and onHandleWork would be executed again. onUbind() is called immediately after onHandleWork() finishes, after JobScheduler unbinds, so this seems the earliest possible moment to terminate. Differential Revision: https://phabricator.services.mozilla.com/D9919
mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashReporterService.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashReporterService.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashReporterService.java
@@ -72,16 +72,22 @@ public class CrashReporterService extend
             startActivity(intent);
             return;
         }
 
         submitCrash(intent);
     }
 
     @Override
+    public boolean onUnbind(Intent intent) {
+        shutdown();
+        return false;
+    }
+
+    @Override
     public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
         // When running on pre-O devices the work will be dispatched to onHandleWork() automatically
         // When running on Oreo and later devices we will enqueue the work for the JobIntentService to perform
         if (Build.VERSION.SDK_INT >= 26) {
             // Only when the system restarts the service because of Service.START_STICKY
             // the intent will be null. So the intent is safe to be passed to the JobIntentService.
             enqueueWork(this, intent);
         }
@@ -433,9 +439,23 @@ public class CrashReporterService extend
                 conn.disconnect();
             }
         }
     }
 
     private String unescape(String string) {
         return string.replaceAll("\\\\\\\\", "\\").replaceAll("\\\\n", "\n").replaceAll("\\\\t", "\t");
     }
+
+    /**
+     * Terminate the currently running Java Virtual Machine.
+     *
+     * This service is started as a foreground service.
+     * But because it does little work it doesn't post a Notification to bug the user unneededly.
+     * Although all it's work is done in < 5 seconds, after them passing the ActivityManager will post
+     * an ANR error to logcat because we aren't calling Service.startForeground().
+     * Although nothing gets through to the user this errors are registered in the Google Play console.
+     * See bug 1501449.
+     */
+    private void shutdown() {
+        System.exit(0);
+    }
 }