android: Use a specific action to disconnect from the VPN
This commit is contained in:
+17
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012-2016 Tobias Brunner
|
* Copyright (C) 2012-2017 Tobias Brunner
|
||||||
* Copyright (C) 2012 Giuliano Grassi
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
* Copyright (C) 2012 Ralf Sager
|
* Copyright (C) 2012 Ralf Sager
|
||||||
* HSR Hochschule fuer Technik Rapperswil
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
@@ -64,6 +64,7 @@ import java.util.Locale;
|
|||||||
public class CharonVpnService extends VpnService implements Runnable, VpnStateService.VpnStateListener
|
public class CharonVpnService extends VpnService implements Runnable, VpnStateService.VpnStateListener
|
||||||
{
|
{
|
||||||
private static final String TAG = CharonVpnService.class.getSimpleName();
|
private static final String TAG = CharonVpnService.class.getSimpleName();
|
||||||
|
public static final String DISCONNECT_ACTION = "org.strongswan.android.CharonVpnService.DISCONNECT";
|
||||||
public static final String LOG_FILE = "charon.log";
|
public static final String LOG_FILE = "charon.log";
|
||||||
public static final int VPN_STATE_NOTIFICATION_ID = 1;
|
public static final int VPN_STATE_NOTIFICATION_ID = 1;
|
||||||
|
|
||||||
@@ -119,18 +120,25 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe
|
|||||||
{
|
{
|
||||||
if (intent != null)
|
if (intent != null)
|
||||||
{
|
{
|
||||||
Bundle bundle = intent.getExtras();
|
if (DISCONNECT_ACTION.equals(intent.getAction()))
|
||||||
VpnProfile profile = null;
|
|
||||||
if (bundle != null)
|
|
||||||
{
|
{
|
||||||
profile = mDataSource.getVpnProfile(bundle.getLong(VpnProfileDataSource.KEY_ID));
|
setNextProfile(null);
|
||||||
if (profile != null)
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
VpnProfile profile = null;
|
||||||
|
if (bundle != null)
|
||||||
{
|
{
|
||||||
String password = bundle.getString(VpnProfileDataSource.KEY_PASSWORD);
|
profile = mDataSource.getVpnProfile(bundle.getLong(VpnProfileDataSource.KEY_ID));
|
||||||
profile.setPassword(password);
|
if (profile != null)
|
||||||
|
{
|
||||||
|
String password = bundle.getString(VpnProfileDataSource.KEY_PASSWORD);
|
||||||
|
profile.setPassword(password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
setNextProfile(profile);
|
||||||
}
|
}
|
||||||
setNextProfile(profile);
|
|
||||||
}
|
}
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2012-2013 Tobias Brunner
|
* Copyright (C) 2012-2017 Tobias Brunner
|
||||||
* Hochschule fuer Technik Rapperswil
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
@@ -197,10 +197,11 @@ public class VpnStateService extends Service
|
|||||||
* VpnService.Builder object the system binds to the service and keeps
|
* VpnService.Builder object the system binds to the service and keeps
|
||||||
* bound until the file descriptor of the TUN device is closed. thus
|
* bound until the file descriptor of the TUN device is closed. thus
|
||||||
* calling stopService() here would not stop (destroy) the service yet,
|
* calling stopService() here would not stop (destroy) the service yet,
|
||||||
* instead we call startService() with an empty Intent which shuts down
|
* instead we call startService() with a specific action which shuts down
|
||||||
* the daemon (and closes the TUN device, if any) */
|
* the daemon (and closes the TUN device, if any) */
|
||||||
Context context = getApplicationContext();
|
Context context = getApplicationContext();
|
||||||
Intent intent = new Intent(context, CharonVpnService.class);
|
Intent intent = new Intent(context, CharonVpnService.class);
|
||||||
|
intent.setAction(CharonVpnService.DISCONNECT_ACTION);
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user