From bb68674cae4522b40771e971474ca91ba8b65e02 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 20 Oct 2021 16:31:55 -0300 Subject: [PATCH] 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 --- .../src/main/java/org/microg/gms/gcm/McsService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java index 04dcfdfb..e0f3e038 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java @@ -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);