From ebee98f7c2b261d16ceba3e9a9270b8cbae128f6 Mon Sep 17 00:00:00 2001 From: Dimitris Papavasiliou Date: Tue, 11 Dec 2018 20:40:56 +0200 Subject: [PATCH] Share IncomingMessageObserver's pipe by reference. --- .../dependencies/SignalCommunicationModule.java | 5 ++--- .../service/IncomingMessageObserver.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index 0b3d82c7960..07e8d47915e 100644 --- a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -131,11 +131,10 @@ synchronized SignalServiceMessageSender provideSignalMessageSender() { new SignalProtocolStoreImpl(context), BuildConfig.USER_AGENT, TextSecurePreferences.isMultiDevice(context), - Optional.fromNullable(IncomingMessageObserver.getPipe()), - Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()), + IncomingMessageObserver.getPipeReference(), + IncomingMessageObserver.getUnidentifiedPipeReference(), Optional.of(new SecurityEventListener(context))); } else { - this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe()); this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context)); } diff --git a/src/org/thoughtcrime/securesms/service/IncomingMessageObserver.java b/src/org/thoughtcrime/securesms/service/IncomingMessageObserver.java index 702d60255d1..e51f19085e5 100644 --- a/src/org/thoughtcrime/securesms/service/IncomingMessageObserver.java +++ b/src/org/thoughtcrime/securesms/service/IncomingMessageObserver.java @@ -36,6 +36,7 @@ import org.whispersystems.signalservice.api.SignalServiceMessageReceiver; import java.io.IOException; +import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -153,6 +154,14 @@ private void shutdown(SignalServiceMessagePipe pipe, SignalServiceMessagePipe un return unidentifiedPipe; } + public static AtomicReference getPipeReference() { + return pipeReference; + } + + public static AtomicReference getUnidentifiedPipeReference() { + return unidentifiedPipeReference; + } + private class MessageRetrievalThread extends Thread implements Thread.UncaughtExceptionHandler { MessageRetrievalThread() { @@ -170,8 +179,11 @@ public void run() { pipe = receiver.createMessagePipe(); unidentifiedPipe = receiver.createUnidentifiedMessagePipe(); - SignalServiceMessagePipe localPipe = pipe; - SignalServiceMessagePipe unidentifiedLocalPipe = unidentifiedPipe; + pipeReference.set(pipe); + unidentifiedPipeReference.set(unidentifiedPipe); + + final SignalServiceMessagePipe localPipe = pipe; + final SignalServiceMessagePipe unidentifiedLocalPipe = unidentifiedPipe; try { while (isConnectionNecessary() && !interrupted()) {