1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2024-12-24 08:45:53 +00:00

Added method to send crash report

This commit is contained in:
M66B 2015-11-02 22:57:24 +01:00
parent 212f2f84d2
commit e7b1b067bb

View file

@ -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<Object, Object, Intent>() {
@Override