blob: 061ea9ae2366adb65705eb63564ba5fe8e94d585 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package de.danoeh.antennapod;
import android.os.Build;
import android.util.Log;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class CrashReportWriter implements Thread.UncaughtExceptionHandler {
private static final String TAG = "CrashReportWriter";
private final Thread.UncaughtExceptionHandler defaultHandler;
public CrashReportWriter() {
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
}
public static File getFile() {
return new File(UserPreferences.getDataFolder(null), "crash-report.log");
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
File path = getFile();
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter(path));
out.println(getSystemInfo());
out.println();
out.println("[ StackTrace ]");
ex.printStackTrace(out);
} catch (IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
} finally {
IOUtils.closeQuietly(out);
}
defaultHandler.uncaughtException(thread, ex);
}
public static String getSystemInfo() {
return "[ Environment ]" +
"\nAndroid version: " + Build.VERSION.RELEASE +
"\nOS version: " + System.getProperty("os.version") +
"\nAntennaPod version: " + BuildConfig.VERSION_NAME +
"\nModel: " + Build.MODEL +
"\nDevice: " + Build.DEVICE +
"\nProduct: " + Build.PRODUCT +
"\nTime: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()) + "\n";
}
}
|