Fixed sqlite crashes

pull/50/head
M66B 6 years ago
parent eb3582e05d
commit 8e9aef4ea0

@ -79,14 +79,16 @@ public abstract class DB extends RoomDatabase {
sInstance = migrate(Room sInstance = migrate(Room
.databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME) .databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME)
.setJournalMode(JournalMode.WRITE_AHEAD_LOGGING)); .setJournalMode(JournalMode.WRITE_AHEAD_LOGGING));
return sInstance; return sInstance;
} }
public static DB getBlockingInstance(Context context) { @Override
return migrate(Room public void beginTransaction() {
.databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME) // This is a workaround for sqlite crashing on some devices
.setJournalMode(JournalMode.WRITE_AHEAD_LOGGING) // Confusingly, the journal mode needs to be set to write ahead logging first for this to work
.allowMainThreadQueries()); getOpenHelper().setWriteAheadLoggingEnabled(false);
super.beginTransaction();
} }
private static DB migrate(RoomDatabase.Builder<DB> builder) { private static DB migrate(RoomDatabase.Builder<DB> builder) {

@ -900,15 +900,6 @@ public class FragmentCompose extends FragmentEx {
String pbody = "<pre>" + body.replaceAll("\\r?\\n", "<br />") + "</pre>"; String pbody = "<pre>" + body.replaceAll("\\r?\\n", "<br />") + "</pre>";
// Check data
if (action == R.id.action_send) {
if (draft.identity == null)
throw new IllegalArgumentException(context.getString(R.string.title_from_missing));
if (draft.to == null && draft.cc == null && draft.bcc == null)
throw new IllegalArgumentException(context.getString(R.string.title_to_missing));
}
try { try {
db.beginTransaction(); db.beginTransaction();
@ -940,6 +931,15 @@ public class FragmentCompose extends FragmentEx {
db.message().updateMessage(draft); db.message().updateMessage(draft);
draft.write(context, pbody); draft.write(context, pbody);
// Check data
if (action == R.id.action_send) {
if (draft.identity == null)
throw new IllegalArgumentException(context.getString(R.string.title_from_missing));
if (draft.to == null && draft.cc == null && draft.bcc == null)
throw new IllegalArgumentException(context.getString(R.string.title_to_missing));
}
// Save message ID // Save message ID
String msgid = draft.msgid; String msgid = draft.msgid;

Loading…
Cancel
Save