aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-08-08 12:25:17 +0200
committerTobias Brunner <tobias@strongswan.org>2012-08-13 11:00:27 +0200
commit1b8877727c1c228fb9411daf1cec9a63d83c4d2c (patch)
treee82777e7505478f6998c6962ee56100e85d8d942
parentd4f76751992579d9fcbb636fff0ed4429bbfc75e (diff)
downloadstrongswan-1b8877727c1c228fb9411daf1cec9a63d83c4d2c.tar.bz2
strongswan-1b8877727c1c228fb9411daf1cec9a63d83c4d2c.tar.xz
Add a function to disconnect any current VPN connection
-rw-r--r--src/frontends/android/src/org/strongswan/android/logic/VpnStateService.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/frontends/android/src/org/strongswan/android/logic/VpnStateService.java b/src/frontends/android/src/org/strongswan/android/logic/VpnStateService.java
index 2e2bce541..1c14cb601 100644
--- a/src/frontends/android/src/org/strongswan/android/logic/VpnStateService.java
+++ b/src/frontends/android/src/org/strongswan/android/logic/VpnStateService.java
@@ -22,6 +22,7 @@ import java.util.concurrent.Callable;
import org.strongswan.android.data.VpnProfile;
import android.app.Service;
+import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
@@ -146,6 +147,24 @@ public class VpnStateService extends Service
}
/**
+ * Disconnect any existing connection and shutdown the daemon, the
+ * VpnService is not stopped but it is reset so new connections can be
+ * started.
+ */
+ public void disconnect()
+ {
+ /* as soon as the TUN device is created by calling establish() on the
+ * VpnService.Builder object the system binds to the service and keeps
+ * bound until the file descriptor of the TUN device is closed. thus
+ * calling stopService() here would not stop (destroy) the service yet,
+ * instead we call startService() with an empty Intent which shuts down
+ * the daemon (and closes the TUN device, if any) */
+ Context context = getApplicationContext();
+ Intent intent = new Intent(context, CharonVpnService.class);
+ context.startService(intent);
+ }
+
+ /**
* Update state and notify all listeners about the change. By using a Handler
* this is done from the main UI thread and not the initial reporter thread.
* Also, in doing the actual state change from the main thread, listeners