From: Tobias Brunner Date: Wed, 8 Aug 2012 10:25:17 +0000 (+0200) Subject: Add a function to disconnect any current VPN connection X-Git-Tag: 5.0.1~210^2~46 X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=commitdiff_plain;h=1b8877727c1c228fb9411daf1cec9a63d83c4d2c;hp=d4f76751992579d9fcbb636fff0ed4429bbfc75e Add a function to disconnect any current VPN connection --- 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 2e2bce5..1c14cb6 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