mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 11:51:10 +01:00
Introduce SignalDatabase as the main database entrypoint.
This commit is contained in:
@@ -3,14 +3,13 @@ package org.thoughtcrime.securesms.migrations;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobs.StorageSyncJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
/**
|
||||
* Marks the AccountRecord as dirty and runs a storage sync. Can be enqueued when we've added a new
|
||||
@@ -47,7 +46,7 @@ public class AccountRecordMigrationJob extends MigrationJob {
|
||||
return;
|
||||
}
|
||||
|
||||
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(Recipient.self().getId());
|
||||
SignalDatabase.recipients().markNeedsSync(Recipient.self().getId());
|
||||
ApplicationDependencies.getJobManager().add(new StorageSyncJob());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,13 @@ import androidx.annotation.NonNull;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.signalservice.api.storage.SignalAccountRecord;
|
||||
import org.whispersystems.signalservice.api.storage.StorageId;
|
||||
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord;
|
||||
@@ -56,7 +55,7 @@ public class ApplyUnknownFieldsToSelfMigrationJob extends MigrationJob {
|
||||
|
||||
try {
|
||||
self = Recipient.self();
|
||||
settings = DatabaseFactory.getRecipientDatabase(context).getRecipientSettingsForSync(self.getId());
|
||||
settings = SignalDatabase.recipients().getRecipientSettingsForSync(self.getId());
|
||||
} catch (RecipientDatabase.MissingRecipientException e) {
|
||||
Log.w(TAG, "Unable to find self");
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.migrations;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class AttachmentCleanupMigrationJob extends MigrationJob {
|
||||
|
||||
@Override
|
||||
public void performMigration() {
|
||||
int deletes = DatabaseFactory.getAttachmentDatabase(context).deleteAbandonedAttachmentFiles();
|
||||
int deletes = SignalDatabase.attachments().deleteAbandonedAttachmentFiles();
|
||||
Log.i(TAG, "Deleted " + deletes + " abandoned attachments.");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DatabaseMigrationJob extends MigrationJob {
|
||||
|
||||
@Override
|
||||
public void performMigration() {
|
||||
DatabaseFactory.getInstance(context).triggerDatabaseAccess();
|
||||
SignalDatabase.triggerDatabaseAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColorsLegacy;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColorsMapper;
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColorsPalette;
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.MessageDatabase;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase.Reader;
|
||||
import org.thoughtcrime.securesms.database.PushDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
@@ -111,7 +106,7 @@ public class LegacyMigrationJob extends MigrationJob {
|
||||
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
|
||||
|
||||
if (lastSeenVersion < SQLCIPHER && masterSecret != null) {
|
||||
DatabaseFactory.getInstance(context).onApplicationLevelUpgrade(context, masterSecret, lastSeenVersion, (progress, total) -> {
|
||||
SignalDatabase.onApplicationLevelUpgrade(context, masterSecret, lastSeenVersion, (progress, total) -> {
|
||||
Log.i(TAG, "onApplicationLevelUpgrade: " + progress + "/" + total);
|
||||
});
|
||||
} else if (lastSeenVersion < SQLCIPHER) {
|
||||
@@ -235,7 +230,7 @@ public class LegacyMigrationJob extends MigrationJob {
|
||||
if (lastSeenVersion < COLOR_MIGRATION) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
//noinspection deprecation
|
||||
DatabaseFactory.getRecipientDatabase(context).updateSystemContactColors();
|
||||
SignalDatabase.recipients().updateSystemContactColors();
|
||||
Log.i(TAG, "Color migration took " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
|
||||
@@ -256,9 +251,9 @@ public class LegacyMigrationJob extends MigrationJob {
|
||||
}
|
||||
|
||||
private void schedulePendingIncomingParts(Context context) {
|
||||
final AttachmentDatabase attachmentDb = DatabaseFactory.getAttachmentDatabase(context);
|
||||
final MessageDatabase mmsDb = DatabaseFactory.getMmsDatabase(context);
|
||||
final List<DatabaseAttachment> pendingAttachments = DatabaseFactory.getAttachmentDatabase(context).getPendingAttachments();
|
||||
final AttachmentDatabase attachmentDb = SignalDatabase.attachments();
|
||||
final MessageDatabase mmsDb = SignalDatabase.mms();
|
||||
final List<DatabaseAttachment> pendingAttachments = SignalDatabase.attachments().getPendingAttachments();
|
||||
|
||||
Log.i(TAG, pendingAttachments.size() + " pending parts.");
|
||||
for (DatabaseAttachment attachment : pendingAttachments) {
|
||||
@@ -277,7 +272,7 @@ public class LegacyMigrationJob extends MigrationJob {
|
||||
}
|
||||
|
||||
private static void scheduleMessagesInPushDatabase(@NonNull Context context) {
|
||||
PushDatabase pushDatabase = DatabaseFactory.getPushDatabase(context);
|
||||
PushDatabase pushDatabase = SignalDatabase.push();
|
||||
JobManager jobManager = ApplicationDependencies.getJobManager();
|
||||
|
||||
try (PushDatabase.Reader pushReader = pushDatabase.readerFor(pushDatabase.getPending())) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
@@ -35,7 +35,7 @@ public class ProfileSharingUpdateMigrationJob extends MigrationJob {
|
||||
@Override
|
||||
public void performMigration() {
|
||||
long messageRequestEnableTime = SignalStore.misc().getMessageRequestEnableTime();
|
||||
DatabaseFactory.getRecipientDatabase(context).markPreMessageRequestRecipientsAsProfileSharingEnabled(messageRequestEnableTime);
|
||||
SignalDatabase.recipients().markPreMessageRequestRecipientsAsProfileSharingEnabled(messageRequestEnableTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.StickerDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
@@ -50,7 +50,7 @@ public class StickerLaunchMigrationJob extends MigrationJob {
|
||||
|
||||
private static void installPack(@NonNull Context context, @NonNull BlessedPacks.Pack pack) {
|
||||
JobManager jobManager = ApplicationDependencies.getJobManager();
|
||||
StickerDatabase stickerDatabase = DatabaseFactory.getStickerDatabase(context);
|
||||
StickerDatabase stickerDatabase = SignalDatabase.stickers();
|
||||
|
||||
if (stickerDatabase.isPackAvailableAsReference(pack.getPackId())) {
|
||||
stickerDatabase.markPackAsInstalled(pack.getPackId(), false);
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.migrations;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
@@ -48,7 +48,7 @@ public class StorageServiceMigrationJob extends MigrationJob {
|
||||
return;
|
||||
}
|
||||
|
||||
DatabaseFactory.getRecipientDatabase(context).markNeedsSync(Recipient.self().getId());
|
||||
SignalDatabase.recipients().markNeedsSync(Recipient.self().getId());
|
||||
|
||||
JobManager jobManager = ApplicationDependencies.getJobManager();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.MainActivity;
|
||||
import org.thoughtcrime.securesms.NewConversationActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
@@ -74,7 +74,7 @@ public class UserNotificationMigrationJob extends MigrationJob {
|
||||
return;
|
||||
}
|
||||
|
||||
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
||||
ThreadDatabase threadDatabase = SignalDatabase.threads();
|
||||
|
||||
int threadCount = threadDatabase.getUnarchivedConversationListCount() +
|
||||
threadDatabase.getArchivedConversationListCount();
|
||||
@@ -84,8 +84,8 @@ public class UserNotificationMigrationJob extends MigrationJob {
|
||||
return;
|
||||
}
|
||||
|
||||
List<RecipientId> registered = DatabaseFactory.getRecipientDatabase(context).getRegistered();
|
||||
List<RecipientId> systemContacts = DatabaseFactory.getRecipientDatabase(context).getSystemContacts();
|
||||
List<RecipientId> registered = SignalDatabase.recipients().getRegistered();
|
||||
List<RecipientId> systemContacts = SignalDatabase.recipients().getSystemContacts();
|
||||
Set<RecipientId> registeredSystemContacts = SetUtil.intersection(registered, systemContacts);
|
||||
Set<RecipientId> threadRecipients = threadDatabase.getAllThreadRecipients();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.text.TextUtils;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
@@ -14,12 +14,10 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Couple migrations steps need to happen after we move to UUIDS.
|
||||
@@ -68,14 +66,14 @@ public class UuidMigrationJob extends MigrationJob {
|
||||
}
|
||||
|
||||
private static void ensureSelfRecipientExists(@NonNull Context context) {
|
||||
DatabaseFactory.getRecipientDatabase(context).getOrInsertFromE164(Objects.requireNonNull(SignalStore.account().getE164()));
|
||||
SignalDatabase.recipients().getOrInsertFromE164(Objects.requireNonNull(SignalStore.account().getE164()));
|
||||
}
|
||||
|
||||
private static void fetchOwnUuid(@NonNull Context context) throws IOException {
|
||||
RecipientId self = Recipient.self().getId();
|
||||
ACI localUuid = ApplicationDependencies.getSignalServiceAccountManager().getOwnAci();
|
||||
|
||||
DatabaseFactory.getRecipientDatabase(context).markRegisteredOrThrow(self, localUuid);
|
||||
SignalDatabase.recipients().markRegisteredOrThrow(self, localUuid);
|
||||
SignalStore.account().setAci(localUuid);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user