How to extend VpnService to open an L2TP/IPSEC connection in android programmatically?

非 Y 不嫁゛ 提交于 2019-12-13 15:23:38

问题


I am looking to implement a solution to open a L2TP/IPSEC connection from the android application so I can simply pass the server ip, pre-shared key, username and password and so the device is connected to this VPN server

I looked here https://developer.android.com/reference/android/net/VpnService.html that we need to extend and build our own VPN solutions to do that.

Is there any available solutions for that so we can use it instead of reinventing the wheel?

I tried the below implementations of VpnService but none of them worked for me

  • https://android.googlesource.com/platform/development/+/master/samples/ToyVpn/src/com/example/android/toyvpn
  • https://pomgit.com/limeysoft/L2TP-VPN/tree/master/app

And tried this

  • https://alvinalexander.com/java/jwarehouse/android/vpn/java/android/net/vpn/

and got the below error

mtpd: Start VPN daemon: mtpd W/libc: Set property "ctl.start" to "mtpd" Unable to set property "ctl.start" to "mtpd": connection failed; errno=13 (Permission denied) E/SysPropJNI: SystemProperties_set key:ctl.start,val:mtpd W/System.err: java.io.IOException: cannot start service: mtpd W/System.err: at com.mega.speed.vpn.DaemonProxy.start(DaemonProxy.java:58) W/System.err: at com.mega.speed.vpn.VpnDaemons.startDaemon(VpnDaemons.java:92) at com.mega.speed.vpn.VpnDaemons.startMtpd(VpnDaemons.java:113) at com.mega.speed.vpn.VpnDaemons.startL2tp(VpnDaemons.java:36) W/System.err: at com.mega.speed.vpn.L2tpService.connect(L2tpService.java:16) at com.mega.speed.fragments.HotspotFragment.onCreateView(HotspotFragment.java:125) W/System.err: at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) W/System.err: at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) W/System.err: at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) W/System.err: at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) W/System.err: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733) at android.os.Handler.handleCallback(Handler.java:808) W/System.err:
at android.os.Handler.dispatchMessage(Handler.java:101) at android.os.Looper.loop(Looper.java:166) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7529) W/System.err: at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

来源:https://stackoverflow.com/questions/56966665/how-to-extend-vpnservice-to-open-an-l2tp-ipsec-connection-in-android-programmati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!