Prevent bug reporting from crashing NetGuard

This commit is contained in:
M66B 2015-11-23 10:58:22 +01:00
parent 84df549beb
commit ac637888e5
1 changed files with 29 additions and 25 deletions

View File

@ -146,37 +146,41 @@ public class Util {
}
public static void sendCrashReport(Throwable ex, final Context context) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = context.getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
report.systemApp = false;
try {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = context.getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
report.systemApp = false;
ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
crash.exceptionClassName = ex.getClass().getSimpleName();
crash.exceptionMessage = ex.getMessage();
ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
crash.exceptionClassName = ex.getClass().getSimpleName();
crash.exceptionMessage = ex.getMessage();
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
ex.printStackTrace(printer);
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
ex.printStackTrace(printer);
crash.stackTrace = writer.toString();
crash.stackTrace = writer.toString();
StackTraceElement stack = ex.getStackTrace()[0];
crash.throwClassName = stack.getClassName();
crash.throwFileName = stack.getFileName();
crash.throwLineNumber = stack.getLineNumber();
crash.throwMethodName = stack.getMethodName();
StackTraceElement stack = ex.getStackTrace()[0];
crash.throwClassName = stack.getClassName();
crash.throwFileName = stack.getFileName();
crash.throwLineNumber = stack.getLineNumber();
crash.throwMethodName = stack.getMethodName();
report.crashInfo = crash;
report.crashInfo = crash;
final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (bug.resolveActivity(context.getPackageManager()) == null)
sendLogcat(ex.toString() + "\n" + Log.getStackTraceString(ex), context);
else
context.startActivity(bug);
final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (bug.resolveActivity(context.getPackageManager()) == null)
sendLogcat(ex.toString() + "\n" + Log.getStackTraceString(ex), context);
else
context.startActivity(bug);
} catch (Throwable exex) {
Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
}
}
public static void sendLogcat(final String message, final Context context) {