From bf0fa9e28c8bb376d64bd8e42cdf634a1137e191 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Wed, 26 Oct 2022 14:56:20 +0900 Subject: [PATCH] MCS: fallback to port 443 if 5228 is blocked(https://github.com/microg/GmsCore/commit/758fb760834fb01c10a797df1b4a6cd88dd9120f) --- .../java/org/microg/gms/gcm/McsService.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 adbe73f7..b5e4c39a 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 @@ -94,9 +94,8 @@ public class McsService extends Service implements Handler.Callback { public static final String SERVICE_HOST = "mtalk.google.com"; // A few ports are available: 443, 5228-5230 but also 5222-5223 // See https://github.com/microg/GmsCore/issues/408 - public static final int SERVICE_PORT = 5228; // Likely if the main port 5228 is blocked by a firewall, the other 52xx are blocked as well - public static final int SERVICE_PORT_FALLBACK = 443; + public static final int[] SERVICE_PORTS = {5228, 443}; private static final int WAKELOCK_TIMEOUT = 5000; // On bad mobile network a ping can take >60s, so we wait for an ACK for 90s @@ -478,8 +477,20 @@ public class McsService extends Service implements Handler.Callback { return; } - if (!connect(SERVICE_PORT)) - connect(SERVICE_PORT_FALLBACK); + Exception exception = null; + for (int port : SERVICE_PORTS) { + try { + connect(port); + return; + } catch (Exception e) { + exception = e; + Log.w(TAG, "Exception while connecting to " + SERVICE_HOST + ":" + port, e); + closeAll(); + } + } + + logd(this, "Unable to connect to all different ports, retrying later"); + rootHandler.sendMessage(rootHandler.obtainMessage(MSG_TEARDOWN, exception)); } private void handleClose(Close close) {