diff --git a/java/src/main/java/org/whispersystems/signalservice/api/util/SignalThread.java b/java/src/main/java/org/whispersystems/signalservice/api/util/SignalThread.java new file mode 100644 index 0000000000..4d7dadb877 --- /dev/null +++ b/java/src/main/java/org/whispersystems/signalservice/api/util/SignalThread.java @@ -0,0 +1,24 @@ +/** + * Copyright (C) 2014-2016 Open Whisper Systems + * + * Licensed according to the LICENSE file in this repository. + */ + +package org.whispersystems.signalservice.api.util; + +import org.whispersystems.signalservice.internal.util.Util; + +public class SignalThread { + + private static boolean active = false; + + public static synchronized void onTrigger() { + active = true; + SignalThread.class.notifyAll(); + } + + public static synchronized void sleep(long millis) { + Util.wait(SignalThread.class, active ? 0 : millis); + } + +} \ No newline at end of file diff --git a/java/src/main/java/org/whispersystems/signalservice/internal/websocket/WebSocketConnection.java b/java/src/main/java/org/whispersystems/signalservice/internal/websocket/WebSocketConnection.java index b6a845a033..b9d26fcffd 100644 --- a/java/src/main/java/org/whispersystems/signalservice/internal/websocket/WebSocketConnection.java +++ b/java/src/main/java/org/whispersystems/signalservice/internal/websocket/WebSocketConnection.java @@ -6,6 +6,7 @@ import org.whispersystems.libsignal.util.Pair; import org.whispersystems.signalservice.api.push.TrustStore; import org.whispersystems.signalservice.api.util.CredentialsProvider; +import org.whispersystems.signalservice.api.util.SignalThread; import org.whispersystems.signalservice.api.websocket.ConnectivityListener; import org.whispersystems.signalservice.internal.util.BlacklistingTrustManager; import org.whispersystems.signalservice.internal.util.Util; @@ -42,7 +43,7 @@ public class WebSocketConnection extends WebSocketListener { private static final String TAG = WebSocketConnection.class.getSimpleName(); - private static final int KEEPALIVE_TIMEOUT_SECONDS = 55; + private static final int KEEPALIVE_TIMEOUT_SECONDS = 60; private final LinkedList incomingRequests = new LinkedList<>(); private final Map>> outgoingRequests = new HashMap<>(); @@ -297,7 +298,7 @@ private class KeepAliveSender extends Thread { public void run() { while (!stop.get()) { try { - Thread.sleep(TimeUnit.SECONDS.toMillis(KEEPALIVE_TIMEOUT_SECONDS)); + SignalThread.sleep(TimeUnit.SECONDS.toMillis(KEEPALIVE_TIMEOUT_SECONDS)); Log.w(TAG, "Sending keep alive..."); sendKeepAlive();