3

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.

0

You must log in to answer this question.

Browse other questions tagged .