From 8b99af3eef4ed7f858e6ff9949d5598543bf9512 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 24 Sep 2019 12:03:33 -0400 Subject: [PATCH] Fix threading issues with LiveRecipient. --- .../thoughtcrime/securesms/recipients/LiveRecipient.java | 4 ++-- .../securesms/recipients/LiveRecipientCache.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java b/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java index 172284f428..3ef0464b21 100644 --- a/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java +++ b/src/org/thoughtcrime/securesms/recipients/LiveRecipient.java @@ -118,7 +118,7 @@ public final class LiveRecipient { * @return A fully-resolved version of the recipient. May require reading from disk. */ @WorkerThread - public synchronized @NonNull Recipient resolve() { + public @NonNull Recipient resolve() { Recipient recipient = get(); if (recipient.isResolving()) { @@ -134,7 +134,7 @@ public final class LiveRecipient { * Forces a reload of the underlying recipient. */ @WorkerThread - public synchronized void refresh() { + public void refresh() { Recipient recipient = fetchRecipientFromDisk(defaultRecipient.getId()); liveData.postValue(recipient); Stream.of(recipient.getParticipants()).map(Recipient::live).forEach(LiveRecipient::refresh); diff --git a/src/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java b/src/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java index 07c09c1211..6fc3751c3c 100644 --- a/src/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java +++ b/src/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java @@ -52,9 +52,11 @@ public final class LiveRecipientCache { return live; } - synchronized @NonNull Recipient getSelf() { - if (localRecipientId == null) { - localRecipientId = recipientDatabase.getOrInsertFromE164(TextSecurePreferences.getLocalNumber(context)); + @NonNull Recipient getSelf() { + synchronized (this) { + if (localRecipientId == null) { + localRecipientId = recipientDatabase.getOrInsertFromE164(TextSecurePreferences.getLocalNumber(context)); + } } return getLive(localRecipientId).resolve();