How to programmatically create a new VPN interface with Android 4.0?

后端 未结 2 1157
鱼传尺愫
鱼传尺愫 2020-12-02 09:34

I\'d like to know whether it\'s possible to create a VPN interface programmatically with the new VPN APIs in Android 4.0. I\'ve looked through http://developer.android.com/r

2条回答
  •  北海茫月
    2020-12-02 09:54

    It appears that this is handled internally via the com.android.settings.vpn2.VpnDialog (and related) classes, which basically do KeyStore.getInstance().put("VPN_[VPN ID]", [encoded VpnProfile object]>) -- which then causes files with names like "/data/misc/vpn/1000_VPN_[VPN ID]" to get created (where 1000 is apparently the system process ID).

    Using reflection (or one of the hacks to access the hidden / internal APIs) you can do this yourself, but because your process will not be running as the system process, the system VPN browser won't see them.

    However, according to this (http://code.google.com/p/android/issues/detail?id=8915), there is at least one app that does this without a rooted phone, but the source doesn't seem to be available...so perhaps there's some way to do this that I can't figure out -- I'd definitely be interested if there is.

    P.S. - Here's another similar question (though it's specifically asking about using a rooted device): Create VPN profile on Android

提交回复
热议问题