From 80bf751141c85316c22a0d16c1e4d6fa0f473f44 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 2 Oct 2021 13:31:36 +0200 Subject: * refactor startTorProxy() * fix setting http proxy port correctly * snowflake+tor does currently only work when being connected to a wifi, not a cellular network. For now, we check if the device is connected to a wifi, before attempting to start tor --- .../providersetup/ProviderApiManager.java | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'app/src/production/java') diff --git a/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java b/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java index fc1f0f59..3067c1bf 100644 --- a/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java +++ b/app/src/production/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java @@ -28,6 +28,7 @@ import org.json.JSONObject; import java.io.IOException; import java.net.URL; import java.util.List; +import java.util.concurrent.TimeoutException; import de.blinkt.openvpn.core.VpnStatus; import okhttp3.OkHttpClient; @@ -325,17 +326,21 @@ public class ProviderApiManager extends ProviderApiManagerBase { } } - if (tries == 0 && - responseString != null && - responseString.contains(ERRORS) && - PreferenceHelper.useTor(preferences) && - EipStatus.getInstance().isDisconnected() && - (TorStatusObservable.getStatus() == OFF || - TorStatusObservable.getStatus() == UNKOWN)) { - TorStatusObservable.setProxyPort(startTorProxy()); - return downloadWithCommercialCA(stringUrl, provider, 1); + try { + if (tries == 0 && + responseString != null && + responseString.contains(ERRORS) && + PreferenceHelper.useTor(preferences) && + EipStatus.getInstance().isDisconnected() && + (TorStatusObservable.getStatus() == OFF || + TorStatusObservable.getStatus() == UNKOWN) && + startTorProxy() + ) { + return downloadWithCommercialCA(stringUrl, provider, 1); + } + } catch (InterruptedException | TimeoutException e) { + e.printStackTrace(); } - return responseString; } @@ -366,15 +371,20 @@ public class ProviderApiManager extends ProviderApiManagerBase { List> headerArgs = getAuthorizationHeader(); responseString = sendGetStringToServer(urlString, headerArgs, okHttpClient); - if (tries == 0 && - responseString != null && - responseString.contains(ERRORS) && - PreferenceHelper.useTor(preferences) && - EipStatus.getInstance().isDisconnected() && - (TorStatusObservable.getStatus() == OFF || - TorStatusObservable.getStatus() == UNKOWN)) { - TorStatusObservable.setProxyPort(startTorProxy()); - return downloadFromUrlWithProviderCA(urlString, provider, 1); + try { + if (tries == 0 && + responseString != null && + responseString.contains(ERRORS) && + PreferenceHelper.useTor(preferences) && + EipStatus.getInstance().isDisconnected() && + (TorStatusObservable.getStatus() == OFF || + TorStatusObservable.getStatus() == UNKOWN) && + startTorProxy() + ) { + return downloadFromUrlWithProviderCA(urlString, provider, 1); + } + } catch (InterruptedException | TimeoutException e) { + e.printStackTrace(); } return responseString; -- cgit v1.2.3