mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-03 10:16:45 +00:00
Store crash info as draft email
This commit is contained in:
parent
7e89563b48
commit
bc9a26c2c7
2 changed files with 55 additions and 0 deletions
|
@ -20,6 +20,57 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
public class ApplicationEx extends Application {
|
||||
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) {
|
||||
Log.w(Helper.TAG, "Handling crash");
|
||||
DB db = null;
|
||||
try {
|
||||
db = DB.getBlockingInstance(ApplicationEx.this);
|
||||
EntityFolder drafts = db.folder().getPrimaryDraftFolder();
|
||||
if (drafts != null) {
|
||||
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");
|
||||
|
||||
EntityMessage draft = new EntityMessage();
|
||||
draft.account = drafts.account;
|
||||
draft.folder = drafts.id;
|
||||
draft.to = MessageHelper.encodeAddresses(new Address[]{to});
|
||||
draft.subject = BuildConfig.APPLICATION_ID + " crash info";
|
||||
draft.body = "<pre>" + ex.toString().replaceAll("\\r?\\n", "<br />") + "</pre>";
|
||||
draft.received = new Date().getTime();
|
||||
draft.seen = false;
|
||||
draft.ui_seen = false;
|
||||
draft.ui_hide = false;
|
||||
draft.id = db.message().insertMessage(draft);
|
||||
|
||||
Log.w(Helper.TAG, "Crash info stored as draft");
|
||||
}
|
||||
} catch (Throwable e1) {
|
||||
Log.e(Helper.TAG, e1 + "\n" + Log.getStackTraceString(e1));
|
||||
} finally {
|
||||
if (db != null)
|
||||
db.close();
|
||||
}
|
||||
|
||||
if (prev != null)
|
||||
prev.uncaughtException(thread, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,10 @@ public abstract class DB extends RoomDatabase {
|
|||
return sInstance;
|
||||
}
|
||||
|
||||
public static DB getBlockingInstance(Context context) {
|
||||
return migrate(Room.databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME).allowMainThreadQueries());
|
||||
}
|
||||
|
||||
private static DB migrate(RoomDatabase.Builder<DB> builder) {
|
||||
return builder
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
|
|
Loading…
Reference in a new issue