From 5c1ec4c06d72825c017b026ecd91e28fad514c58 Mon Sep 17 00:00:00 2001 From: Mikunj Varsani Date: Wed, 13 Nov 2019 09:47:27 +1100 Subject: [PATCH] Fix contact sync caused decryption lock to never release. Fix message --- .../securesms/jobs/PushDecryptJob.java | 18 ++++++++---------- .../securesms/sms/MessageSender.java | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index d27589ed83..4f1345f5a0 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -14,6 +14,7 @@ import android.util.Pair; import com.annimon.stream.Collectors; import com.annimon.stream.Stream; +import com.google.android.gms.common.util.IOUtils; import org.signal.libsignal.metadata.InvalidMetadataMessageException; import org.signal.libsignal.metadata.InvalidMetadataVersionException; @@ -139,6 +140,7 @@ import org.whispersystems.signalservice.loki.messaging.LokiThreadSessionResetSta import org.whispersystems.signalservice.loki.utilities.PromiseUtil; import java.io.IOException; +import java.io.InputStream; import java.security.MessageDigest; import java.security.SecureRandom; import java.util.ArrayList; @@ -649,10 +651,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private void handleSynchronizeContactMessage(@NonNull ContactsMessage contactsMessage) { if (contactsMessage.getContactsStream().isStream()) { Log.d("Loki", "Received contact sync message"); + try { - DeviceContactsInputStream contactsInputStream = new DeviceContactsInputStream(contactsMessage.getContactsStream().asStream().getInputStream()); - DeviceContact deviceContact = contactsInputStream.read(); - while (deviceContact != null) { + InputStream in = contactsMessage.getContactsStream().asStream().getInputStream(); + DeviceContactsInputStream contactsInputStream = new DeviceContactsInputStream(in); + List devices = contactsInputStream.readAll(); + for (DeviceContact deviceContact : devices) { // Check if we have the contact as a friend and that we're not trying to sync our own device Address address = Address.fromSerialized(deviceContact.getNumber()); if (!address.isPhone() || address.toPhoneString().equalsIgnoreCase(TextSecurePreferences.getLocalNumber(context))) { continue; } @@ -676,17 +680,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // TODO: Handle blocked - If user is not blocked then we should do the friend request logic otherwise add them to our block list // TODO: Handle expiration timer - Update expiration timer? // TODO: Handle avatar - Download and set avatar? - - // Read the next contact - deviceContact = contactsInputStream.read(); } - } catch (IOException e) { - // Exception is thrown when we don't have any more contacts to read from } catch (Exception e) { - Log.d("Loki", "Failed to sync contact: " + e.getMessage()); + Log.d("Loki", "Failed to sync contact: " + e); } } - } private void handleSynchronizeSentMessage(@NonNull SignalServiceContent content, diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index 2ee0a3a5a4..996684cd1a 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -115,7 +115,7 @@ public class MessageSender { if (friendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_RECEIVED) { sendBackgroundMessage(context, device); } else if (friendRequestStatus == LokiThreadFriendRequestStatus.NONE || friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_EXPIRED) { - sendBackgroundFriendRequest(context, device, "This is a friend request from android! please replace this message in the future"); + sendBackgroundFriendRequest(context, device, "Accept this friend request to enable messages to be synced across devices"); } } });