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+ }
0 commit comments