mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 08:09:12 +01:00
Introduce SignalDatabase as the main database entrypoint.
This commit is contained in:
@@ -5,7 +5,7 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
@@ -22,7 +22,7 @@ public final class SenderKeyUtil {
|
||||
public static void rotateOurKey(@NonNull Context context, @NonNull DistributionId distributionId) {
|
||||
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
|
||||
ApplicationDependencies.getSenderKeyStore().deleteAllFor(Recipient.self().requireServiceId(), distributionId);
|
||||
DatabaseFactory.getSenderKeySharedDatabase(context).deleteAllFor(distributionId);
|
||||
SignalDatabase.senderKeyShared().deleteAllFor(distributionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class SenderKeyUtil {
|
||||
*/
|
||||
public static long getCreateTimeForOurKey(@NonNull Context context, @NonNull DistributionId distributionId) {
|
||||
SignalProtocolAddress address = new SignalProtocolAddress(Recipient.self().requireServiceId(), SignalServiceAddress.DEFAULT_DEVICE_ID);
|
||||
return DatabaseFactory.getSenderKeyDatabase(context).getCreatedTime(address, distributionId);
|
||||
return SignalDatabase.senderKeys().getCreatedTime(address, distributionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ public final class SenderKeyUtil {
|
||||
public static void clearAllState(@NonNull Context context) {
|
||||
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
|
||||
ApplicationDependencies.getSenderKeyStore().deleteAll();
|
||||
DatabaseFactory.getSenderKeySharedDatabase(context).deleteAll();
|
||||
SignalDatabase.senderKeyShared().deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.crypto.storage;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
@@ -191,10 +191,10 @@ public class SignalProtocolStoreImpl implements SignalServiceDataStore {
|
||||
|
||||
@Override
|
||||
public Transaction beginTransaction() {
|
||||
DatabaseFactory.getInstance(context).getRawDatabase().beginTransaction();
|
||||
SignalDatabase.getRawDatabase().beginTransaction();
|
||||
return () -> {
|
||||
DatabaseFactory.getInstance(context).getRawDatabase().setTransactionSuccessful();
|
||||
DatabaseFactory.getInstance(context).getRawDatabase().endTransaction();
|
||||
SignalDatabase.getRawDatabase().setTransactionSuccessful();
|
||||
SignalDatabase.getRawDatabase().endTransaction();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.whispersystems.signalservice.api.SignalServiceSenderKeyStore;
|
||||
import org.whispersystems.signalservice.api.push.DistributionId;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
@@ -34,35 +34,35 @@ public final class SignalSenderKeyStore implements SignalServiceSenderKeyStore {
|
||||
@Override
|
||||
public void storeSenderKey(@NonNull SignalProtocolAddress sender, @NonNull UUID distributionId, @NonNull SenderKeyRecord record) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSenderKeyDatabase(context).store(sender, DistributionId.from(distributionId), record);
|
||||
SignalDatabase.senderKeys().store(sender, DistributionId.from(distributionId), record);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable SenderKeyRecord loadSenderKey(@NonNull SignalProtocolAddress sender, @NonNull UUID distributionId) {
|
||||
synchronized (LOCK) {
|
||||
return DatabaseFactory.getSenderKeyDatabase(context).load(sender, DistributionId.from(distributionId));
|
||||
return SignalDatabase.senderKeys().load(sender, DistributionId.from(distributionId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SignalProtocolAddress> getSenderKeySharedWith(DistributionId distributionId) {
|
||||
synchronized (LOCK) {
|
||||
return DatabaseFactory.getSenderKeySharedDatabase(context).getSharedWith(distributionId);
|
||||
return SignalDatabase.senderKeyShared().getSharedWith(distributionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markSenderKeySharedWith(DistributionId distributionId, Collection<SignalProtocolAddress> addresses) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSenderKeySharedDatabase(context).markAsShared(distributionId, addresses);
|
||||
SignalDatabase.senderKeyShared().markAsShared(distributionId, addresses);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSenderKeySharedWith(Collection<SignalProtocolAddress> addresses) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSenderKeySharedDatabase(context).deleteAllFor(addresses);
|
||||
SignalDatabase.senderKeyShared().deleteAllFor(addresses);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class SignalSenderKeyStore implements SignalServiceSenderKeyStore {
|
||||
*/
|
||||
public void deleteAllFor(@NonNull String addressName, @NonNull DistributionId distributionId) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSenderKeyDatabase(context).deleteAllFor(addressName, distributionId);
|
||||
SignalDatabase.senderKeys().deleteAllFor(addressName, distributionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public final class SignalSenderKeyStore implements SignalServiceSenderKeyStore {
|
||||
*/
|
||||
public void deleteAll() {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSenderKeyDatabase(context).deleteAll();
|
||||
SignalDatabase.senderKeys().deleteAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@ import androidx.annotation.Nullable;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||
import org.thoughtcrime.securesms.crypto.SessionUtil;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
||||
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.identity.IdentityRecordList;
|
||||
import org.thoughtcrime.securesms.database.model.IdentityRecord;
|
||||
import org.thoughtcrime.securesms.database.model.IdentityStoreRecord;
|
||||
@@ -43,7 +43,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
||||
private final Cache cache;
|
||||
|
||||
public TextSecureIdentityKeyStore(Context context) {
|
||||
this(context, DatabaseFactory.getIdentityDatabase(context));
|
||||
this(context, SignalDatabase.identities());
|
||||
}
|
||||
|
||||
TextSecureIdentityKeyStore(@NonNull Context context, @NonNull IdentityDatabase identityDatabase) {
|
||||
@@ -92,7 +92,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
||||
cache.save(address.getName(), recipientId, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
|
||||
IdentityUtil.markIdentityUpdate(context, recipientId);
|
||||
SessionUtil.archiveSiblingSessions(address);
|
||||
DatabaseFactory.getSenderKeySharedDatabase(context).deleteAllFor(recipientId);
|
||||
SignalDatabase.senderKeyShared().deleteAllFor(recipientId);
|
||||
return SaveResult.UPDATE;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.content.Context;
|
||||
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.whispersystems.libsignal.InvalidKeyIdException;
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.PreKeyStore;
|
||||
@@ -31,7 +31,7 @@ public class TextSecurePreKeyStore implements PreKeyStore, SignedPreKeyStore {
|
||||
@Override
|
||||
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
|
||||
synchronized (LOCK) {
|
||||
PreKeyRecord preKeyRecord = DatabaseFactory.getPreKeyDatabase(context).getPreKey(preKeyId);
|
||||
PreKeyRecord preKeyRecord = SignalDatabase.preKeys().getPreKey(preKeyId);
|
||||
|
||||
if (preKeyRecord == null) throw new InvalidKeyIdException("No such key: " + preKeyId);
|
||||
else return preKeyRecord;
|
||||
@@ -41,7 +41,7 @@ public class TextSecurePreKeyStore implements PreKeyStore, SignedPreKeyStore {
|
||||
@Override
|
||||
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
|
||||
synchronized (LOCK) {
|
||||
SignedPreKeyRecord signedPreKeyRecord = DatabaseFactory.getSignedPreKeyDatabase(context).getSignedPreKey(signedPreKeyId);
|
||||
SignedPreKeyRecord signedPreKeyRecord = SignalDatabase.signedPreKeys().getSignedPreKey(signedPreKeyId);
|
||||
|
||||
if (signedPreKeyRecord == null) throw new InvalidKeyIdException("No such signed prekey: " + signedPreKeyId);
|
||||
else return signedPreKeyRecord;
|
||||
@@ -51,41 +51,41 @@ public class TextSecurePreKeyStore implements PreKeyStore, SignedPreKeyStore {
|
||||
@Override
|
||||
public List<SignedPreKeyRecord> loadSignedPreKeys() {
|
||||
synchronized (LOCK) {
|
||||
return DatabaseFactory.getSignedPreKeyDatabase(context).getAllSignedPreKeys();
|
||||
return SignalDatabase.signedPreKeys().getAllSignedPreKeys();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storePreKey(int preKeyId, PreKeyRecord record) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getPreKeyDatabase(context).insertPreKey(preKeyId, record);
|
||||
SignalDatabase.preKeys().insertPreKey(preKeyId, record);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeSignedPreKey(int signedPreKeyId, SignedPreKeyRecord record) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSignedPreKeyDatabase(context).insertSignedPreKey(signedPreKeyId, record);
|
||||
SignalDatabase.signedPreKeys().insertSignedPreKey(signedPreKeyId, record);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsPreKey(int preKeyId) {
|
||||
return DatabaseFactory.getPreKeyDatabase(context).getPreKey(preKeyId) != null;
|
||||
return SignalDatabase.preKeys().getPreKey(preKeyId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsSignedPreKey(int signedPreKeyId) {
|
||||
return DatabaseFactory.getSignedPreKeyDatabase(context).getSignedPreKey(signedPreKeyId) != null;
|
||||
return SignalDatabase.signedPreKeys().getSignedPreKey(signedPreKeyId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePreKey(int preKeyId) {
|
||||
DatabaseFactory.getPreKeyDatabase(context).removePreKey(preKeyId);
|
||||
SignalDatabase.preKeys().removePreKey(preKeyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSignedPreKey(int signedPreKeyId) {
|
||||
DatabaseFactory.getSignedPreKeyDatabase(context).removeSignedPreKey(signedPreKeyId);
|
||||
SignalDatabase.signedPreKeys().removeSignedPreKey(signedPreKeyId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SessionDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.whispersystems.libsignal.NoSessionException;
|
||||
@@ -36,7 +36,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
@Override
|
||||
public SessionRecord loadSession(@NonNull SignalProtocolAddress address) {
|
||||
synchronized (LOCK) {
|
||||
SessionRecord sessionRecord = DatabaseFactory.getSessionDatabase(context).load(address);
|
||||
SessionRecord sessionRecord = SignalDatabase.sessions().load(address);
|
||||
|
||||
if (sessionRecord == null) {
|
||||
Log.w(TAG, "No existing session information found for " + address);
|
||||
@@ -50,7 +50,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
@Override
|
||||
public List<SessionRecord> loadExistingSessions(List<SignalProtocolAddress> addresses) throws NoSessionException {
|
||||
synchronized (LOCK) {
|
||||
List<SessionRecord> sessionRecords = DatabaseFactory.getSessionDatabase(context).load(addresses);
|
||||
List<SessionRecord> sessionRecords = SignalDatabase.sessions().load(addresses);
|
||||
|
||||
if (sessionRecords.size() != addresses.size()) {
|
||||
String message = "Mismatch! Asked for " + addresses.size() + " sessions, but only found " + sessionRecords.size() + "!";
|
||||
@@ -69,14 +69,14 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
@Override
|
||||
public void storeSession(@NonNull SignalProtocolAddress address, @NonNull SessionRecord record) {
|
||||
synchronized (LOCK) {
|
||||
DatabaseFactory.getSessionDatabase(context).store(address, record);
|
||||
SignalDatabase.sessions().store(address, record);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsSession(SignalProtocolAddress address) {
|
||||
synchronized (LOCK) {
|
||||
SessionRecord sessionRecord = DatabaseFactory.getSessionDatabase(context).load(address);
|
||||
SessionRecord sessionRecord = SignalDatabase.sessions().load(address);
|
||||
|
||||
return sessionRecord != null &&
|
||||
sessionRecord.hasSenderChain() &&
|
||||
@@ -88,7 +88,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
public void deleteSession(SignalProtocolAddress address) {
|
||||
synchronized (LOCK) {
|
||||
Log.w(TAG, "Deleting session for " + address);
|
||||
DatabaseFactory.getSessionDatabase(context).delete(address);
|
||||
SignalDatabase.sessions().delete(address);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,36 +96,36 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
public void deleteAllSessions(String name) {
|
||||
synchronized (LOCK) {
|
||||
Log.w(TAG, "Deleting all sessions for " + name);
|
||||
DatabaseFactory.getSessionDatabase(context).deleteAllFor(name);
|
||||
SignalDatabase.sessions().deleteAllFor(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getSubDeviceSessions(String name) {
|
||||
synchronized (LOCK) {
|
||||
return DatabaseFactory.getSessionDatabase(context).getSubDevices(name);
|
||||
return SignalDatabase.sessions().getSubDevices(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) {
|
||||
synchronized (LOCK) {
|
||||
return DatabaseFactory.getSessionDatabase(context)
|
||||
.getAllFor(addressNames)
|
||||
.stream()
|
||||
.filter(row -> isActive(row.getRecord()))
|
||||
.map(row -> new SignalProtocolAddress(row.getAddress(), row.getDeviceId()))
|
||||
.collect(Collectors.toSet());
|
||||
return SignalDatabase.sessions()
|
||||
.getAllFor(addressNames)
|
||||
.stream()
|
||||
.filter(row -> isActive(row.getRecord()))
|
||||
.map(row -> new SignalProtocolAddress(row.getAddress(), row.getDeviceId()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void archiveSession(SignalProtocolAddress address) {
|
||||
synchronized (LOCK) {
|
||||
SessionRecord session = DatabaseFactory.getSessionDatabase(context).load(address);
|
||||
SessionRecord session = SignalDatabase.sessions().load(address);
|
||||
if (session != null) {
|
||||
session.archiveCurrentState();
|
||||
DatabaseFactory.getSessionDatabase(context).store(address, session);
|
||||
SignalDatabase.sessions().store(address, session);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
|
||||
public void archiveSiblingSessions(@NonNull SignalProtocolAddress address) {
|
||||
synchronized (LOCK) {
|
||||
List<SessionDatabase.SessionRow> sessions = DatabaseFactory.getSessionDatabase(context).getAllFor(address.getName());
|
||||
List<SessionDatabase.SessionRow> sessions = SignalDatabase.sessions().getAllFor(address.getName());
|
||||
|
||||
for (SessionDatabase.SessionRow row : sessions) {
|
||||
if (row.getDeviceId() != address.getDeviceId()) {
|
||||
@@ -159,7 +159,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
|
||||
public void archiveAllSessions() {
|
||||
synchronized (LOCK) {
|
||||
List<SessionDatabase.SessionRow> sessions = DatabaseFactory.getSessionDatabase(context).getAll();
|
||||
List<SessionDatabase.SessionRow> sessions = SignalDatabase.sessions().getAll();
|
||||
|
||||
for (SessionDatabase.SessionRow row : sessions) {
|
||||
row.getRecord().archiveCurrentState();
|
||||
|
||||
Reference in New Issue
Block a user