From e7b1b067bb484cd3e15db2e4c2b6846b65505f9a Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 2 Nov 2015 22:57:24 +0100 Subject: [PATCH] Added method to send crash report --- .../main/java/eu/faircode/netguard/Util.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/src/main/java/eu/faircode/netguard/Util.java b/app/src/main/java/eu/faircode/netguard/Util.java index 8fc4d00c..59ac15ca 100644 --- a/app/src/main/java/eu/faircode/netguard/Util.java +++ b/app/src/main/java/eu/faircode/netguard/Util.java @@ -1,5 +1,6 @@ package eu.faircode.netguard; +import android.app.ApplicationErrorReport; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; @@ -22,6 +23,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringWriter; import java.security.MessageDigest; import java.util.Set; @@ -106,6 +109,36 @@ public class Util { } } + public static void sendCrashReport(Throwable ex, Context context) { + 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(); + + StringWriter writer = new StringWriter(); + PrintWriter printer = new PrintWriter(writer); + ex.printStackTrace(printer); + + 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(); + + report.crashInfo = crash; + + Intent intent = new Intent(Intent.ACTION_APP_ERROR); + intent.putExtra(Intent.EXTRA_BUG_REPORT, report); + context.startActivity(intent); + } + public static void sendLogcat(final String tag, final Context context) { AsyncTask task = new AsyncTask() { @Override