summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-03-23 14:45:07 +0100
committerParménides GV <parmegv@sdf.org>2015-03-23 14:45:07 +0100
commit7c17d2654d9b6f32580e71e22ea08fca1893aa93 (patch)
treeafe1b4749fb7ea876a783d35d39cefc661d6dc81
parent966ac406322f0c6b36b2fe746cd3f738bd0f5a00 (diff)
Ammend.
-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, 46 insertions, 45 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index ed507de4..43e0c2aa 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);
}
- private void stop() {
- if(eip_status.isConnecting())
- VoidVpnService.stop();
+ public void stop() {
+ Intent intent = new Intent(dashboard.getApplicationContext(), VoidVpnService.class);
+ dashboard.stopService(intent);
disconnect();
}
@@ -296,6 +296,7 @@ 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 3b72a486..5cac4588 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -126,8 +126,12 @@ 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())
- result_code = Activity.RESULT_OK;
+ if(eip_status.isConnected() || eip_status.isConnecting()) {
+ Intent intent = new Intent();
+ intent.setComponent(VoidVpnLauncher.getService());
+ stopService(intent);
+ 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 adbbaef3..3b9dad1c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
@@ -22,6 +22,7 @@ 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();
@@ -48,8 +49,6 @@ 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);
@@ -142,10 +141,10 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
VpnStatus.LogItem[] log = VpnStatus.getlogbuffer();
String message = "";
- for (int i = 0; i < lines; i++) {
- message = log[log.length-1].getString(context);
+ for (int i = 1; i <= lines && i < log.length; i++) {
+ message = log[log.length-i].getString(context);
for(int j = 0; j < error_keywords.length; j++)
- if(message.contains(error_keywords[i]))
+ if(message.contains(error_keywords[j]))
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 d79d8003..e7ce74d4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
@@ -1,6 +1,7 @@
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;
@@ -9,6 +10,8 @@ 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);
@@ -27,11 +30,17 @@ public class VoidVpnLauncher extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == VPN_USER_PERMISSION) {
if(resultCode == RESULT_OK) {
- Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class);
- void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE);
- startService(void_vpn_service);
+ 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);
}
}
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 0a707ab1..367a9f1d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -13,42 +13,29 @@ 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) {
- 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;
- }
+ String action = intent != null ? intent.getAction() : "";
+ if (action == Constants.START_BLOCKING_VPN_PROFILE) {
+ start();
+ }
- @Override
- public void onRevoke() {
- super.onRevoke();
+ return 0;
}
- public static boolean stop() {
+ 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");
try {
- if(fd != null)
- fd.close();
- return true;
- } catch (IOException | NullPointerException e) {
- android.util.Log.d(TAG, "VoidVpnService didn't stop");
+ 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) {
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 5f5dcabd..c29cc180 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java
@@ -148,6 +148,7 @@ public class VpnConfigGenerator {
+ new_line
+ "persist-tun"
+ new_line
- + "auth-retry nointeract";
+ + "auth-retry nointeract"
+ + "fragment 1400";
}
}