From 9c4926fd5605f1717f0515a216aad683bb6073af Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 10 May 2013 14:14:37 +0200 Subject: Report ics-openvpn version to server when push-peer-info is used --- src/de/blinkt/openvpn/core/OpenVPNThread.java | 43 +++++++++++++++++--------- src/de/blinkt/openvpn/core/OpenVpnService.java | 14 ++++++++- 2 files changed, 41 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/de/blinkt/openvpn/core/OpenVPNThread.java b/src/de/blinkt/openvpn/core/OpenVPNThread.java index 9d6d8e77..d8fff1dd 100644 --- a/src/de/blinkt/openvpn/core/OpenVPNThread.java +++ b/src/de/blinkt/openvpn/core/OpenVPNThread.java @@ -10,6 +10,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.LinkedList; import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; import android.util.Log; import de.blinkt.openvpn.R; @@ -25,8 +27,9 @@ public class OpenVPNThread implements Runnable { private String mNativeDir; private OpenVpnService mService; private String mDumpPath; + private Map mProcessEnv; - public OpenVPNThread(OpenVpnService service,String[] argv, String nativelibdir) + public OpenVPNThread(OpenVpnService service,String[] argv, Map processEnv, String nativelibdir) { mArgv = argv; mNativeDir = nativelibdir; @@ -43,7 +46,7 @@ public class OpenVPNThread implements Runnable { public void run() { try { Log.i(TAG, "Starting openvpn"); - startOpenVPNThreadArgs(mArgv); + startOpenVPNThreadArgs(mArgv, mProcessEnv); Log.i(TAG, "Giving up"); } catch (Exception e) { e.printStackTrace(); @@ -81,7 +84,7 @@ public class OpenVPNThread implements Runnable { } } - private void startOpenVPNThreadArgs(String[] argv) { + private void startOpenVPNThreadArgs(String[] argv,Map env) { LinkedList argvlist = new LinkedList(); for(String arg:argv) @@ -90,20 +93,14 @@ public class OpenVPNThread implements Runnable { ProcessBuilder pb = new ProcessBuilder(argvlist); // Hack O rama - // Hack until I find a good way to get the real library path - String applibpath = argv[0].replace("/cache/" + VpnProfile.MINIVPN , "/lib"); - - String lbpath = pb.environment().get("LD_LIBRARY_PATH"); - if(lbpath==null) - lbpath = applibpath; - else - lbpath = lbpath + ":" + applibpath; - - if (!applibpath.equals(mNativeDir)) { - lbpath = lbpath + ":" + mNativeDir; - } + String lbpath = genLibraryPath(argv, pb); pb.environment().put("LD_LIBRARY_PATH", lbpath); + + // Add extra variables + for(Entry e:env.entrySet()){ + pb.environment().put(e.getKey(), e.getValue()); + } pb.redirectErrorStream(true); try { mProcess = pb.start(); @@ -133,4 +130,20 @@ public class OpenVPNThread implements Runnable { } + + private String genLibraryPath(String[] argv, ProcessBuilder pb) { + // Hack until I find a good way to get the real library path + String applibpath = argv[0].replace("/cache/" + VpnProfile.MINIVPN , "/lib"); + + String lbpath = pb.environment().get("LD_LIBRARY_PATH"); + if(lbpath==null) + lbpath = applibpath; + else + lbpath = lbpath + ":" + applibpath; + + if (!applibpath.equals(mNativeDir)) { + lbpath = lbpath + ":" + mNativeDir; + } + return lbpath; + } } diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java index d86ae92b..eb6e98d2 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnService.java +++ b/src/de/blinkt/openvpn/core/OpenVpnService.java @@ -3,7 +3,9 @@ package de.blinkt.openvpn.core; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import java.util.Vector; import android.Manifest.permission; @@ -15,6 +17,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; import android.net.ConnectivityManager; import android.net.LocalServerSocket; import android.net.LocalSocket; @@ -323,7 +327,15 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac } else { - processThread = new OpenVPNThread(this, argv,nativelibdir); + HashMap env = new HashMap(); + String version="unknown"; + try { + PackageInfo packageinfo = getPackageManager().getPackageInfo(getPackageName(), 0); + version = packageinfo.versionName; + } catch (NameNotFoundException e) { + } + env.put("UV_ICSOPENVPN_VERSION", version); + processThread = new OpenVPNThread(this, argv, env, nativelibdir); } mProcessThread = new Thread(processThread, "OpenVPNProcessThread"); -- cgit v1.2.3