Bug 1322029 - Put process name into Android crash reports r=jchen

This commit is contained in:
James Willcox 2017-02-02 12:54:35 -06:00
Родитель f37c8b3419
Коммит 8c58183633
1 изменённых файлов: 19 добавлений и 10 удалений

Просмотреть файл

@ -179,15 +179,8 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
return CrashHandler.class.getPackage().getName(); return CrashHandler.class.getPackage().getName();
} }
protected String getAppPackageName() { private static String getProcessName() {
final Context context = getAppContext();
if (context != null) {
return context.getPackageName();
}
try { try {
// Package name is also the command line string in most cases.
final FileReader reader = new FileReader("/proc/self/cmdline"); final FileReader reader = new FileReader("/proc/self/cmdline");
final char[] buffer = new char[64]; final char[] buffer = new char[64];
try { try {
@ -199,9 +192,23 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
} finally { } finally {
reader.close(); 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. // Fallback to using CrashHandler's package name.
@ -223,10 +230,12 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
final Context context = getAppContext(); final Context context = getAppContext();
final Bundle extras = new Bundle(); final Bundle extras = new Bundle();
final String pkgName = getAppPackageName(); final String pkgName = getAppPackageName();
final String processName = getProcessName();
extras.putString("ProductName", pkgName); extras.putString("ProductName", pkgName);
extras.putLong("CrashTime", getCrashTime()); extras.putLong("CrashTime", getCrashTime());
extras.putLong("StartupTime", getStartupTime()); extras.putLong("StartupTime", getStartupTime());
extras.putString("AndroidProcessName", getProcessName());
if (context != null) { if (context != null) {
final PackageManager pkgMgr = context.getPackageManager(); final PackageManager pkgMgr = context.getPackageManager();