Skip to content

Commit

Permalink
Share IncomingMessageObserver's pipe by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris Papavasiliou committed May 4, 2019
1 parent 8f86147 commit ebee98f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -153,6 +154,14 @@ private void shutdown(SignalServiceMessagePipe pipe, SignalServiceMessagePipe un
return unidentifiedPipe;
}

public static AtomicReference<SignalServiceMessagePipe> getPipeReference() {
return pipeReference;
}

public static AtomicReference<SignalServiceMessagePipe> getUnidentifiedPipeReference() {
return unidentifiedPipeReference;
}

private class MessageRetrievalThread extends Thread implements Thread.UncaughtExceptionHandler {

MessageRetrievalThread() {
Expand All @@ -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()) {
Expand Down

0 comments on commit ebee98f

Please sign in to comment.