Skip to content

Commit c329af6

Browse files
author
Daniil Efremov
authored
Merge pull request #73 from dividiti/issue-70
Add exception handler #70
2 parents e547647 + 1590adf commit c329af6

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

app/src/main/java/openscience/crowdsource/video/experiments/ConsoleActivity.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package openscience.crowdsource.video.experiments;
22

3+
import android.app.ProgressDialog;
34
import android.content.Intent;
5+
import android.content.pm.PackageInstaller;
6+
import android.os.AsyncTask;
47
import android.os.Bundle;
8+
import android.os.Message;
59
import android.support.annotation.Nullable;
610
import android.support.v7.app.AppCompatActivity;
711
import android.view.View;
812
import android.widget.Button;
913
import android.widget.EditText;
1014

15+
import java.io.UnsupportedEncodingException;
16+
import java.net.PasswordAuthentication;
17+
import java.util.Properties;
18+
19+
import static android.R.attr.password;
20+
1121
/**
1222
* Screen with app console log displays recognition and other processes details
1323
*
@@ -30,6 +40,14 @@ protected void onCreate(Bundle savedInstanceState) {
3040
AppLogger.updateTextView(consoleEditText);
3141
MainActivity.setTaskBarColored(this);
3242
registerLoggerViewerUpdater();
43+
44+
String error = getIntent().getStringExtra(ExceptionHandler.ERROR);
45+
if (error != null) {
46+
AppLogger.logMessage(error);
47+
Button homeRecognize = (Button) findViewById(R.id.btn_home_recognizeConsole);
48+
homeRecognize.setEnabled(false);
49+
homeRecognize.setVisibility(View.GONE);
50+
}
3351
}
3452

3553
private void registerLoggerViewerUpdater() {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package openscience.crowdsource.video.experiments;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Build;
6+
7+
import java.io.PrintWriter;
8+
import java.io.StringWriter;
9+
10+
/**
11+
* @author Daniil Efremov
12+
*/
13+
14+
public class ExceptionHandler implements
15+
java.lang.Thread.UncaughtExceptionHandler {
16+
public static final String ERROR = "error";
17+
private final Activity myContext;
18+
private final String LINE_SEPARATOR = "\n";
19+
20+
public ExceptionHandler(Activity context) {
21+
myContext = context;
22+
}
23+
24+
public void uncaughtException(Thread thread, Throwable exception) {
25+
StringWriter stackTrace = new StringWriter();
26+
exception.printStackTrace(new PrintWriter(stackTrace));
27+
StringBuilder errorReport = new StringBuilder();
28+
errorReport.append("************ CAUSE OF ERROR ************\n\n");
29+
errorReport.append(stackTrace.toString());
30+
31+
errorReport.append("\n************ DEVICE INFORMATION ***********\n");
32+
errorReport.append("Brand: ");
33+
errorReport.append(Build.BRAND);
34+
errorReport.append(LINE_SEPARATOR);
35+
errorReport.append("Device: ");
36+
errorReport.append(Build.DEVICE);
37+
errorReport.append(LINE_SEPARATOR);
38+
errorReport.append("Model: ");
39+
errorReport.append(Build.MODEL);
40+
errorReport.append(LINE_SEPARATOR);
41+
errorReport.append("Id: ");
42+
errorReport.append(Build.ID);
43+
errorReport.append(LINE_SEPARATOR);
44+
errorReport.append("Product: ");
45+
errorReport.append(Build.PRODUCT);
46+
errorReport.append(LINE_SEPARATOR);
47+
errorReport.append("\n************ FIRMWARE ************\n");
48+
errorReport.append("SDK: ");
49+
errorReport.append(Build.VERSION.SDK);
50+
errorReport.append(LINE_SEPARATOR);
51+
errorReport.append("Release: ");
52+
errorReport.append(Build.VERSION.RELEASE);
53+
errorReport.append(LINE_SEPARATOR);
54+
errorReport.append("Incremental: ");
55+
errorReport.append(Build.VERSION.INCREMENTAL);
56+
errorReport.append(LINE_SEPARATOR);
57+
58+
// AppLogger.logMessage(errorReport.toString());
59+
Intent intent = new Intent(myContext, ConsoleActivity.class);
60+
intent.putExtra(ERROR, errorReport.toString());
61+
myContext.startActivity(intent);
62+
63+
android.os.Process.killProcess(android.os.Process.myPid());
64+
System.exit(10);
65+
}
66+
67+
}

app/src/main/java/openscience/crowdsource/video/experiments/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ private RecognitionScenario getSelectedRecognitionScenario() {
218218
@Override
219219
protected void onCreate(Bundle savedInstanceState) {
220220
super.onCreate(savedInstanceState);
221+
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
221222
setContentView(R.layout.activity_main);
222223
setTaskBarColored(this);
223224

0 commit comments

Comments
 (0)