FairEmail/app/src/main/java/eu/faircode/email/ApplicationEx.java

68 lines
2.3 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
This file is part of Safe email.
Safe email is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NetGuard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.app.Application;
2018-08-03 18:07:12 +00:00
import android.util.Log;
2018-08-11 04:41:26 +00:00
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
2018-08-02 13:33:06 +00:00
public class ApplicationEx extends Application {
2018-08-03 18:07:12 +00:00
private Thread.UncaughtExceptionHandler prev = null;
@Override
public void onCreate() {
super.onCreate();
prev = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
2018-08-11 04:41:26 +00:00
Log.e(Helper.TAG, ex + "\r\n" + Log.getStackTraceString(ex));
2018-08-08 13:05:43 +00:00
2018-08-11 04:41:26 +00:00
File file = new File(getCacheDir(), "crash.log");
Log.w(Helper.TAG, "Writing exception to " + file);
2018-08-03 18:07:12 +00:00
2018-08-11 04:41:26 +00:00
FileWriter out = null;
try {
out = new FileWriter(file);
out.write(ex.toString() + "\n" + Log.getStackTraceString(ex));
} catch (IOException e) {
Log.e(Helper.TAG, e + "\n" + Log.getStackTraceString(ex));
2018-08-03 18:07:12 +00:00
} finally {
2018-08-11 04:41:26 +00:00
if (out != null) {
try {
out.close();
} catch (IOException e) {
Log.e(Helper.TAG, e + "\n" + Log.getStackTraceString(ex));
}
}
2018-08-03 18:07:12 +00:00
}
if (prev != null)
prev.uncaughtException(thread, ex);
}
});
}
2018-08-02 13:33:06 +00:00
}