Attempt to fix AccountRecord restore crash.

My guess is that we're seeing a crash when updating because we're using
an out-of-date recipient snapshot that has an old/invalid storageId.

This commit uses a fresher recipient, and it prefers using the raw
record (what's in the DB) instead.
This commit is contained in:
Greyson Parrelli
2023-11-02 10:25:14 -04:00
parent bba3334df5
commit b5c1051506
5 changed files with 13 additions and 5 deletions

View File

@@ -105,7 +105,7 @@ public class StorageAccountRestoreJob extends BaseJob {
Log.i(TAG, "Applying changes locally...");
SignalDatabase.getRawDatabase().beginTransaction();
try {
StorageSyncHelper.applyAccountStorageSyncUpdates(context, Recipient.self(), accountRecord, false);
StorageSyncHelper.applyAccountStorageSyncUpdates(context, Recipient.self().fresh(), accountRecord, false);
SignalDatabase.getRawDatabase().setTransactionSuccessful();
} finally {
SignalDatabase.getRawDatabase().endTransaction();

View File

@@ -199,7 +199,7 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
fun generateAciIdentityKeyIfNecessary() {
synchronized(this) {
if (store.containsKey(KEY_ACI_IDENTITY_PUBLIC_KEY)) {
Log.w(TAG, "Tried to generate an ANI identity, but one was already set!", Throwable())
Log.w(TAG, "Tried to generate an ACI identity, but one was already set!", Throwable())
return
}

View File

@@ -157,8 +157,9 @@ public final class LiveRecipient {
}
@WorkerThread
public void refresh() {
public LiveRecipient refresh() {
refresh(getId());
return this;
}
/**

View File

@@ -1196,7 +1196,7 @@ public class Recipient {
* Forces retrieving a fresh copy of the recipient, regardless of its state.
*/
public @NonNull Recipient fresh() {
return live().resolve();
return live().refresh().resolve();
}
public @NonNull LiveRecipient live() {

View File

@@ -36,6 +36,7 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
import org.whispersystems.signalservice.internal.storage.protos.AccountRecord;
import org.whispersystems.signalservice.internal.storage.protos.OptionalBool;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@@ -126,9 +127,15 @@ public final class StorageSyncHelper {
record = recipientTable.getRecordForSync(self.getId());
}
if (record == null) {
Log.w(TAG, "[buildAccountRecord] Could not find a RecipientRecord for ourselves! ID: " + self.getId());
} else if (!Arrays.equals(record.getStorageId(), self.getStorageServiceId())) {
Log.w(TAG, "[buildAccountRecord] StorageId on RecipientRecord did not match self! ID: " + self.getId());
}
final boolean hasReadOnboardingStory = SignalStore.storyValues().getUserHasViewedOnboardingStory() || SignalStore.storyValues().getUserHasReadOnboardingStory();
SignalAccountRecord.Builder account = new SignalAccountRecord.Builder(self.getStorageServiceId(), record != null ? record.getSyncExtras().getStorageProto() : null)
SignalAccountRecord.Builder account = new SignalAccountRecord.Builder(record != null ? record.getStorageId() : self.getStorageServiceId(), record != null ? record.getSyncExtras().getStorageProto() : null)
.setProfileKey(self.getProfileKey())
.setGivenName(self.getProfileName().getGivenName())
.setFamilyName(self.getProfileName().getFamilyName())