From dfcadde076f5a7a7c854514a1bb5c4e3039d0d36 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 20 Apr 2022 10:49:15 -0400 Subject: [PATCH] Ensure we enqueue a storage sync after a safety number change. --- .../storage/SignalBaseIdentityKeyStore.java | 6 +++--- .../securesms/database/IdentityDatabase.java | 11 +++++++++-- .../storage/ContactRecordProcessor.java | 16 ++++++++++++++-- .../securesms/util/IdentityUtil.java | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) 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 161d3a3d1e..4aa0cf24c0 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 @@ -71,13 +71,13 @@ public class SignalBaseIdentityKeyStore { RecipientId recipientId = RecipientId.fromExternalPush(address.getName()); if (identityRecord == null) { - Log.i(TAG, "Saving new identity..."); + Log.i(TAG, "Saving new identity for " + address); cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval); return SaveResult.NEW; } if (!identityRecord.getIdentityKey().equals(identityKey)) { - Log.i(TAG, "Replacing existing identity... Existing: " + identityRecord.getIdentityKey().hashCode() + " New: " + identityKey.hashCode()); + Log.i(TAG, "Replacing existing identity for " + address + " | Existing: " + identityRecord.getIdentityKey().hashCode() + ", New: " + identityKey.hashCode()); VerifiedStatus verifiedStatus; if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED || @@ -96,7 +96,7 @@ public class SignalBaseIdentityKeyStore { } if (isNonBlockingApprovalRequired(identityRecord)) { - Log.i(TAG, "Setting approval status..."); + Log.i(TAG, "Setting approval status for " + address); cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval); return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java index d6bec856c8..1ee2571728 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/IdentityDatabase.java @@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.database.model.IdentityStoreRecord; import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientId; +import org.thoughtcrime.securesms.storage.StorageSyncHelper; import org.thoughtcrime.securesms.util.Base64; import org.signal.core.util.CursorUtil; import org.thoughtcrime.securesms.util.IdentityUtil; @@ -141,6 +142,7 @@ public class IdentityDatabase extends Database { { saveIdentityInternal(addressName, recipientId, identityKey, verifiedStatus, firstUse, timestamp, nonBlockingApproval); SignalDatabase.recipients().markNeedsSync(recipientId); + StorageSyncHelper.scheduleSyncForDataChange(); } public void setApproval(@NonNull String addressName, @NonNull RecipientId recipientId, boolean nonBlockingApproval) { @@ -152,6 +154,7 @@ public class IdentityDatabase extends Database { database.update(TABLE_NAME, contentValues, ADDRESS + " = ?", SqlUtil.buildArgs(addressName)); SignalDatabase.recipients().markNeedsSync(recipientId); + StorageSyncHelper.scheduleSyncForDataChange(); } public void setVerified(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) { @@ -169,11 +172,14 @@ public class IdentityDatabase extends Database { Optional record = getIdentityRecord(addressName); if (record.isPresent()) EventBus.getDefault().post(record.get()); SignalDatabase.recipients().markNeedsSync(recipientId); + StorageSyncHelper.scheduleSyncForDataChange(); } } public void updateIdentityAfterSync(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) { - boolean hadEntry = getIdentityRecord(addressName).isPresent(); + Optional existingRecord = getIdentityRecord(addressName); + + boolean hadEntry = existingRecord.isPresent(); boolean keyMatches = hasMatchingKey(addressName, identityKey); boolean statusMatches = keyMatches && hasMatchingStatus(addressName, identityKey, verifiedStatus); @@ -190,7 +196,8 @@ public class IdentityDatabase extends Database { } if (hadEntry && !keyMatches) { - IdentityUtil.markIdentityUpdate(context, RecipientId.fromExternalPush(addressName)); + Log.w(TAG, "Updated identity key during storage sync for " + addressName + " | Existing: " + existingRecord.get().getIdentityKey().hashCode() + ", New: " + identityKey.hashCode()); + IdentityUtil.markIdentityUpdate(context, recipientId); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/ContactRecordProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/storage/ContactRecordProcessor.java index 1f4dd3ea41..214f20c1ca 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/ContactRecordProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/ContactRecordProcessor.java @@ -86,6 +86,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor r.getContact().get()); } + @Override @NonNull SignalContactRecord merge(@NonNull SignalContactRecord remote, @NonNull SignalContactRecord local, @NonNull StorageKeyGenerator keyGenerator) { String givenName; String familyName; @@ -98,14 +99,25 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor