diff --git a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java index a4faa115e97..37c5b1a7bdb 100644 --- a/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java +++ b/src/org/thoughtcrime/securesms/dependencies/SignalCommunicationModule.java @@ -115,10 +115,8 @@ synchronized SignalServiceMessageSender provideSignalMessageSender() { new DynamicCredentialsProvider(context), new SignalProtocolStoreImpl(context), BuildConfig.USER_AGENT, - Optional.fromNullable(MessageRetrievalService.getPipe()), + MessageRetrievalService.getPipeReference(), Optional.of(new SecurityEventListener(context))); - } else { - this.messageSender.setMessagePipe(MessageRetrievalService.getPipe()); } return this.messageSender; diff --git a/src/org/thoughtcrime/securesms/service/MessageRetrievalService.java b/src/org/thoughtcrime/securesms/service/MessageRetrievalService.java index 27429e10a81..242328e38c2 100644 --- a/src/org/thoughtcrime/securesms/service/MessageRetrievalService.java +++ b/src/org/thoughtcrime/securesms/service/MessageRetrievalService.java @@ -35,6 +35,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; @@ -63,6 +64,7 @@ public class MessageRetrievalService extends Service implements InjectableType, private MessageRetrievalThread retrievalThread = null; public static SignalServiceMessagePipe pipe = null; + public static AtomicReference pipeReference = new AtomicReference<>(); @Override public void onCreate() { @@ -283,6 +285,10 @@ public static void registerActivityStopped(Context activity) { return pipe; } + public static AtomicReference getPipeReference() { + return pipeReference; + } + private class MessageRetrievalThread extends Thread implements Thread.UncaughtExceptionHandler { private AtomicBoolean stopThread = new AtomicBoolean(false); @@ -299,9 +305,10 @@ public void run() { waitForConnectionNecessary(); Log.i(TAG, "Making websocket connection...."); - pipe = receiver.createMessagePipe(); + final SignalServiceMessagePipe localPipe = receiver.createMessagePipe(); - SignalServiceMessagePipe localPipe = pipe; + pipe = localPipe; + pipeReference.set(localPipe); try { while (isConnectionNecessary() && !stopThread.get() && !interrupted()) {