From 3440d95fbb00a530a7e4d977bbef553135232f70 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 20 Oct 2019 18:35:33 +0200 Subject: show dialog if end of provider's gateway list is reached (#8964) --- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/eip/EIP.java') 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 2b03ce5c..5ce8b6e2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -50,7 +50,10 @@ import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.VpnStatus; import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.OnBootReceiver; +import se.leap.bitmaskclient.ProviderObservable; import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.utils.ConfigHelper; +import se.leap.bitmaskclient.utils.PreferenceHelper; import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_OK; @@ -225,7 +228,7 @@ public final class EIP extends JobIntentService implements Observer { if (launchActiveGateway(gateway, nClosestGateway)) { tellToReceiverOrBroadcast(EIP_ACTION_START, RESULT_OK); } else { - setErrorResult(result, NO_MORE_GATEWAYS.toString()); + setErrorResult(result, NO_MORE_GATEWAYS.toString(), getStringResourceForNoMoreGateways(), getString(R.string.app_name)); tellToReceiverOrBroadcast(EIP_ACTION_START, RESULT_CANCELED, result); } } @@ -378,30 +381,25 @@ public final class EIP extends JobIntentService implements Observer { * @param errorId - MainActivityErrorDialog DownloadError id */ void setErrorResult(Bundle result, @StringRes int errorMessageId, String errorId) { - JSONObject errorJson = new JSONObject(); - try { - errorJson.put(ERRORS, getResources().getString(errorMessageId)); - errorJson.put(ERROR_ID, errorId); - } catch (JSONException e) { - e.printStackTrace(); - } - result.putString(ERRORS, errorJson.toString()); - result.putBoolean(BROADCAST_RESULT_KEY, false); + setErrorResult(result, errorId, errorMessageId, (Object[]) null); } + /** - * Helper function to add an error to result bundle. - * Error results set by this method will be handled as - * internal errors without any user interaction - * (Setting only ERROR_ID but no ERRORS in the errorjson - * will be ignored in MainActivity) + * helper function to add error to result bundle * * @param result - result of an action - * @param errorId - error identifier + * @param errorMessageId - id of string resource describing the error + * @param errorId - MainActivityErrorDialog DownloadError id */ - void setErrorResult(Bundle result, String errorId) { + void setErrorResult(Bundle result, String errorId, @StringRes int errorMessageId, Object... args) { JSONObject errorJson = new JSONObject(); try { + if (args != null) { + errorJson.put(ERRORS, getResources().getString(errorMessageId, args)); + } else { + errorJson.put(ERRORS, getResources().getString(errorMessageId)); + } errorJson.put(ERROR_ID, errorId); } catch (JSONException e) { e.printStackTrace(); @@ -451,6 +449,19 @@ public final class EIP extends JobIntentService implements Observer { return false; } + + private @StringRes int getStringResourceForNoMoreGateways() { + if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) { + if (PreferenceHelper.getUsePluggableTransports(getApplicationContext())) { + return R.string.warning_no_more_gateways_use_ovpn; + } else { + return R.string.warning_no_more_gateways_use_pt; + } + } else { + return R.string.warning_no_more_gateways_no_pt; + } + } + /** * Assigns a new OpenVpnServiceConnection to EIP's member variable openVpnServiceConnection. * Only one thread at a time can create the service connection, that will be shared between threads -- cgit v1.2.3