I'm pretty new to Android programming and I had a little project for an Android VPN firewall-sortofthing in mind, based on this GitHub repo: https://github.com/hexene/LocalVPN (so on top of VpnService)
The problem is that, no edits done to the code from the original repo, the VPN stops working after a while (after seconds usually). By that I mean internet connection is lost in all applications, so I guess packets stop flowing through the VPN. It happens randomly and seemingly with no triggering event. Again, I edited 0 lines from the code.
What I've tried so far is:
- Using startForeground() as suggested here. Nothing changes.
- Having a permanent high priority notification showing to prevent the service from stopping (although I don't know if the service stopping is the cause.
- Only allowing certain apps in the VPN with Builder.addAllowedApplication(). This didn't work, as expected.
Anyone have any ideas or wisdom to share? Would be much appreciated!
Edit: the Log, when internet stops working, says this:
03-16 00:52:18.904 13182-13260/xyz.hexene.localvpn E/TCPInput: Network read error: 172.217.23.67:443:42746
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:382)
at xyz.hexene.localvpn.TCPInput.processInput(TCPInput.java:133)
at xyz.hexene.localvpn.TCPInput.run(TCPInput.java:72)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)