Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

root - Create VPN profile on Android

Is it possible to programmatically create VPN profile on Android (assuming that I have a rooted device)?

If is possible, how?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should look at the com.android.settings.vpn2 package. There it uses the @hidden KeyStore methods to manipulate VPNs:

  • KeyStore.getInstance().saw(Credentials.VPN) returns an array of String VPN IDs

  • VpnProfile.decode(KeyStore.getInstance().get(Credentials.VPN + vpn_id)) gets the VPN configuration data for the given VPN ID and decodes it as a VpnProfile object.

  • VpnProfile.put(Credentials.VPN + vpn_id, someVpnProfileInstance.encode()) will create/update a VPN connection with the given ID using the settings in the VpnProfile instance.

However, you will need to execute this as the system process -- otherwise, the KeyStore instance you get will not be connected to the one that the OS uses.

If there is a way to do this without a rooted device, I'd be interested in knowing how...

P.S. - There's a similar question here: How to programmatically create a new VPN interface with Android 4.0?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...