summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-10-20 18:35:33 +0200
committercyBerta <cyberta@riseup.net>2019-10-20 18:35:33 +0200
commit3440d95fbb00a530a7e4d977bbef553135232f70 (patch)
treed2c8583862c04fb4ec166b02553b143056031b68 /app/src
parent30b3f419c1c0f9c5d74453e51d5300c8c108872b (diff)
show dialog if end of provider's gateway list is reached (#8964)
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/MainActivityErrorDialog.java29
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java17
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java45
-rw-r--r--app/src/main/res/values/strings.xml5
4 files changed, 78 insertions, 18 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivityErrorDialog.java b/app/src/main/java/se/leap/bitmaskclient/MainActivityErrorDialog.java
index cead4fa0..6ce21918 100644
--- a/app/src/main/java/se/leap/bitmaskclient/MainActivityErrorDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/MainActivityErrorDialog.java
@@ -17,6 +17,7 @@
package se.leap.bitmaskclient;
import android.app.Dialog;
+import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -26,12 +27,17 @@ import android.support.v7.app.AlertDialog;
import org.json.JSONObject;
import se.leap.bitmaskclient.eip.EIP;
+import se.leap.bitmaskclient.eip.EipCommand;
import static se.leap.bitmaskclient.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;
import static se.leap.bitmaskclient.eip.EIP.EIPErrors.UNKNOWN;
import static se.leap.bitmaskclient.eip.EIP.EIPErrors.valueOf;
import static se.leap.bitmaskclient.eip.EIP.ERRORS;
import static se.leap.bitmaskclient.eip.EIP.ERROR_ID;
+import static se.leap.bitmaskclient.utils.PreferenceHelper.getUsePluggableTransports;
+import static se.leap.bitmaskclient.utils.PreferenceHelper.usePluggableTransports;
/**
* Implements an error dialog for the main activity.
@@ -101,6 +107,29 @@ public class MainActivityErrorDialog extends DialogFragment {
builder.setPositiveButton(R.string.update_certificate, (dialog, which) ->
ProviderAPICommand.execute(getContext(), UPDATE_INVALID_VPN_CERTIFICATE, provider));
break;
+ case NO_MORE_GATEWAYS:
+ Context context = getContext();
+ if (context != null) {
+ Context applicationContext = context.getApplicationContext();
+ if (provider.supportsPluggableTransports()) {
+ if (getUsePluggableTransports(applicationContext)) {
+ builder.setPositiveButton(warning_option_try_ovpn, ((dialog, which) -> {
+ usePluggableTransports(applicationContext, false);
+ EipCommand.startVPN(applicationContext.getApplicationContext(), false);
+ }));
+ } else {
+ builder.setPositiveButton(warning_option_try_pt, ((dialog, which) -> {
+ usePluggableTransports(applicationContext, true);
+ EipCommand.startVPN(applicationContext.getApplicationContext(), false);
+ }));
+ }
+ } else {
+ builder.setPositiveButton(R.string.retry,(dialog, which) -> {
+ EipCommand.startVPN(applicationContext.getApplicationContext(), false);
+ });
+ }
+ }
+
default:
break;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
index 7f52911b..dea54a18 100644
--- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
@@ -47,6 +47,7 @@ import android.view.ViewGroup;
import java.util.Set;
import de.blinkt.openvpn.core.VpnStatus;
+import se.leap.bitmaskclient.Constants;
import se.leap.bitmaskclient.EipFragment;
import se.leap.bitmaskclient.FragmentManagerEnhanced;
import se.leap.bitmaskclient.MainActivity;
@@ -87,7 +88,7 @@ import static se.leap.bitmaskclient.utils.PreferenceHelper.usePluggableTransport
* See the <a href="https://developer.android.com/design/patterns/navigation-drawer.html#Interaction">
* design guidelines</a> for a complete explanation of the behaviors implemented here.
*/
-public class NavigationDrawerFragment extends Fragment {
+public class NavigationDrawerFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
/**
* Per the design guidelines, you should show the drawer on launch until the user manually
@@ -127,6 +128,7 @@ public class NavigationDrawerFragment extends Fragment {
// drawer. See PREF_USER_LEARNED_DRAWER for details.
preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
userLearnedDrawer = preferences.getBoolean(PREF_USER_LEARNED_DRAWER, false);
+ preferences.registerOnSharedPreferenceChangeListener(this);
}
@Override
@@ -164,6 +166,8 @@ public class NavigationDrawerFragment extends Fragment {
wasPaused = true;
}
+
+
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
@@ -272,6 +276,9 @@ public class NavigationDrawerFragment extends Fragment {
useBridges.setVisibility(VISIBLE);
useBridges.setChecked(getUsePluggableTransports(getContext()));
useBridges.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ if (!buttonView.isPressed()) {
+ return;
+ }
usePluggableTransports(getContext(), isChecked);
if (VpnStatus.isVPNActive()) {
EipCommand.startVPN(getContext(), true);
@@ -499,6 +506,7 @@ public class NavigationDrawerFragment extends Fragment {
public void onDestroy() {
super.onDestroy();
getRefWatcher(getActivity()).watch(this);
+ preferences.unregisterOnSharedPreferenceChangeListener(this);
}
/**
@@ -550,4 +558,11 @@ public class NavigationDrawerFragment extends Fragment {
updateExcludeAppsSubtitle(excludeApps, number);
}
}
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (key.equals(Constants.USE_PLUGGABLE_TRANSPORTS)) {
+ initUseBridgesEntry();
+ }
+ }
}
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
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1e4840c2..06aeeacf 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -122,4 +122,9 @@
<item quantity="one">%d unprotected app</item>
<item quantity="other">%d unprotected apps</item>
</plurals>
+ <string name="warning_no_more_gateways_use_pt">%s could not connect. It might be that vpn connections get blocked. Do you want to try to connect using obfuscated connections?</string>
+ <string name="warning_no_more_gateways_no_pt">%s could not connect. Do you want to retry?</string>
+ <string name="warning_no_more_gateways_use_ovpn">%s could not connect using obfuscated vpn connections. Do you want to try to connect using a standard vpn?</string>
+ <string name="warning_option_try_pt">Try obfuscated connection</string>
+ <string name="warning_option_try_ovpn">Try standard connection</string>
</resources>