summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java11
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java71
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java10
3 files changed, 59 insertions, 33 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java
index 85c1d526..2911fb1e 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNManagement.java
@@ -16,18 +16,19 @@ public interface OpenVPNManagement {
screenOff
}
- int mBytecountInterval =2;
+ int mBytecountInterval = 2;
- void reconnect();
+ void reconnect();
- void pause(pauseReason reason);
+ void pause(pauseReason reason);
- void resume();
+ void resume();
/**
* @param replaceConnection True if the VPN is connected by a new connection.
+ * @return true if there was a process that has been send a stop signal
*/
- boolean stopVPN(boolean replaceConnection);
+ boolean stopVPN(boolean replaceConnection);
/*
* Rebind the interface
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index d2a21946..536abdc2 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -87,6 +87,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
private final Object mProcessLock = new Object();
private Handler guiHandler;
private Toast mlastToast;
+ private Runnable mOpenVPNThread;
// From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
public static String humanReadableByteCount(long bytes, boolean mbit) {
@@ -132,6 +133,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
VpnStatus.removeByteCountListener(this);
unregisterDeviceStateReceiver();
ProfileManager.setConntectedVpnProfileDisconnected(this);
+ mOpenVPNThread = null;
if (!mStarting) {
stopForeground(!mNotificationAlwaysVisible);
@@ -420,24 +422,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
// Set a flag that we are starting a new VPN
mStarting = true;
// Stop the previous session by interrupting the thread.
- if (mManagement != null && mManagement.stopVPN(true))
- // an old was asked to exit, wait 1s
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //ignore
- }
- synchronized (mProcessLock) {
- if (mProcessThread != null) {
- mProcessThread.interrupt();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- //ignore
- }
- }
- }
+ stopOldOpenVPNProcess();
// An old running VPN should now be exited
mStarting = false;
@@ -448,10 +434,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
if (!"ovpn3".equals(BuildConfig.FLAVOR))
mOvpn3 = false;
-
// Open the Management Interface
if (!mOvpn3) {
-
// start a Thread that handles incoming messages of the managment socket
OpenVpnManagementThread ovpnManagementThread = new OpenVpnManagementThread(mProfile, this);
if (ovpnManagementThread.openManagementInterface(this)) {
@@ -467,7 +451,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
}
Runnable processThread;
- if (mOvpn3) {
+ if (mOvpn3)
+
+ {
OpenVPNManagement mOpenVPN3 = instantiateOpenVPN3Core();
processThread = (Runnable) mOpenVPN3;
@@ -477,22 +463,53 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
} else {
HashMap<String, String> env = new HashMap<>();
processThread = new OpenVPNThread(this, argv, env, nativeLibraryDirectory);
+ mOpenVPNThread = processThread;
}
- synchronized (mProcessLock) {
+ synchronized (mProcessLock)
+
+ {
mProcessThread = new Thread(processThread, "OpenVPNProcessThread");
mProcessThread.start();
}
new Handler(getMainLooper()).post(new Runnable() {
- @Override
- public void run() {
- if (mDeviceStateReceiver != null)
- unregisterDeviceStateReceiver();
+ @Override
+ public void run() {
+ if (mDeviceStateReceiver != null)
+ unregisterDeviceStateReceiver();
- registerDeviceStateReceiver(mManagement);
+ registerDeviceStateReceiver(mManagement);
+ }
+ }
+
+ );
+ }
+
+ private void stopOldOpenVPNProcess() {
+ if (mManagement != null) {
+ if (mOpenVPNThread!=null)
+ ((OpenVPNThread) mOpenVPNThread).setReplaceConnection();
+ if (mManagement.stopVPN(true)) {
+ // an old was asked to exit, wait 1s
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ }
+ }
+
+ synchronized (mProcessLock) {
+ if (mProcessThread != null) {
+ mProcessThread.interrupt();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ //ignore
+ }
}
- });
+ }
}
private OpenVPNManagement instantiateOpenVPN3Core() {
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
index fabe7e3e..a70e71f2 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNThread.java
@@ -46,6 +46,7 @@ public class OpenVPNThread implements Runnable {
private String mDumpPath;
private Map<String, String> mProcessEnv;
private boolean mBrokenPie = false;
+ private boolean mNoProcessExitStatus = false;
public OpenVPNThread(OpenVPNService service, String[] argv, Map<String, String> processEnv, String nativelibdir) {
mArgv = argv;
@@ -58,6 +59,11 @@ public class OpenVPNThread implements Runnable {
mProcess.destroy();
}
+ void setReplaceConnection()
+ {
+ mNoProcessExitStatus=true;
+ }
+
@Override
public void run() {
try {
@@ -95,7 +101,9 @@ public class OpenVPNThread implements Runnable {
}
- VpnStatus.updateStateString("NOPROCESS", "No process running.", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED);
+ if (!mNoProcessExitStatus)
+ VpnStatus.updateStateString("NOPROCESS", "No process running.", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED);
+
if (mDumpPath != null) {
try {
BufferedWriter logout = new BufferedWriter(new FileWriter(mDumpPath + ".log"));