kopia lustrzana https://github.com/ryukoposting/Signal-Android
Ensure we only have one IncomingMessageObserver.
We saw a worrisome log that implied there may be a situation where there's two IncomingMessageObservers. I can't see how that would happen, but this is a failsafe to prevent that from happening.fork-5.53.8
rodzic
158f3d898f
commit
763a12dbc6
|
@ -37,6 +37,7 @@ import java.util.List;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class IncomingMessageObserver {
|
||||
|
||||
|
@ -45,6 +46,8 @@ public class IncomingMessageObserver {
|
|||
public static final int FOREGROUND_ID = 313399;
|
||||
private static final long REQUEST_TIMEOUT_MINUTES = 1;
|
||||
|
||||
private static final AtomicInteger INSTANCE_COUNT = new AtomicInteger(0);
|
||||
|
||||
private static SignalServiceMessagePipe pipe = null;
|
||||
private static SignalServiceMessagePipe unidentifiedPipe = null;
|
||||
|
||||
|
@ -59,6 +62,10 @@ public class IncomingMessageObserver {
|
|||
private volatile boolean terminated;
|
||||
|
||||
public IncomingMessageObserver(@NonNull Application context) {
|
||||
if (INSTANCE_COUNT.incrementAndGet() != 1) {
|
||||
throw new AssertionError("Multiple observers!");
|
||||
}
|
||||
|
||||
this.context = context;
|
||||
this.networkAccess = ApplicationDependencies.getSignalServiceNetworkAccess();
|
||||
this.decryptionDrainedListeners = new CopyOnWriteArrayList<>();
|
||||
|
@ -160,6 +167,8 @@ public class IncomingMessageObserver {
|
|||
}
|
||||
|
||||
public void terminateAsync() {
|
||||
INSTANCE_COUNT.decrementAndGet();
|
||||
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
Log.w(TAG, "Beginning termination.");
|
||||
terminated = true;
|
||||
|
|
Ładowanie…
Reference in New Issue