summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/OpenVpnService.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-05-10 10:53:21 +0200
committerArne Schwabe <arne@rfc2549.org>2012-05-10 10:53:21 +0200
commit11973ef9a293ca0eaa11e760a800071042c5a7bb (patch)
treed6f1f285dc422b51dc3374138ec0fff36fd30193 /src/de/blinkt/openvpn/OpenVpnService.java
parenta77da4c2fed8bcfe12d63b804d4f07c7fc978c9d (diff)
parentcc7f23dcefea2e255dcfe0f38031a3840288aafa (diff)
Version 0.5.2
Fix minivpn vs openvpn. (closes issue #16) If minivpn binary is already available don't write it (closes issue #15)
Diffstat (limited to 'src/de/blinkt/openvpn/OpenVpnService.java')
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index a3df9fde..9f0f7326 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -17,9 +17,14 @@
package de.blinkt.openvpn;
import java.io.IOException;
+import java.util.List;
import java.util.Vector;
+import android.R.anim;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
@@ -117,11 +122,10 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
- private LocalSocket openManagmentInterface() {
+ private LocalSocket openManagmentInterface(int tries) {
// Could take a while to open connection
String socketname = (getCacheDir().getAbsolutePath() + "/" + "mgmtsocket");
LocalSocket sock = new LocalSocket();
- int tries = 8;
while(tries > 0 && !sock.isConnected()) {
try {
@@ -142,6 +146,14 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ // Extract information from the intent.
+ String prefix = getPackageName();
+ String[] argv = intent.getStringArrayExtra(prefix + ".ARGV");
+
+ String profileUUID = intent.getStringExtra(prefix + ".profileUUID");
+ mProfile = ProfileManager.get(profileUUID);
+
+
// The handler is only used to show messages.
if (mHandler == null) {
mHandler = new Handler(this);
@@ -164,13 +176,19 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
}
}
+ // See if there is a managment socket we can connect to and kill the process too
+ LocalSocket mgmtsocket = openManagmentInterface(1);
+ if(mgmtsocket!=null) {
+ // Fire and forget :)
+ new OpenVpnManagementThread(mProfile,mgmtsocket,this).managmentCommand("signal SIGINT\n");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+ //checkForRemainingMiniVpns();
+ }
- // Extract information from the intent.
- String prefix = getPackageName();
- String[] argv = intent.getStringArrayExtra(prefix + ".ARGV");
- String profileUUID = intent.getStringExtra(prefix + ".profileUUID");
- mProfile = ProfileManager.get(profileUUID);
// Start a new session by creating a new thread.
@@ -181,7 +199,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
// Open the Management Interface
- LocalSocket mgmtsocket = openManagmentInterface();
+ mgmtsocket = openManagmentInterface(8);
if(mgmtsocket!=null) {
// start a Thread that handles incoming messages of the managment socket
@@ -197,6 +215,23 @@ public class OpenVpnService extends VpnService implements Handler.Callback {
+ private void checkForRemainingMiniVpns() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ if (manager == null)
+ return;
+ List<RunningAppProcessInfo> service= manager.getRunningAppProcesses();
+ // Does not return the minivpn binarys :S
+ for(RunningAppProcessInfo rapi:service){
+ if(rapi.processName.equals("minivpn"))
+ android.os.Process.killProcess(rapi.pid);
+ }
+ }
+
+
+
+
+
+
@Override
public void onDestroy() {
if (mServiceThread != null) {