My Android app has registered ConnectivityManager onAvailable and onLost NetworkCallbacks, but they are not called when a VPN (I'm testing with OpenVPN app) is connected or disconnected. They do get called when cellular network is connected/disconnected.
Before I connect the VPN, allNetworks shows one network:
11-17 16:16:22.719 23531 23531 I Baresip : Found network 106 with [ Transports: CELLULAR Capabilities: SUPL&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED Unwanted: LinkUpBandwidth>=51200Kbps LinkDnBandwidth>=102400Kbps Specifier: <6>]
After I have connected the VPN, there is two networks:
11-17 16:17:17.464 23531 23531 I Baresip : Found network 106 with [ Transports: CELLULAR Capabilities: SUPL&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED Unwanted: LinkUpBandwidth>=51200Kbps LinkDnBandwidth>=102400Kbps Specifier: <6>]
11-17 16:17:17.466 23531 23531 I Baresip : Found network 225 with [ Transports: VPN Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&VALIDATED&NOT_ROAMING&FOREGROUND&NOT_CONGESTED&NOT_SUSPENDED Unwanted: ]
But when the VPN network becomes available, my app does not get onAvailable (nor any other) ConnectivityManager notification about it. Same problem, when I disconnect the VPN.
Is this an Android bug or is there some other means to get notified about VPN events?
Edit: I searched Google's issue tracker and found exactly the same issue:
https://issuetracker.google.com/issues/138035152
Unfortunately the author did not provide all the information Google asked and they closed the issue.
I created a new bug report, but most likely it will not lead anywhere:
https://issuetracker.google.com/issues/173534857
So help from community would be welcome.