Android App: WiFi transfer speed is throttled, but increases when the screen is tapped

I'm creating an Android app that writes binary files to a flash memory chip. I already have a working Windows counterpart written in C# so I've chosen to use Xamarin to build an Android version.

The application works using either a USB interface or a WiFi interface. I'm encountering some strange behaviour when implementing the WiFi transfer.

When I run the app using the USB cable the data transfer rate is consistent and the process takes around 2 minutes which is identical to my Windows application. When using WiFi the file takes around 4 minutes to write. If I pick up my phone and rub my finger around on the screen the speed will increase and the write only takes 2.5 minutes~ which to me indicates the reduced WiFi performance is somehow related to the WiFi management in Android.

My Windows app will complete the process on both WiFi and USB in around 2min so there's no inherent reason that one should be slower. It's even more confusing that just rubbing the screen will cause an instantaneous speed boost. The moment I take my fingers off the screen the rate slows down again.

The USB transfer is unaffected by touching the screen. Does Android somehow keep my task prioritised when the USB transfer is in process? And if so, is there a way I can get it to respect my WiFi traffic in the same way? The total filesize of the transfer is only 128kb so I don't think I'm maxing out any hardware!

I've tried the following based on other threads here:

-WiFi lock (WifiMode.FullLowLatency). I used the wifi lock function to put the adapter into full performance mode and low latency modes but that made no difference.

-Wake lock (WakeLockFlags.Full) to keep the screen on for the entire process. This made no difference as I had already disabled the auto sleep function for testing. Turning the screen off during the process does slow things down significantly though.

-Forground service: I decided to move all logic into a foreground service and call that. That made no difference at all.

-Moved all logic into MainActivity. This reduced the total time by about 30 seconds, but still slow and an improvement was still seen when rubbing the screen.

-Disabling Nagle's Algorithm and trying varying buffer sizes made no difference at all.

Am I missing any other tweaks that will change how Android treats my WiFi traffic?

Upvotes: 0

Views: 46

Answers (0)

Related Questions