Bug 1322029 - Put process name into Android crash reports. r=jchen, a=lizzard
authorJames Willcox <snorp@snorp.net>
Thu, 02 Feb 2017 12:54:35 -0600
changeset 376095 b11f70bc7607c2c0c53f50e9a9b1e6fcedb60017
parent 376094 739dac1dbd6ad4d93e70bf81956446812092ab58
child 376096 e4e388730c788910fa60c5470705b436a88bb805
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, lizzard
bugs1322029
milestone53.0a2
Bug 1322029 - Put process name into Android crash reports. r=jchen, a=lizzard
mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/CrashHandler.java
@@ -174,39 +174,46 @@ public class CrashHandler implements Thr
         }
         return uptimeMins / 1000;
     }
 
     private static String getJavaPackageName() {
         return CrashHandler.class.getPackage().getName();
     }
 
-    protected String getAppPackageName() {
-        final Context context = getAppContext();
-
-        if (context != null) {
-            return context.getPackageName();
-        }
-
+    private static String getProcessName() {
         try {
-            // Package name is also the command line string in most cases.
             final FileReader reader = new FileReader("/proc/self/cmdline");
             final char[] buffer = new char[64];
             try {
                 if (reader.read(buffer) > 0) {
                     // cmdline is delimited by '\0', and we want the first token.
                     final int nul = Arrays.asList(buffer).indexOf('\0');
                     return (new String(buffer, 0, nul < 0 ? buffer.length : nul)).trim();
                 }
             } finally {
                 reader.close();
             }
+        } catch (final IOException e) {
+        }
 
-        } catch (final IOException e) {
-            Log.i(LOGTAG, "Error reading package name", e);
+        return null;
+    }
+
+    protected String getAppPackageName() {
+        final Context context = getAppContext();
+
+        if (context != null) {
+            return context.getPackageName();
+        }
+
+        // Package name is also the process name in most cases.
+        String processName = getProcessName();
+        if (processName != null) {
+            return processName;
         }
 
         // Fallback to using CrashHandler's package name.
         return getJavaPackageName();
     }
 
     protected Context getAppContext() {
         return appContext;
@@ -218,20 +225,22 @@ public class CrashHandler implements Thr
      * @param thread The exception thread
      * @param exc An exception
      * @return "Extras" in the from of a Bundle
      */
     protected Bundle getCrashExtras(final Thread thread, final Throwable exc) {
         final Context context = getAppContext();
         final Bundle extras = new Bundle();
         final String pkgName = getAppPackageName();
+        final String processName = getProcessName();
 
         extras.putString("ProductName", pkgName);
         extras.putLong("CrashTime", getCrashTime());
         extras.putLong("StartupTime", getStartupTime());
+        extras.putString("AndroidProcessName", getProcessName());
 
         if (context != null) {
             final PackageManager pkgMgr = context.getPackageManager();
             try {
                 final PackageInfo pkgInfo = pkgMgr.getPackageInfo(pkgName, 0);
                 extras.putString("Version", pkgInfo.versionName);
                 extras.putInt("BuildID", pkgInfo.versionCode);
                 extras.putLong("InstallTime", pkgInfo.lastUpdateTime / 1000);