From af2cddee9120cd09d91f6fabdfab159ad5e65cb8 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 13 Sep 2016 23:24:49 +0200 Subject: [PATCH] made acra catch and report errors --- .../org/schabi/newpipe/AcraReportSender.java | 11 +++------- .../org/schabi/newpipe/ErrorActivity.java | 22 +++++++++++++++++++ .../java/org/schabi/newpipe/MainActivity.java | 2 ++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/AcraReportSender.java b/app/src/main/java/org/schabi/newpipe/AcraReportSender.java index 66bd17e1e..b86e056f7 100644 --- a/app/src/main/java/org/schabi/newpipe/AcraReportSender.java +++ b/app/src/main/java/org/schabi/newpipe/AcraReportSender.java @@ -31,13 +31,8 @@ public class AcraReportSender implements ReportSender { @Override public void send(Context context, CrashReportData report) throws ReportSenderException { - Log.e("Newpipe UI ERROR", report.toString()); - try { - ((String)null).length(); - } catch(Exception e) { - ErrorActivity.reportError(context, e, null, null, - ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,"none", - "App crash, UI failure", R.string.app_ui_crash)); - } + ErrorActivity.reportError(context, report, + ErrorActivity.ErrorInfo.make(ErrorActivity.UI_ERROR,"none", + "App crash, UI failure", R.string.app_ui_crash)); } } diff --git a/app/src/main/java/org/schabi/newpipe/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/ErrorActivity.java index d064af291..f572468c9 100644 --- a/app/src/main/java/org/schabi/newpipe/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ErrorActivity.java @@ -26,6 +26,8 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; +import org.acra.ReportField; +import org.acra.collector.CrashReportData; import org.json.JSONArray; import org.json.JSONObject; import org.schabi.newpipe.extractor.Parser; @@ -124,6 +126,7 @@ public class ErrorActivity extends AppCompatActivity { public static final int SOMETHING_ELSE = 3; public static final int USER_REPORT = 4; public static final int LOAD_IMAGE = 5; + public static final int UI_ERROR = 6; // MESSAGE STRING public static final String SEARCHED_STRING = "searched"; @@ -132,6 +135,7 @@ public class ErrorActivity extends AppCompatActivity { public static final String SOMETHING_ELSE_STRING = "something"; public static final String USER_REPORT_STRING = "user report"; public static final String LOAD_IMAGE_STRING = "load image"; + public static final String UI_ERROR_STRING = "ui error"; public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org"; @@ -211,6 +215,22 @@ public class ErrorActivity extends AppCompatActivity { }); } + public static void reportError(final Context context, final CrashReportData report, final ErrorInfo errorInfo) { + // get key first (don't ask about this solution) + ReportField key = null; + for(ReportField k : report.keySet()) { + if(k.toString().equals("STACK_TRACE")) { + key = k; + } + } + String[] el = new String[] { report.get(key) }; + + Intent intent = new Intent(context, ErrorActivity.class); + intent.putExtra(ERROR_INFO, errorInfo); + intent.putExtra(ERROR_LIST, el); + context.startActivity(intent); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -397,6 +417,8 @@ public class ErrorActivity extends AppCompatActivity { return USER_REPORT_STRING; case LOAD_IMAGE: return LOAD_IMAGE_STRING; + case UI_ERROR: + return UI_ERROR_STRING; default: return "Your description is in another castle."; } diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index e94d7591c..9e4a3c08f 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -44,6 +44,8 @@ public class MainActivity extends AppCompatActivity { setVolumeControlStream(AudioManager.STREAM_MUSIC); mainFragment = getSupportFragmentManager() .findFragmentById(R.id.search_fragment); + + ((String)null).length(); } public boolean onCreateOptionsMenu(Menu menu) {