How to automatically reconnect VPN on network change? I'm using a VPN service, but so far I've only been using it on my computer. Now I'd like to have it on my phone as well. The service I use allow up to four simultaneous connections, so that isn't an issue. They don't have their own client for Android, but they do make config files available for download and use with any client that supports OpenVPN. I've tried OpenVPN Connect, and it works quite well. However, whenever I switch between networks, for example when I lose my home WiFi on leaving my home, or when switching between public WiFis, it doesn't reconnect, so I have to remember to actively disconnect and reconnect.

I've tried setting up a macro in MacroDroid to automatically close OpenVPN Connect, wait for a few seconds, then reopen OpenVPN Connect, but all that does, is bring up the login screen, and I still have to manually click Connect.

My phone is rooted, and in case it matters, it's a Honor 8, FRD-L09 running EMUI 4.1. I'm not going to upgrade to 5.0 at this time, as TWRP and SuperSU have been reported not to be compatible with the EMUI 5.0 kernel. Other than that, I'm open to suggestions. I'm not afraid to play with shell scripts, as long as I have some understanding of what the script does, and with this, I have no idea how to implement it in a shell script, so if if you have such a solution, please also explain what it actually does.

EDIT: OpenVPN Connect has the ability to create shortcuts to disconnect and connect on the homescreen. I'm assuming that these shortcuts just pass arguments to the executable, telling it what to do, and what config file to use. If I knew how to find what arguments the shortcuts pass, I'd likely be able to write a shell script that I could then call from MacroDroid upon network change.
This seems to have been caused by either a bug or an oversight by the app developer, and it sorted itself after an update. Just make sure the OpenVPN client is recent.

Also, the following settings are worth checking.

Reconnect on reboot. Enable it unless you want to manually decide when to OpenVPN and when not to.

Seamless tunnel. Enabling it blocks all internet traffic while the VPN is (re)-connection, to avoid leaking your real IP.

Connction timeout. How long to try re-acquiring the connection if it is lost. Set this to CONTINOUSLY RETRY to keep trying until a connection is established. If a timeout is set, and a connection has not been established before it runs out, OpenVPN Connect will exit, and the connection will be unblocked, to let you connect unprotected until you manually restart OpenVPN Connect.

Moreover, keep in mind, that reconnect on reboot only works if OpenVPN Connect is connected when you initiate the reboot. If you manually disconnected or if you lost the connection, you need to manually reconnect after rebooting.