androidvpntun

How can I monitor vpn tun close event?


About android vpn service . When I start my vpn app and start vpn, then start another vpn app and start vpn, my app's tun network interface is closed, bug my app's vpnservice is runing normally, why?

I want to know is there any method can let me know:my vpn's fd should close. Two may sulution:

  1. monitor network change event, can found that tun is closed.
  2. when another vpn established, my vpnservice received onDestroy callback . ---acturally onDestroy is not called.

Solution

  • I have found the reason:

        override fun onBind(intent: Intent): IBinder {
            return Binder()
        }
    

    Nomally onBind should be :

    public IBinder onBind(Intent intent) {
        if (intent != null && SERVICE_INTERFACE.equals(intent.getAction())) {
            return new Callback();
        }
        return null;
    }
    

    How can I found that? When another vpn app called prepare, the vpn service should stop,but I find a logcat: oneway function results for code 16777215 on binder at 0xb40000730f64d060 will be dropped but finished with status UNKNOWN_TRANSACTION It seems that the binder has error, so I go to check the onBind implmentation.