Fix some issues with restoring old backups.

There's a bug where if you restore a database with a different column
definition order than a new install, then column indexes in cursors
could be wrong. Closing and re-opening the database fixes this.

I also removed a reference to a possibly-closed database we were holding
onto in LiveRecipient.
This commit is contained in:
Greyson Parrelli 2021-11-19 10:41:38 -05:00 committed by Cody Henthorne
parent 44fa42fca4
commit ff038e3ade
2 changed files with 4 additions and 3 deletions

View file

@ -237,6 +237,9 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS job_spec")
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS constraint_spec")
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS dependency_spec")
instance!!.rawWritableDatabase.close()
triggerDatabaseAccess()
}
}

View file

@ -45,7 +45,6 @@ public final class LiveRecipientCache {
private final Map<RecipientId, LiveRecipient> recipients;
private final LiveRecipient unknown;
private final Executor resolveExecutor;
private final SQLiteDatabase db;
private final AtomicReference<RecipientId> localRecipientId;
private final AtomicBoolean warmedUp;
@ -58,8 +57,7 @@ public final class LiveRecipientCache {
this.warmedUp = new AtomicBoolean(false);
this.localRecipientId = new AtomicReference<>(null);
this.unknown = new LiveRecipient(context, Recipient.UNKNOWN);
this.db = SignalDatabase.getRawDatabase();
this.resolveExecutor = ThreadUtil.trace(new FilteredExecutor(SignalExecutors.BOUNDED, () -> !db.inTransaction()));
this.resolveExecutor = ThreadUtil.trace(new FilteredExecutor(SignalExecutors.BOUNDED, () -> !SignalDatabase.inTransaction()));
}
@AnyThread