9

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

If is possible, how?

Thanks.

jorjap
  • 358
  • 3
  • 7
  • 20

1 Answers1

10

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?

Community
  • 1
  • 1
  • 1
    This can be done without rooting the device. Simply gain access to the hidden API and the rest is just a google away. – slott Jun 24 '13 at 19:13
  • 1
    @slott how to gain access to the hidden API ? – Shamis Shukoor Aug 03 '13 at 09:36
  • 1
    http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/ – slott Aug 08 '13 at 16:12
  • I tried to follow the blog but it seems i am unable to extract classes.dex from framework.jar emulator as well as devices didnt have it even rooted one.. did i miss something obvious ?? – amIT Jul 02 '15 at 09:00