mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-11-11 14:49:24 +01:00
Initiate connection teardown only once
Otherwise, this gets called multiple times from different places via MSG_TEARDOWN. This causes the reconnect delay to increase with each call to scheduleReconnect(), increasing the time we stay disconnected. This commit introduces a boolean flag preventing handleTeardown() to run twice or more until connect() was called again. Change-Id: I3d7cb08d696be48532a61819fbb279a908919a3d
This commit is contained in:
parent
10455df7e2
commit
bb68674cae
@ -127,6 +127,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
private static long lastIncomingNetworkRealtime = 0;
|
||||
private static long startTimestamp = 0;
|
||||
public static String activeNetworkPref = null;
|
||||
private boolean wasTornDown = false;
|
||||
private AtomicInteger nextMessageId = new AtomicInteger(0x1000000);
|
||||
|
||||
private static Socket sslSocket;
|
||||
@ -431,6 +432,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
|
||||
private synchronized void connect() {
|
||||
wasTornDown = false;
|
||||
try {
|
||||
closeAll();
|
||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@ -692,7 +694,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
handleOutputDone(msg);
|
||||
return true;
|
||||
}
|
||||
Log.w(TAG, "Unknown message: " + msg);
|
||||
Log.w(TAG, "Unknown message (" + msg.what + "): " + msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -754,6 +756,14 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
|
||||
private void handleTeardown(android.os.Message msg) {
|
||||
if (wasTornDown) {
|
||||
// This can get called multiple times from different places via MSG_TEARDOWN
|
||||
// this causes the reconnect delay to increase with each call to scheduleReconnect(),
|
||||
// increasing the time we are disconnected.
|
||||
logd(this, "Was torn down already, not doing it again");
|
||||
return;
|
||||
}
|
||||
wasTornDown = true;
|
||||
closeAll();
|
||||
|
||||
scheduleReconnect(this);
|
||||
|
Loading…
Reference in New Issue
Block a user