Search code examples
javaandroidtimestampunix-timestamp

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


Solution

  • 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 :)