From 1547ec20672d75aba3aa3a4a18a44336015fd464 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Mon, 8 Aug 2022 10:37:27 -0400 Subject: [PATCH] Fix illegal state exception during backup restore of unamed groups. --- .../recipients/LiveRecipientCache.java | 23 +++++++++++++++++++ .../securesms/recipients/Recipient.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java index 5c46c24d1c..82670b28cc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java @@ -6,6 +6,7 @@ import android.database.Cursor; import androidx.annotation.AnyThread; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.signal.core.util.ThreadUtil; import org.signal.core.util.concurrent.SignalExecutors; @@ -176,6 +177,28 @@ public final class LiveRecipientCache { return getLive(selfId).resolve(); } + /** Can safely get self id. If used during early registration (backup), will return null as we don't know self yet. */ + @Nullable RecipientId getSelfId() { + RecipientId selfId; + + synchronized (localRecipientId) { + selfId = localRecipientId.get(); + } + + if (selfId != null) { + return selfId; + } + + ACI localAci = SignalStore.account().getAci(); + String localE164 = SignalStore.account().getE164(); + + if (localAci == null && localE164 == null) { + return null; + } else { + return getSelf().getId(); + } + } + @AnyThread public void warmUp() { if (warmedUp.getAndSet(true)) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java index 9c29654db3..d0567e2cf0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java @@ -489,7 +489,7 @@ public class Recipient { public @Nullable String getGroupName(@NonNull Context context) { if (groupId != null && Util.isEmpty(this.groupName)) { - RecipientId selfId = Recipient.self().getId(); + RecipientId selfId = ApplicationDependencies.getRecipientCache().getSelfId(); List others = participantIds.stream() .filter(id -> !id.equals(selfId)) .limit(MAX_MEMBER_NAMES)