Browse Source

Store crash info as draft email

main
M66B 6 years ago
parent
commit
bc9a26c2c7
2 changed files with 55 additions and 0 deletions
  1. +51
    -0
      app/src/main/java/eu/faircode/email/ApplicationEx.java
  2. +4
    -0
      app/src/main/java/eu/faircode/email/DB.java

+ 51
- 0
app/src/main/java/eu/faircode/email/ApplicationEx.java View File

@ -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);
}
});
}
}

+ 4
- 0
app/src/main/java/eu/faircode/email/DB.java View File

@ -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…
Cancel
Save