在Android上创建VPN配置文件

时间:2012-03-15 10:56:22

标签: android root vpn

是否可以在Android上以编程方式创建VPN配置文件(假设我有一个root设备)?

如果可能,怎么样?

感谢。

1 个答案:

答案 0 :(得分:9)

您应该查看com.android.settings.vpn2包。它使用@hidden KeyStore方法来操纵VPN:

  • KeyStore.getInstance().saw(Credentials.VPN)返回String VPN ID数组

  • VpnProfile.decode(KeyStore.getInstance().get(Credentials.VPN + vpn_id))获取给定VPN ID的VPN配置数据,并将其解码为VpnProfile对象。

  • VpnProfile.put(Credentials.VPN + vpn_id, someVpnProfileInstance.encode())将使用VpnProfile实例中的设置创建/更新具有给定ID的VPN连接。

但是,您需要将此作为系统进程执行 - 否则,您获得的KeyStore实例将不会连接到操作系统使用的实例。

如果有办法没有一个有根设备,我有兴趣知道如何...

P.S。 - 这里有一个类似的问题:How to programmatically create a new VPN interface with Android 4.0?

相关问题