I'm looking at trying to implement a VPNService on Android for packet filtering and reporting and I have initially been looking at this project:
https://github.com/hexene/LocalVPN
As well as this I have been looking at Google's ToyVpn as a basis to understand what I can and can't do with a VPNService. The only issue with both is that start a non-blocking VPN when building the VPNService and then poll the file descrptor and then wait something like 100ms. Both have comments suggesting that this is not the way to do it. I'm assuming they run a non-blocking VPN because a blocking VPN is much more complicated?
I also assumed (wrongly) that adding the line
builder.setBlocking(true);
would fix things, but instead whilst the VPN service seems to do something, it doesn't seem to do anything useful because if you connect to it and open a browser session everything times out. It's almost as if adding this line causes packets to be dropped.
The aim is to get this as a blocking VPN so that I can eliminate the need for polling the file descriptor which I am sure is bad for battery life.