How to detect programatically if traffic is going through VPN without using intent to connect to VPNService. Is there some system call?
I guess for most use-cases you want to check if the actively used network is using VPN instead of if just any network available is using VPN.
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_VPN)
... is returning a NetworkInfo for an available VPN Network. This might not be the active Network! Instead you could use the following snippet to test if the active Network is using VPN:
Network activeNetwork = connectivityManager.getActiveNetwork();
NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(activeNetwork);
boolean vpnInUse = caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN);