Strange behavior observed with WiFi direct API

While I was trying to get some data on power consumption of the WiFi Direct API usage, I discovered some strange behavior with it. I had seen earlier that sometimes I’m not really getting services discovered properly. While not knowing what was going on this was getting often a bit frustrating.

While still not knowing exact reasoning why this happens, at least I do have test data that does show that its happening. With the data the N4/N5 in the device id indicates Nexus 4/Nexus 5 device, and the ending part is the firmware version used in the device.

I had the devices going through the testing for around 11 hours, devices were stationary and only running the power test app in them.The environment was my home office, thus it did not have much interference from other devices around.

The logic of the app is to start peer discovery, and once it gets peers changed event, it starts looking for services, and then it just waits until it gets services discovered. Any error situation starts 1 minute timer, which starts peer discovery again. Discovery stopped event also triggers peers discovery start. There is also additional timer to keep the logic running in all situations.

You can find the test application used from Github under DrJukka/WifiTestPower.¬† And here’s first graph showing the data:


From the graph we can see that we get loads of Peers Changed events for each Service Discovery start. This is expected, the logic is build in a way that it starts Service discovery only when there is Peer Change event, and we don’t have active Service Discovery going on already.

From the data we can see that the Peers changed events are coming generally all times, and there is no major gaps when we would not be getting them. With devices having Kitkat there is also nice wave pattern on the graph, we’ll get back to that in the end of this article.

Then to see what actually happens with Service Discovery, lets have a look on the data without the Peers Changed events. Then the data looks like this:


And what we can see from the data, is that we are getting time periods when we are not actually discovering any services. For me this would be strange behavior, since the environment stays the same, and we have same number of devices around all times advertising their services. But still for some reason the API just stops finding these services.

From the data we can see that Nexus 5 devices having KitKat, the behavior appears to be exactly same with both devices. The time periods when they are discovering services and the time periods when they are not are more-or-less the same.

But with the devices having Lollipop on them, the general behavior is still the same, but the timings are bit off. Also the time periods for different behaviors are longer than with devices having KitKat on them.

All and all, all of the devices are showing behavior where they are having time periods when they are not discovering any services, while still having the Peer Changed event coming, and while starting periodically discovering the services.

Also the data shows that the devices will eventually start finding the services again.

And then lets get back to the wave pattern shown with the first graph. The data also appears to show that when we are actually discovering services, we are getting less Peer Change events.And when the period when we are not getting services discovered starts, we start getting more Peer Changed events.

This can be seen with all devices, though is is less obvious with the Nexus 4 having Lollipop. Not certain if this would help us on finding the root cause of the problem, anyways its still valid observation.

Then lets have a another way on looking into the data, the following graph is showing the cumulative  numbers Discovery starts and actual Discoveries over the 11 hour period.


Again Nexus 5 devices with Kitkat are doing it in sync, and devices with Lollipop are doing it differently. But the point what this graph shows clearly, is that the Lollipop devices appears to be making only half of the amount of Discovery start events, when compared to the devices having Kitkat.

Also it shows that both Lollipop devices are making about the same amount of Discovery starts, but as the Nexus 4 had longer period it was not getting any services discovered, it gets only 2/3 of the services discovered, when compared to Nexus 5 with Lollipop.

Lets see if we find any good reasons for the behavior of not Discovering services, or should we go finding a workaround solutions, meanwhile I’ll continue on trying to get the power consumption data for the API usage.