summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java7
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java15
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java49
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java3
6 files changed, 45 insertions, 46 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 43e0c2aa..ed507de4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -197,9 +197,9 @@ public class EipFragment extends Fragment implements Observer {
eipCommand(Constants.ACTION_START_EIP);
}
- public void stop() {
- Intent intent = new Intent(dashboard.getApplicationContext(), VoidVpnService.class);
- dashboard.stopService(intent);
+ private void stop() {
+ if(eip_status.isConnecting())
+ VoidVpnService.stop();
disconnect();
}
@@ -296,7 +296,6 @@ public class EipFragment extends Fragment implements Observer {
&& !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){
dashboard.showLog();
}
- status_message.setText(dashboard.getString(R.string.eip_state_not_connected));
}
private void adjustSwitch() {
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 5cac4588..3b72a486 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -126,12 +126,8 @@ public final class EIP extends IntentService {
private void stopEIP() {
EipStatus eip_status = EipStatus.getInstance();
int result_code = Activity.RESULT_CANCELED;
- if(eip_status.isConnected() || eip_status.isConnecting()) {
- Intent intent = new Intent();
- intent.setComponent(VoidVpnLauncher.getService());
- stopService(intent);
- result_code = Activity.RESULT_OK;
- }
+ 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/EipStatus.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
index 3b9dad1c..adbbaef3 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
@@ -22,7 +22,6 @@ import android.content.*;
import java.util.*;
import de.blinkt.openvpn.core.*;
-import se.leap.bitmaskclient.EipFragment;
public class EipStatus extends Observable implements VpnStatus.StateListener {
public static String TAG = EipStatus.class.getSimpleName();
@@ -49,6 +48,8 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
updateStatus(state, logmessage, localizedResId, level);
if(isConnected() || isDisconnected()) {
setConnectedOrDisconnected();
+ if(isDisconnected())
+ VoidVpnService.stop();
} else if(isConnecting())
setConnecting();
Log.d(TAG, "update state with level " + level);
@@ -141,10 +142,10 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
VpnStatus.LogItem[] log = VpnStatus.getlogbuffer();
String message = "";
- for (int i = 1; i <= lines && i < log.length; i++) {
- message = log[log.length-i].getString(context);
+ for (int i = 0; i < lines; i++) {
+ message = log[log.length-1].getString(context);
for(int j = 0; j < error_keywords.length; j++)
- if(message.contains(error_keywords[j]))
+ if(message.contains(error_keywords[i]))
result = true;
}
return result;
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
index e7ce74d4..d79d8003 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
@@ -1,7 +1,6 @@
package se.leap.bitmaskclient.eip;
import android.app.Activity;
-import android.content.ComponentName;
import android.content.Intent;
import android.net.VpnService;
import android.os.Bundle;
@@ -10,8 +9,6 @@ public class VoidVpnLauncher extends Activity {
private static final int VPN_USER_PERMISSION = 71;
- private static ComponentName service;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -30,17 +27,11 @@ public class VoidVpnLauncher extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == VPN_USER_PERMISSION) {
if(resultCode == RESULT_OK) {
- Intent intent = new Intent(getApplicationContext(), VoidVpnService.class);
- intent.setAction(Constants.START_BLOCKING_VPN_PROFILE);
- android.util.Log.d(VoidVpnLauncher.class.getSimpleName(), "VoidVpnService starting from Launcher");
-
- service = startService(intent);
+ Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class);
+ void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE);
+ startService(void_vpn_service);
}
}
finish();
}
-
- public static ComponentName getService() {
- return service;
- }
}
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 367a9f1d..0a707ab1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -13,29 +13,42 @@ public class VoidVpnService extends VpnService {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- String action = intent != null ? intent.getAction() : "";
- if (action == Constants.START_BLOCKING_VPN_PROFILE) {
- start();
- }
+ String action = intent != null ? intent.getAction() : "";
+ if (action == Constants.START_BLOCKING_VPN_PROFILE) {
+ new Thread(new Runnable() {
+ public void run() {
+ Builder builder = new Builder();
+ builder.setSession("Blocking until running");
+ builder.addAddress("10.42.0.8",16);
+ builder.addRoute("0.0.0.0", 1);
+ builder.addRoute("192.168.1.0", 24);
+ builder.addDnsServer("10.42.0.1");
+ try {
+ fd = builder.establish();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ android.util.Log.d(TAG, "VoidVpnService set up");
+ }
+ }).run();
+ }
+ return 0;
+ }
- return 0;
+ @Override
+ public void onRevoke() {
+ super.onRevoke();
}
- protected void start() {
- Builder builder = new Builder();
- builder.setSession("Blocking until running");
- builder.addAddress("10.42.0.8", 16);
- builder.addRoute("0.0.0.0", 1);
- builder.addRoute("192.168.1.0", 24);
- builder.addDnsServer("10.42.0.1");
+ public static boolean stop() {
try {
- fd = builder.establish();
- if (fd != null)
- android.util.Log.d(TAG, "VoidVpnService set up");
- else
- android.util.Log.d(TAG, "VoidVpnService failed to set up");
- } catch (Exception e) {
+ if(fd != null)
+ fd.close();
+ return true;
+ } catch (IOException | NullPointerException e) {
+ android.util.Log.d(TAG, "VoidVpnService didn't stop");
e.printStackTrace();
+ return false;
}
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
index c29cc180..5f5dcabd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -148,7 +148,6 @@ public class VpnConfigGenerator {
+ new_line
+ "persist-tun"
+ new_line
- + "auth-retry nointeract"
- + "fragment 1400";
+ + "auth-retry nointeract";
}
}