Android VPN: hexene LocalVPN service not working after a while - android

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)

Related

Android VPNService setBlocking(true) Breaks VPN

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.
Just for anyone seeing this and having the same issue, this is a question that misses the mark. Turns out turning blocking on was OK, it's just that the polling loop was not setup to be blocking which causes deadlock.

How to have a task in the background which can read and write data from a Bluetooth connection?

I'm currently making an app to exchange data between phone and a bluetooth device. I need this exchange to be in the background so when the device send some data, the app can read it and act from it, whenever the app is active or not.
I already establish some read and write data in the app, but only when it is active for the user. Now I want to take the next level and make the same read and write data but in the background, so the connection between the devices is establish and maintain.
I already know about jobschedule and service. Also, I know that, with the new versions of Android OS, services are killed by some time passed or in Doze mode. Other things I found out was to use threads in the background, but I'm still searching for that. But in the end, I'm still a newbie and maybe I'm missing out some information or I couldn't understand the concepts in their fullness, because I can't see yet how to make a process in background that could react upon a message received from the device or react upon a message received from the phone and create this exchange data.
In all, this raised me a question: how to have this kind of task in the background which read and write data from bluetooth connection between phone and a device? Is it jobschedule? Threads? Or there is one that I'm missing out?
Yet, in SO exist some questions about this related topic, some are outdate about the killing service which android does now, but if this question is a repeated one, please link me one that can solve this problem. I'll be gratefull.
Side note: I would like to know if there is a way to turn this task on and off by some condition or by the user's preference.
EDIT:
Some questions I found:
How to keep Bluetooth connection background? - This one is recent, but I don't know if this service will not be killed by the system.
Android 8.0 background services for bluetooth device - This is recent too and it has in his answer the bluetooth connection could be killed too.

Is it a good idea to initialize Crashlytics, on android's onCreate method?

I'm using Crashlytics for android and it really helped me to fix many of my crashes. But today I had a little problem with it.
When I tried to test crashlytics on 2.3.3 Galaxy S device, which is connected to internet by wi-fi(with proxy), I saw black screen on device for about 2:30 minutes. While debugging; I see that Crashlytics.start(this) code is not async. It waits to establish a connection and thus onCreate method can not be finished by UI thread.(This explains black screen).
I know this a proxy issue(proxy setting is a bit buggy on 2.3.x devices) but waiting for about 2:30 minutes made my app black screen. This worried me that this may happen on any other real life conditions such as poor internet connection.
I will try to put Crashlytics.start(this) function into an asynctask and will try this on every activities onCreate method. (AFAIK there is no method to check isCrashlyticsInitialized)
Does anyone have better idea about this?
Thanks in advance.
LOGCAT:
10-02 16:01:38.410: D/Crashlytics(1561): Initializing Crashlytics 0.9.11.11
10-02 16:04:19.664: E/Crashlytics(1561): Network error while loading Crashlytics settings. Crashes will be cached until the network is available.
[URL=https://settings.crashlytics.com/api/v2/keys/KEY/platforms/android/apps/com.myapp/settings.json?libVersion=0.9.11.11&bundleVersion=441210&shortBundleVersion=2.1];[class java.net.SocketTimeoutException: Connection timed out]
Marc from Crashlytics here. Crashlytics.start() does all the heavy lifting in a background thread in newer versions of the SDK. Your logs indicate you're using v0.9.11. Once you update to the latest version (v1.0.4), you'll be fine keeping Crashlytics.start in the Application subclass. Please contact us at support at crashlytics dot com if you need any help updating!

Flex mobile app crashes/hangs while waiting for web service response

I have having problems with a WSDL/SOAP service call in an app I have built in flash builder for mobile. I have connected to the service using flash builders built in data/services functionality.
For the most part, the service call works perfectly but once in a while it will cause the app to crash - on my android device it completely locks up (spinning animation stops) and then Android informs me that the app is not responding and asks if I want to close it.
The crash appears to occur quite frequently but not with any pattern. One time it happened on my third attempt, another time it took approximately 30, a couple of times I could not get it to happen and most times it occurs somewhere in between.
It appears that the crash happens after a service call is made but before any response is received. Neither the success or the fault listeners are ever fired. I am very confident that I am sending exactly the same variables to the service every time.
I have used web service calls in other apps without trouble so I have to assume there is something in this particular build that is causing problems but I can't seem to find anything.
Any thoughts on possible causes, things to test or even a solution would be hugely appreciated.
Thank you,
Jamie
Your question lacks essential details, so now I can suggest you to setup Charles proxy and monitor you requests trough it.
If you send too many requests simultaneously, you shall not be confident in fault/result events as air runtime has limitations (in any case, it is a good practice to handle request timeout).

IdleConnectionHandler removing a connection that never existed in my android app

My android app keeps logging this warning :
IdleConnectionHandler removing a connection that never existed
What does that mean? Is that a big problem? What should I do to avoid this?
My app makes many http connections in AsyncTask, is that related?
EDIT:
I found that this call was the reason of this message :
httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
So maybe it tries to close some connections that don't exist?
It sounds like there is a logic error in your code. You may be able to track down the problems using this Android tool called ARO. You can find out more about it here http://developer.att.com/developer/legalAgreementPage.jsp?passedItemId=9700312
It will help you to understand more about how your application is using the network and how you can improve that part of your application to make it more efficient.
Is there a reason you need to make many http connections at once?
I got that error too, but my app uses internet only for ad loading. Currently I have no permission that my app can use internet, so that is why it says "Removing a connection that never existed". That may be one of the reason for this warning.

Categories

Resources