Add a function to disconnect any current VPN connection

This commit is contained in:
Tobias Brunner
2012-08-13 11:00:27 +02:00
parent d4f7675199
commit 1b8877727c
@@ -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;
@@ -145,6 +146,24 @@ public class VpnStateService extends Service
return mError;
}
/**
* 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.