Vpn

183 views
Skip to first unread message

Adam

unread,
Sep 19, 2020, 4:48:18 PM9/19/20
to Automate
Hi, I would like to detect when my VPN turns off. I tried to use 'network type?' but it does not seem to work. (i've tried including my connection i.e. : VPN + Wifi but nothing changes, it only detects if my wifi goes off)

I've read a post very similar to mine where the dev said to use 'Broadcast receive' with "android.net.conn.CONNECTIVITY_CHANGE" in action. This does work to detect if my VPN went off but it seems to also detects other stuffs which are not my VPN turning off? (It triggered a few times when my vpn was still well connected. The connected time on the vpn was saying like 40hours or so). 

So I was wondering if there are any better solutions for me to detect VPN state changes.

Henrik "The Developer" Lindqvist

unread,
Sep 20, 2020, 3:25:19 PM9/20/20
to Automate
For what i know there's no way to detect anything about VPN, there's no public APIs for it.

Raffaele Ziraldo

unread,
Jan 20, 2022, 3:12:37 AM1/20/22
to Automate
MacroDroid app is able to detect if VPN is off or on without root access, so something to check it there is.

P. Andreas Schmidt, IVE

unread,
Jan 29, 2022, 1:43:51 PM1/29/22
to Automate
Hi there, I ain't no expert at all, but I just tried the broadcast thingy out, and it worked for me, too. Perhaps the "solution" is to filter the connections, since it will not just broadcast (as far as I understand) about the VPN connection but also WiFi and Data. In my case in the dictionary the first key is the networkType and WiFi was 0, Data 1 and the VPN 17. You should do some tests there and find out which is which on your device and filter just the ones regarding your VPN. The message will also say if the "agend disconnected" (thus turned off) or only the state, no message (meaning turned on). At least that's what happened on mine (LG Velvet 5G latest Automate, Android 11).
If you turn the system setting "Always On VPN" off, it will turn off your VPN, which will cause a broadcast. But you can catch separately if this setting is changed (experiment with the settings finder flow). When the setting is changed you'll also know which VPN is always on.
The downside to this approach is you'll only know when something changes. You cannot request the current state by this. You'll probably need run some ADB shell command ... But like I said I'm no expert on this at all, so if you're looking for that, too, you'll have to keep digging. 
Something else that might be worth looking into is current "Private DNS" setting, in case that changes when your VPN turns on/off? Again, use the settings finder flow and see what happens when you manually (de)activate your vpn. 
A last option I can think of would be this. I use Blokada and they have a tasker plugin which at the moment only allows you to run a start and stop command. I've also used Rethink DNS, but it hasn't got me quite convinced yet. But I had also written to them suggesting a Tasker Plugin and they liked it and would look into it. Dunno what's your VPN, but perhaps a feature request is possible? A Tasker Plugin with the event of changing state... at least. Asking them won't cost you anything.

Hope this helps!
P.S. Only now do I realize that the original post over 2 years old is! So probably you've figuered all this already out... and come up with a better solution? Be interesting
Reply all
Reply to author
Forward
0 new messages