summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-17 12:41:53 +0100
committerParménides GV <parmegv@sdf.org>2014-12-17 12:41:53 +0100
commit0cc14918f54619fd39ef4297ddb9564ba981772a (patch)
tree40cb2d14f67cf22a2b4a516403c02248cd5c0a66
parent2571d03aca9f240017dd1f00e0963abc13b35890 (diff)
parentd58b67f214bdd206cae28911073e450ec593f3dc (diff)
Merge branch 'develop' into release-0.8.1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java20
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java24
4 files changed, 38 insertions, 10 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index cca9c63c..e32dbdee 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -292,7 +292,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
if (preferences.getBoolean(Constants.AUTHED_EIP, false)) {
logOut();
}
- eip_fragment.stopEIP();
+ eip_fragment.askToStopEIP();
}
preferences.edit().clear().apply();
startActivityForResult(new Intent(this,ConfigurationWizard.class), SWITCH_PROVIDER);
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 92d2a8bd..420da7a1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -26,6 +26,7 @@ import de.blinkt.openvpn.activities.DisconnectVPN;
import se.leap.bitmaskclient.eip.Constants;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
+import se.leap.bitmaskclient.eip.VoidVpnService;
public class EipFragment extends Fragment implements Observer {
@@ -160,7 +161,7 @@ public class EipFragment extends Fragment implements Observer {
if(eip_status.isConnecting()) {
askPendingStartCancellation();
} else if(eip_status.isConnected()) {
- stopEIP();
+ askToStopEIP();
}
}
@@ -171,7 +172,7 @@ public class EipFragment extends Fragment implements Observer {
.setPositiveButton((R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- stopEIP();
+ askToStopEIP();
}
})
.setNegativeButton(parent_activity.getString(R.string.no), new DialogInterface.OnClickListener() {
@@ -197,7 +198,15 @@ public class EipFragment extends Fragment implements Observer {
eipCommand(Constants.ACTION_START_EIP);
}
- protected void stopEIP() {
+ private void stopEIP() {
+ if(eip_status.isConnecting())
+ VoidVpnService.stop();
+ Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
+ parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
+ eip_status.setDisconnecting();
+ }
+
+ protected void askToStopEIP() {
hideProgressBar();
String status = parent_activity.getString(R.string.eip_state_not_connected);
@@ -306,14 +315,13 @@ public class EipFragment extends Fragment implements Observer {
case Activity.RESULT_OK:
break;
case Activity.RESULT_CANCELED:
+
break;
}
} else if (request.equals(Constants.ACTION_STOP_EIP)) {
switch (resultCode){
case Activity.RESULT_OK:
- Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
- parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
- eip_status.setDisconnecting();
+ stopEIP();
break;
case Activity.RESULT_CANCELED:
break;
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 7017e874..3d3070c8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -149,7 +149,7 @@ public final class EIP extends IntentService {
EipStatus eip_status = EipStatus.getInstance();
Log.d(TAG, "stopEip(): eip is connected? " + eip_status.isConnected());
int result_code = Activity.RESULT_CANCELED;
- if(eip_status.isConnected())
+ if(eip_status.isConnected() || eip_status.isConnecting())
result_code = Activity.RESULT_OK;
tellToReceiver(ACTION_STOP_EIP, result_code);
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index a6f9fe76..0c773208 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -2,14 +2,18 @@ package se.leap.bitmaskclient.eip;
import android.content.Intent;
import android.net.VpnService;
+import android.os.ParcelFileDescriptor;
+
+import java.io.IOException;
public class VoidVpnService extends VpnService {
static final String TAG = VoidVpnService.class.getSimpleName();
+ static ParcelFileDescriptor fd;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- String action = intent.getAction();
+ String action = intent != null ? intent.getAction() : "";
if (action == Constants.START_BLOCKING_VPN_PROFILE) {
new Thread(new Runnable() {
public void run() {
@@ -20,7 +24,7 @@ public class VoidVpnService extends VpnService {
builder.addRoute("192.168.1.0", 24);
builder.addDnsServer("10.42.0.1");
try {
- builder.establish();
+ fd = builder.establish();
} catch (Exception e) {
e.printStackTrace();
}
@@ -30,4 +34,20 @@ public class VoidVpnService extends VpnService {
}
return 0;
}
+
+ @Override
+ public void onRevoke() {
+ super.onRevoke();
+ }
+
+ public static boolean stop() {
+ try {
+ fd.close();
+ return true;
+ } catch (IOException | NullPointerException e) {
+ android.util.Log.d(TAG, "VoidVpnService didn't stop");
+ e.printStackTrace();
+ return false;
+ }
+ }
}