Search code examples
androidandroid-intentservicevpnandroid-vpn-service

How android Always-on VPN internally works?


I can read from developer.android.com about how to support Always-on VPN from the VPN application point of view.

But couldn't find any information how the android system internally implements this feature?

  • Does the android system wake up periodically and check if the VPN service is running and if not then tries to start the specified VPN service?
  • Does this happen on a regular interval basis?
  • What if there is no network connectivity? Will android wait until the n/w conn is restored to start the VPN service?

Thanks in advance


Solution

  • Does the android system wake up periodically and check if the VPN service is running and if not then tries to start the specified VPN service?

    No, the system starts the VPN service once after the system boots up (with action android.net.VpnService). Depending on the Android version the user first has to unlock the system (seems to be the case with Android 8+). On Android 7.x that's not the case, which could be a problem if the VPN app e.g. requires access to credentials in the locked KeyChain.

    It also starts the VPN service whenever the Always-on VPN feature is enabled by the user in the system's VPN setttings.

    Does this happen on a regular interval basis?

    No, but since Android 8 the system displays a notification if the Always-on VPN feature is enabled but there is currently no tunnel interface (tapping the notification will open the system's VPN settings).

    What if there is no network connectivity? Will android wait until the n/w conn is restored to start the VPN service?

    No, the VPN app has to handle that situation.