diff --git a/app/src/androidTest/java/org/thoughtcrime/securesms/messages/EditMessageSyncProcessorTest.kt b/app/src/androidTest/java/org/thoughtcrime/securesms/messages/EditMessageSyncProcessorTest.kt index 193d56f48b..004076602b 100644 --- a/app/src/androidTest/java/org/thoughtcrime/securesms/messages/EditMessageSyncProcessorTest.kt +++ b/app/src/androidTest/java/org/thoughtcrime/securesms/messages/EditMessageSyncProcessorTest.kt @@ -207,7 +207,7 @@ class EditMessageSyncProcessorTest { } fun cleanup() { - SignalDatabase.rawDatabase.withinTransaction { db -> + SignalDatabase.writableDatabase.withinTransaction { db -> SignalDatabase.threads.deleteAllConversations() db.execSQL("DELETE FROM sqlite_sequence WHERE name = '${MessageTable.TABLE_NAME}'") db.execSQL("DELETE FROM sqlite_sequence WHERE name = '${ThreadTable.TABLE_NAME}'") diff --git a/app/src/androidTest/java/org/thoughtcrime/securesms/messages/SyncMessageProcessorTest_synchronizeDeleteForMe.kt b/app/src/androidTest/java/org/thoughtcrime/securesms/messages/SyncMessageProcessorTest_synchronizeDeleteForMe.kt index 04caee40e9..0d1333e1f9 100644 --- a/app/src/androidTest/java/org/thoughtcrime/securesms/messages/SyncMessageProcessorTest_synchronizeDeleteForMe.kt +++ b/app/src/androidTest/java/org/thoughtcrime/securesms/messages/SyncMessageProcessorTest_synchronizeDeleteForMe.kt @@ -516,7 +516,7 @@ class SyncMessageProcessorTest_synchronizeDeleteForMe { SignalDatabase.messages.deleteMessage(messageId = oneToOnePlaceHolderMessage, threadId = aliceThreadId, notify = false, updateThread = false) SignalDatabase.messages.deleteMessage(messageId = groupPlaceholderMessage, threadId = aliceThreadId, notify = false, updateThread = false) - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { assertThat(SignalDatabase.messages.getMessageCountForThread(aliceThreadId)).isEqualTo(16) assertThat(SignalDatabase.messages.getMessageCountForThread(groupThreadId)).isEqualTo(10) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/BackupRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/BackupRepository.kt index e761f6905f..ae77c253c8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/BackupRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/BackupRepository.kt @@ -604,7 +604,7 @@ object BackupRepository { } // We make a copy of the database within a transaction to ensure that no writes occur while we're copying the file - return SignalDatabase.rawDatabase.withinTransaction { + return SignalDatabase.writableDatabase.withinTransaction { val context = AppDependencies.application val existingDbFile = context.getDatabasePath(SignalDatabase.DATABASE_NAME) @@ -898,7 +898,7 @@ object BackupRepository { eventTimer.emit("header") // We're using a snapshot, so the transaction is more for perf than correctness - dbSnapshot.rawWritableDatabase.withinTransaction { + dbSnapshot.signalWritableDatabase.withinTransaction { progressEmitter?.onAccount() AccountDataArchiveProcessor.export(dbSnapshot, signalStoreSnapshot, exportState) { frame -> writer.write(frame) @@ -1164,19 +1164,19 @@ object BackupRepository { // SQLite optimizes deletes if there's no foreign keys, triggers, or WHERE clause, so that's the environment we're gonna create. Log.d(TAG, "[import] Disabling foreign keys...") - SignalDatabase.rawDatabase.forceForeignKeyConstraintsEnabled(false) + SignalDatabase.writableDatabase.forceForeignKeyConstraintsEnabled(false) Log.d(TAG, "[import] Acquiring transaction...") - SignalDatabase.rawDatabase.beginTransaction() + SignalDatabase.writableDatabase.beginTransaction() Log.d(TAG, "[import] Inside transaction.") stopwatch.split("get-transaction") Log.d(TAG, "[import] --- Dropping all indices ---") - val indexMetadata = SignalDatabase.rawDatabase.getAllIndexDefinitions() + val indexMetadata = SignalDatabase.writableDatabase.getAllIndexDefinitions() for (index in indexMetadata) { Log.d(TAG, "[import] Dropping index ${index.name}...") - SignalDatabase.rawDatabase.execSQL("DROP INDEX IF EXISTS ${index.name}") + SignalDatabase.writableDatabase.execSQL("DROP INDEX IF EXISTS ${index.name}") } stopwatch.split("drop-indices") @@ -1185,10 +1185,10 @@ object BackupRepository { } Log.d(TAG, "[import] --- Dropping all triggers ---") - val triggerMetadata = SignalDatabase.rawDatabase.getAllTriggerDefinitions() + val triggerMetadata = SignalDatabase.writableDatabase.getAllTriggerDefinitions() for (trigger in triggerMetadata) { Log.d(TAG, "[import] Dropping trigger ${trigger.name}...") - SignalDatabase.rawDatabase.execSQL("DROP TRIGGER IF EXISTS ${trigger.name}") + SignalDatabase.writableDatabase.execSQL("DROP TRIGGER IF EXISTS ${trigger.name}") } stopwatch.split("drop-triggers") @@ -1207,7 +1207,7 @@ object BackupRepository { add(SessionTable.TABLE_NAME) } } - val tableMetadata = SignalDatabase.rawDatabase.getAllTableDefinitions().filter { !it.name.startsWith(SearchTable.FTS_TABLE_NAME + "_") } + val tableMetadata = SignalDatabase.writableDatabase.getAllTableDefinitions().filter { !it.name.startsWith(SearchTable.FTS_TABLE_NAME + "_") } for (table in tableMetadata) { if (skipTables.contains(table.name)) { Log.d(TAG, "[import] Skipping drop/create of table ${table.name}") @@ -1215,10 +1215,10 @@ object BackupRepository { } Log.d(TAG, "[import] Dropping table ${table.name}...") - SignalDatabase.rawDatabase.execSQL("DROP TABLE IF EXISTS ${table.name}") + SignalDatabase.writableDatabase.execSQL("DROP TABLE IF EXISTS ${table.name}") Log.d(TAG, "[import] Creating table ${table.name}...") - SignalDatabase.rawDatabase.execSQL(table.statement) + SignalDatabase.writableDatabase.execSQL(table.statement) } RecipientId.clearCache() @@ -1340,14 +1340,14 @@ object BackupRepository { Log.d(TAG, "[import] --- Recreating indices ---") for (index in indexMetadata) { Log.d(TAG, "[import] Creating index ${index.name}...") - SignalDatabase.rawDatabase.execSQL(index.statement) + SignalDatabase.writableDatabase.execSQL(index.statement) } stopwatch.split("recreate-indices") Log.d(TAG, "[import] --- Recreating triggers ---") for (trigger in triggerMetadata) { Log.d(TAG, "[import] Creating trigger ${trigger.name}...") - SignalDatabase.rawDatabase.execSQL(trigger.statement) + SignalDatabase.writableDatabase.execSQL(trigger.statement) } stopwatch.split("recreate-triggers") @@ -1357,17 +1357,17 @@ object BackupRepository { } stopwatch.split("thread-updates") - val foreignKeyViolations = SignalDatabase.rawDatabase.getForeignKeyViolations() + val foreignKeyViolations = SignalDatabase.writableDatabase.getForeignKeyViolations() if (foreignKeyViolations.isNotEmpty()) { throw IllegalStateException("Foreign key check failed! Violations: $foreignKeyViolations") } stopwatch.split("fk-check") - SignalDatabase.rawDatabase.setTransactionSuccessful() + SignalDatabase.writableDatabase.setTransactionSuccessful() transactionSuccessful = true } finally { - if (SignalDatabase.rawDatabase.inTransaction()) { - SignalDatabase.rawDatabase.endTransaction() + if (SignalDatabase.writableDatabase.inTransaction()) { + SignalDatabase.writableDatabase.endTransaction() } if (!transactionSuccessful) { @@ -1376,7 +1376,7 @@ object BackupRepository { } Log.d(TAG, "[import] Re-enabling foreign keys...") - SignalDatabase.rawDatabase.forceForeignKeyConstraintsEnabled(true) + SignalDatabase.writableDatabase.forceForeignKeyConstraintsEnabled(true) } SignalDatabase.remappedRecords.clearCache() diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRepository.kt index 4b3b7480fb..fa11cdd16c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRepository.kt @@ -108,7 +108,7 @@ class CallLogRepository( */ fun deleteAllCallLogsOnOrBeforeNow(): Single { return Single.fromCallable { - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { val latestCall = SignalDatabase.calls.getLatestCall() ?: return@withinTransaction SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(latestCall.timestamp) SignalDatabase.callLinks.deleteNonAdminCallLinksOnOrBefore(latestCall.timestamp) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/InternalConversationSettingsFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/InternalConversationSettingsFragment.kt index fade58e6de..f113cc50a0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/InternalConversationSettingsFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/conversation/InternalConversationSettingsFragment.kt @@ -178,7 +178,7 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa val recipient = Recipient.live(recipientId).get() val messageCount = 1000 val startTime = System.currentTimeMillis() - messageCount - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { val targetThread = SignalDatabase.threads.getOrCreateThreadIdFor(recipient) for (i in 1..messageCount) { val time = startTime + i @@ -208,7 +208,7 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa val recipient = Recipient.live(recipientId).get() val messageCount = 100 val startTime = System.currentTimeMillis() - messageCount - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { val targetThread = SignalDatabase.threads.getOrCreateThreadIdFor(recipient) for (i in 1..messageCount) { val time = startTime + i diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java index e2dbfee2dc..ed1d0abefe 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java @@ -5,8 +5,6 @@ import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.zetetic.database.sqlcipher.SQLiteDatabase; - import org.signal.core.util.logging.Log; import org.signal.libsignal.protocol.IdentityKey; import org.signal.libsignal.protocol.SignalProtocolAddress; @@ -15,6 +13,7 @@ import org.thoughtcrime.securesms.crypto.ReentrantSessionLock; import org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore.SaveResult; import org.thoughtcrime.securesms.database.IdentityTable; import org.thoughtcrime.securesms.database.IdentityTable.VerifiedStatus; +import org.thoughtcrime.securesms.database.SQLiteDatabase; import org.thoughtcrime.securesms.database.SignalDatabase; import org.thoughtcrime.securesms.database.identity.IdentityRecordList; import org.thoughtcrime.securesms.database.model.IdentityRecord; @@ -357,7 +356,7 @@ public class SignalBaseIdentityKeyStore { * To prevent this, writes should first acquire the DB lock before getting the cache lock to ensure we always acquire locks in the same order. */ private void withWriteLock(Runnable runnable) { - SQLiteDatabase db = SignalDatabase.getRawDatabase(); + SQLiteDatabase db = SignalDatabase.identities().getWritableDatabase(); db.beginTransaction(); try { synchronized (this) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SearchTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/SearchTable.kt index b1de7e946f..b0df8c419a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SearchTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SearchTable.kt @@ -323,7 +323,7 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa * Drops all tables and recreates them. */ @JvmOverloads - fun fullyResetTables(db: SupportSQLiteDatabase = writableDatabase.sqlCipherDatabase, useTransaction: Boolean = true) { + fun fullyResetTables(db: SupportSQLiteDatabase = writableDatabase, useTransaction: Boolean = true) { if (useTransaction) { db.beginTransaction() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/BackfillDigestsForDataFileJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/BackfillDigestsForDataFileJob.kt index f1ab075d21..d8efd8da89 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/BackfillDigestsForDataFileJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/BackfillDigestsForDataFileJob.kt @@ -51,7 +51,7 @@ class BackfillDigestsForDataFileJob private constructor( override fun getFactoryKey(): String = KEY override fun run(): Result { - val (originalKey, decryptingStream) = SignalDatabase.rawDatabase.withinTransaction { + val (originalKey, decryptingStream) = SignalDatabase.writableDatabase.withinTransaction { val attachment = SignalDatabase.attachments.getMostRecentValidAttachmentUsingDataFile(dataFile) if (attachment == null) { Log.w(TAG, "No attachments using file $dataFile exist anymore! Skipping.") diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupRestoreMediaJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupRestoreMediaJob.kt index 89e9d38742..ef056ea90f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupRestoreMediaJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/BackupRestoreMediaJob.kt @@ -139,7 +139,7 @@ class BackupRestoreMediaJob private constructor(parameters: Parameters) : BaseJo } } - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { // Mark not restorable thumbnails and attachments as failed SignalDatabase.attachments.setThumbnailRestoreState(notRestorable, AttachmentTable.ThumbnailRestoreState.PERMANENT_FAILURE) SignalDatabase.attachments.setRestoreTransferState(notRestorable, AttachmentTable.TRANSFER_PROGRESS_FAILED) diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/DuplicateE164MigrationJob.kt b/app/src/main/java/org/thoughtcrime/securesms/migrations/DuplicateE164MigrationJob.kt index bfdbdc3b7d..14d3d00d13 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/migrations/DuplicateE164MigrationJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/DuplicateE164MigrationJob.kt @@ -99,7 +99,7 @@ internal class DuplicateE164MigrationJob( } Log.w(TAG, "Was not able to resolve all conflicts. We must merge the contacts together.") - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { val first = resolved.first() for (entry in resolved.drop(1)) { Log.w(TAG, "Merging ${first.id} with ${entry.id}") diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/E164FormattingMigrationJob.kt b/app/src/main/java/org/thoughtcrime/securesms/migrations/E164FormattingMigrationJob.kt index cb468dab46..062ade2f7c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/migrations/E164FormattingMigrationJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/E164FormattingMigrationJob.kt @@ -79,7 +79,7 @@ internal class E164FormattingMigrationJob( val existing: Optional = SignalDatabase.recipients.getByE164(formattedE164) if (existing.isPresent) { Log.w(TAG, "Merging ${existing.get()} and $id", true) - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { SignalDatabase.recipients.mergeForMigration(existing.get(), id) } Log.w(TAG, "Successfully merged ${existing.get()} and $id", true) diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/StorageFixLocalUnknownMigrationJob.kt b/app/src/main/java/org/thoughtcrime/securesms/migrations/StorageFixLocalUnknownMigrationJob.kt index ca4e270bc6..1de8735b12 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/migrations/StorageFixLocalUnknownMigrationJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/StorageFixLocalUnknownMigrationJob.kt @@ -37,7 +37,7 @@ internal class StorageFixLocalUnknownMigrationJob( Log.w(TAG, "Removing ${danglingLocalUnknownIds.size} dangling unknown ids") - SignalDatabase.rawDatabase.withinTransaction { + SignalDatabase.writableDatabase.withinTransaction { SignalDatabase.unknownStorageIds.delete(danglingLocalUnknownIds) }