From c1059af0bc5589cc9afc20de2fab093a1cb5c1a5 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Fri, 28 Nov 2014 22:50:52 +0100 Subject: Implement protect call, (closes issue #306) --HG-- extra : rebase_source : ccdfb215c4277456c41aaad0e02d2de230ce1017 --- .../aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl | 6 ++++++ .../java/de/blinkt/openvpn/api/ExternalOpenVPNService.java | 14 ++++++++++++++ .../aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/main/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl b/main/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl index 06545bd7..d0791a4a 100644 --- a/main/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl +++ b/main/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl @@ -49,5 +49,11 @@ interface IOpenVPNAPIService { /** Remove a profile by UUID */ void removeProfile (String profileUUID); + + /** Request a socket to be protected as a VPN socket would be. Useful for creating + * a helper socket for an app controlling OpenVPN + * Before calling this function you should make sure OpenVPN for Android may actually + * this function by checking if prepareVPNService returns null; */ + boolean protectSocket(in ParcelFileDescriptor fd); } \ No newline at end of file diff --git a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java index ec38b7ce..16f7abcf 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/api/ExternalOpenVPNService.java @@ -20,9 +20,11 @@ import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.Message; +import android.os.ParcelFileDescriptor; import android.os.RemoteCallbackList; import android.os.RemoteException; +import java.io.FileDescriptor; import java.io.IOException; import java.io.StringReader; import java.lang.ref.WeakReference; @@ -209,6 +211,18 @@ public class ExternalOpenVPNService extends Service implements StateListener { pm.removeProfile(ExternalOpenVPNService.this, vp); } + @Override + public boolean protectSocket(ParcelFileDescriptor pfd) throws RemoteException { + checkOpenVPNPermission(); + try { + boolean success= mService.protect(pfd.getFd()); + pfd.close(); + return success; + } catch (IOException e) { + throw new RemoteException(e.getMessage()); + } + } + @Override public Intent prepare(String packagename) { diff --git a/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl b/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl index 06545bd7..d0791a4a 100644 --- a/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl +++ b/remoteExample/src/main/aidl/de/blinkt/openvpn/api/IOpenVPNAPIService.aidl @@ -49,5 +49,11 @@ interface IOpenVPNAPIService { /** Remove a profile by UUID */ void removeProfile (String profileUUID); + + /** Request a socket to be protected as a VPN socket would be. Useful for creating + * a helper socket for an app controlling OpenVPN + * Before calling this function you should make sure OpenVPN for Android may actually + * this function by checking if prepareVPNService returns null; */ + boolean protectSocket(in ParcelFileDescriptor fd); } \ No newline at end of file -- cgit v1.2.3