From d4c418faf893d28e3c543f19a276fada23e2fd6e Mon Sep 17 00:00:00 2001 From: cyberta Date: Wed, 28 Apr 2021 10:40:18 +0200 Subject: ask to disable manual gateway selection if current combination of transport and location fails --- .../base/fragments/MainActivityErrorDialog.java | 10 +++++++++- app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 13 +++++++++++-- app/src/main/res/values/untranslatable.xml | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java index f036b411..4034bd04 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java @@ -18,6 +18,7 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -32,6 +33,8 @@ import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.providersetup.ProviderAPICommand; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE; import static se.leap.bitmaskclient.R.string.warning_option_try_ovpn; import static se.leap.bitmaskclient.R.string.warning_option_try_pt; @@ -120,7 +123,12 @@ public class MainActivityErrorDialog extends DialogFragment { break; case NO_MORE_GATEWAYS: builder.setNegativeButton(R.string.cancel, (dialog, id) -> {}); - if (provider.supportsPluggableTransports()) { + if (getPreferredCity(applicationContext) != null) { + builder.setPositiveButton(R.string.warning_option_try_best, (dialog, which) -> { + setPreferredCity(applicationContext, null); + EipCommand.startVPN(applicationContext, false); + }); + } else if (provider.supportsPluggableTransports()) { if (getUsePluggableTransports(applicationContext)) { builder.setPositiveButton(warning_option_try_ovpn, ((dialog, which) -> { usePluggableTransports(applicationContext, false); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 74226250..d632c09e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -84,6 +84,7 @@ import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PROFILE; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICATE; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.utils.ConfigHelper.ensureNotOnMainThread; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUsePluggableTransports; import static se.leap.bitmaskclient.eip.EIP.EIPErrors.ERROR_INVALID_PROFILE; import static se.leap.bitmaskclient.eip.EIP.EIPErrors.ERROR_INVALID_VPN_CERTIFICATE; @@ -317,7 +318,12 @@ public final class EIP extends JobIntentService implements Observer { Connection.TransportType transportType = getUsePluggableTransports(this) ? OBFS4 : OPENVPN; if (gateway == null || (profile = gateway.getProfile(transportType)) == null) { - setErrorResult(result, NO_MORE_GATEWAYS.toString(), getStringResourceForNoMoreGateways(), getString(R.string.app_name)); + String preferredLocation = getPreferredCity(getApplicationContext()); + if (preferredLocation != null) { + setErrorResult(result, NO_MORE_GATEWAYS.toString(), getStringResourceForNoMoreGateways(), getString(R.string.app_name), preferredLocation); + } else { + setErrorResult(result, NO_MORE_GATEWAYS.toString(), getStringResourceForNoMoreGateways(), getString(R.string.app_name)); + } return; } @@ -527,7 +533,10 @@ public final class EIP extends JobIntentService implements Observer { private @StringRes int getStringResourceForNoMoreGateways() { - if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) { + boolean isManualGatewaySelection = PreferenceHelper.getLastConnectedVpnProfile(getApplicationContext()) != null; + if (isManualGatewaySelection) { + return R.string.warning_no_more_gateways_manual_gw_selection; + } else if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) { if (PreferenceHelper.getUsePluggableTransports(getApplicationContext())) { return R.string.warning_no_more_gateways_use_ovpn; } else { diff --git a/app/src/main/res/values/untranslatable.xml b/app/src/main/res/values/untranslatable.xml index 9c6afadd..6f989cc8 100644 --- a/app/src/main/res/values/untranslatable.xml +++ b/app/src/main/res/values/untranslatable.xml @@ -44,5 +44,9 @@ CircleImageView Copyright 2014 - 2020 Henning Dodenhof. Licensed under the Apache License, Version 2.0 + + %1$s could not connect to %2$s. Do you want to try to connect automatically with best location? + Try best location + \ No newline at end of file -- cgit v1.2.3