diff options
author | Arne Schwabe <arne@rfc2549.org> | 2012-05-09 02:06:17 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2012-05-09 02:06:17 +0200 |
commit | 95d6e0331e2db3404475efb91b5a7535b843099a (patch) | |
tree | 8612dfd7101b3fe8b527367090e4818184b6bb2d /src/de/blinkt/openvpn/OpenVPNThread.java | |
parent | 379ae9173874ebe7d3811f0fde9b75221c349386 (diff) |
Openvpn as external external program is coming nearer ....
Diffstat (limited to 'src/de/blinkt/openvpn/OpenVPNThread.java')
-rw-r--r-- | src/de/blinkt/openvpn/OpenVPNThread.java | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/de/blinkt/openvpn/OpenVPNThread.java b/src/de/blinkt/openvpn/OpenVPNThread.java index a5b3e5e4..a8cb8430 100644 --- a/src/de/blinkt/openvpn/OpenVPNThread.java +++ b/src/de/blinkt/openvpn/OpenVPNThread.java @@ -1,6 +1,12 @@ package de.blinkt.openvpn;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Arrays;
+import java.util.LinkedList;
import android.util.Log;
@@ -8,12 +14,17 @@ public class OpenVPNThread implements Runnable { private static final String TAG = "OpenVPN";
private OpenVpnService mService;
private String[] mArgv;
+ private Process mProcess;
public OpenVPNThread(OpenVpnService service,String[] argv)
{
mService = service;
mArgv = argv;
}
+
+ public void stopProcess() {
+ mProcess.destroy();
+ }
@Override
public void run() {
@@ -35,12 +46,9 @@ public class OpenVPNThread implements Runnable { OpenVPN.logMessage(0, "argv:" , Arrays.toString(mArgv));
- OpenVPN.startOpenVPNThreadArgs(mArgv);
-
+ startOpenVPNThreadArgs(mArgv);
-
- // Sleep for a while. This also checks if we got interrupted.
- Thread.sleep(3000);
+
//}
Log.i(TAG, "Giving up");
} catch (Exception e) {
@@ -60,4 +68,36 @@ public class OpenVPNThread implements Runnable { Log.i(TAG, "Exiting");
}
}
+
+ private void startOpenVPNThreadArgs(String[] argv) {
+ LinkedList<String> argvlist = new LinkedList<String>();
+
+ for(String arg:argv)
+ argvlist.add(arg);
+
+ ProcessBuilder pb = new ProcessBuilder(argvlist);
+ pb.redirectErrorStream(true);
+ try {
+ mProcess = pb.start();
+ // Close the output, since we don't need it
+ mProcess.getOutputStream().close();
+ InputStream in = mProcess.getInputStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+
+
+ while(true) {
+ String logline = br.readLine();
+ if(logline==null)
+ return;
+ OpenVPN.logMessage(0, "P:", logline);
+ }
+
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ stopProcess();
+ }
+
+
+ }
}
|