Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

fix Thread.sleep for Android - this fixes #6644 #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WebSocketRequestMessage> incomingRequests = new LinkedList<>();
private final Map<Long, SettableFuture<Pair<Integer, String>>> outgoingRequests = new HashMap<>();
Expand Down Expand Up @@ -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();
Expand Down