Quantcast
Channel: Active questions tagged adb - Android Enthusiasts Stack Exchange
Viewing all articles
Browse latest Browse all 357

How to enable/disable VPN via adb/termux/terminal?

$
0
0

I have a VPN configured on my android device running Lineage OS 18.1 (Android 11). I'm not using any third party apps, I'm simply using the standard Android settings to specify my VPN login data etc.

Now I'm looking for a simple way to enable7disable the VPN connection form the terminal without disruption.

I found a hacky way to do it by launching the VPN settings activity and then sending a bunch of key events to click on the connect/disconnect button.

Connect:

am start -a android.intent.action.MAIN -n com.android.settings/.Settings\$VpnSettingsActivity && input keyevent 20 && input keyevent 23 && input keyevent 61 && input keyevent 61 && input keyevent 61 && input keyevent 61 && input keyevent 61 && input keyevent 61 && input keyevent 66

Disconnect:

am start -a android.intent.action.MAIN -n com.android.settings/.Settings\$VpnSettingsActivity && input keyevent 20 && input keyevent 23 && input keyevent 61 && input keyevent 66

But first of all, this will open the settings dialog in the foreground, disrupting whatever I have been doing and secondly this whole method relies on the UI to have a specific amount of fields and buttons.


Viewing all articles
Browse latest Browse all 357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>