Connect openvpn on android via am command

1.1k views Asked by At

I have android 6.0.1 with OpenVPN Connect 3.2.5.(7182) installed on it and trying to figure out how to connect to vpn with specified profile using adb and android am command. I found some "Tasker instructions" (don't even know what is it exactly) on OpenVPN website and it looks like this:

1. CONNECT
Action: net.openvpn.openvpn.CONNECT
OR
Action: android.intent.action.VIEW
Cat: None
Mime Type: {blank}
Data: {blank}
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME:AS {your_profile_name} (if your profile was downloaded from URL)
OR
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME:PC {your_profile_name} (if your profile was imported via File)
Extra: net.openvpn.openvpn.AUTOCONNECT:true
Package: net.openvpn.openvpn
Class: net.openvpn.unified.MainActivity
Target: Activity

2. DISCONNECT
Action: net.openvpn.openvpn.DISCONNECT
Cat: None
Mime Type: {blank}
Data: {blank}
Extra: net.openvpn.openvpn.STOP:true
Extra: {blank}
Extra: {blank}
Package: net.openvpn.openvpn
Class: net.openvpn.unified.MainActivity
Target: Activity

How can I turn it to adb shell am start ... command? Tried something like:

am start -n net.openvpn.openvpn/net.openvpn.unified.MainActivity \
-a net.openvpn.openvpn.CONNECT \
--es net.openvpn.openvpn.APP_SECTION PC \
--es net.openvpn.openvpn.AUTOSTART_PROFILE_NAME "PC my_profile_name" \
--ez net.openvpn.openvpn.AUTOCONNECT true

but it only opens OpenVPN app and does not connect anywhere.

Please help.

1

There are 1 answers

0
rysson On

Yes, yes, yes! Thank you very much.

I guess you solve this problem a thousand times, I've been searching solution for last three days. I've missed your booleans.

This is working for me:

am start \
  -a android.intent.action.VIEW \
  -n net.openvpn.openvpn/net.openvpn.unified.MainActivity \
  -e net.openvpn.openvpn.AUTOSTART_PROFILE_NAME vpn.myserver.example.com \
  --ez net.openvpn.openvpn.AUTOCONNECT true
am start \
  -a android.intent.action.VIEW \
  -n net.openvpn.openvpn/net.openvpn.unified.MainActivity \
  --ez net.openvpn.openvpn.STOP true