summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-11-01 23:39:42 +0100
committercyBerta <cyberta@riseup.net>2019-11-01 23:39:42 +0100
commitbdd6b529285639ce739385fa265945b9a206df39 (patch)
tree608fbdc495c705ce83d66998954a9c8a4786b0e7
parent433bdd35f59b5166d0f3c9b8807b2aa873ba2077 (diff)
start void vpn if no more gateways available during setup
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java5
3 files changed, 29 insertions, 3 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
index 53bd9002..1a0214dd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
@@ -9,6 +9,8 @@ import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
+import org.json.JSONObject;
+
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -18,6 +20,7 @@ import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConnectionStatus;
import de.blinkt.openvpn.core.LogItem;
import de.blinkt.openvpn.core.VpnStatus;
+import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.Gateway;
@@ -43,6 +46,7 @@ import static se.leap.bitmaskclient.Constants.PROVIDER_PROFILE;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE;
import static se.leap.bitmaskclient.ProviderAPI.CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE;
+import static se.leap.bitmaskclient.ProviderAPI.ERRORS;
import static se.leap.bitmaskclient.utils.PreferenceHelper.getSavedProviderFromSharedPreferences;
/**
@@ -164,6 +168,13 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
int resultCode = intent.getIntExtra(BROADCAST_RESULT_CODE, RESULT_CANCELED);
Bundle result = intent.getBundleExtra(BROADCAST_RESULT_KEY);
String eipRequest = result.getString(EIP_REQUEST);
+ EIP.EIPErrors error = EIP.EIPErrors.UNKNOWN;
+ try {
+ JSONObject jsonObject = new JSONObject(result.getString(EIP.ERRORS));
+ error = EIP.EIPErrors.valueOf(jsonObject.getString(EIP.ERRORID));
+ } catch (Exception e) {
+ //ignore
+ }
if (eipRequest == null) {
return;
}
@@ -172,9 +183,14 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
case EIP_ACTION_START_ALWAYS_ON_VPN:
if (resultCode == RESULT_CANCELED) {
//setup failed
- finishGatewaySetup(false);
- EipCommand.stopVPN(context);
- EipStatus.refresh();
+ if (error == EIP.EIPErrors.NO_MORE_GATEWAYS) {
+ finishGatewaySetup(false);
+ EipCommand.startBlockingVPN(context.getApplicationContext());
+ } else {
+ finishGatewaySetup(false);
+ EipCommand.stopVPN(context);
+ EipStatus.refresh();
+ }
}
break;
case EIP_ACTION_PREPARE_VPN:
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 63a2de0b..1d67cd12 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -64,6 +64,7 @@ import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_IS_RUNNING;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_START;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_ALWAYS_ON_VPN;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_BLOCKING_VPN;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP_BLOCKING_VPN;
import static se.leap.bitmaskclient.Constants.EIP_EARLY_ROUTES;
@@ -185,6 +186,10 @@ public final class EIP extends JobIntentService implements Observer {
case EIP_ACTION_CHECK_CERT_VALIDITY:
checkVPNCertificateValidity();
break;
+ case EIP_ACTION_START_BLOCKING_VPN:
+ disconnect();
+ earlyRoutes();
+ break;
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java
index 2bca5c9b..eb266e3c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipCommand.java
@@ -14,6 +14,7 @@ import se.leap.bitmaskclient.Provider;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_START;
+import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_BLOCKING_VPN;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP;
import static se.leap.bitmaskclient.Constants.EIP_EARLY_ROUTES;
import static se.leap.bitmaskclient.Constants.EIP_N_CLOSEST_GATEWAY;
@@ -62,6 +63,10 @@ public class EipCommand {
execute(context, EIP_ACTION_START, null, baseIntent);
}
+ public static void startBlockingVPN(Context context) {
+ execute(context, EIP_ACTION_START_BLOCKING_VPN);
+ }
+
@VisibleForTesting
public static void startVPN(@NonNull Context context, ResultReceiver resultReceiver) {
execute(context, EIP_ACTION_START, resultReceiver, null);