Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ScanResult Timestamp Field - How accurate is it?

I've been using wifiManager.startScan(); to receive the data from nearby Wi-Fi access points. This is returned as a List of ScanResult. This class can be found here: http://developer.android.com/reference/android/net/wifi/ScanResult.html#timestamp

I understand that the Timestamp field of ScanResult is

timestamp in microseconds (since boot) when this result was last seen.

So I use some calculations to get the actual timestamp of when the access point was seen by the Smartphone device:

long actualTimestamp = System.currentTimeMillis() - SystemClock.elapsedRealtime() + (scanResult.timestamp / 1000);

This works fine, but I'm having some rare interesting results:

15:04:01 28-03-2016 - 1459173841

22:50:44 07-06-2016 - 1465336244

15:04:21 28-03-2016 - 1459173861

Notice above the entry for June 2016, a date in the future which is placed among the other readings gathered from within the List.

What could be happening here? Is my code slightly wrong? Is the timestamp value occasionally inaccurate? Has anyone experienced this before?

Edit: I am testing this on Nexus 5 Marshmallow device. MinSDK 18, Target 23

like image 582
Jonty800 Avatar asked Oct 25 '25 03:10

Jonty800


2 Answers

I seem to have an explanation: this is a bug.

I see that occasionally .timestamp (microseconds since reboot) will be equal to .seen (seconds since Epoch). Nowadays Epoch time is approximately 17 days if reinterpreted as microseconds time period.

Since 2 values clearly cannot be equal, I submitted it to Android: https://code.google.com/p/android/issues/detail?id=225218 Feel free to star the issue :)

like image 139
beefeather Avatar answered Oct 27 '25 18:10

beefeather


This one works for me

long actualTime = System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(SystemClock.elapsedRealtimeNanos() - scanResult.getTimestampNanos(), TimeUnit.NANOSECONDS)
like image 42
Dmytro Batyuk Avatar answered Oct 27 '25 18:10

Dmytro Batyuk