Location.time wrong by a multiple of 24h

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Location.time wrong by a multiple of 24h

I can find reports about such a problem on stackoverflow from 2012. That time people thought it would be hardware or firmware.

6 years later, writing my first Android app, I can reproduce this on an Android emulator, so I guess it cannot be either.
android-studio 3.3rc2 as of today with all plugins and whatever being current.

The emulator: Android 8 .0.0, security patch level April 5, 2018

How to reproduce:
- start google maps
- feed the emulator with gpx data
- wait for one day, maybe a bit more. I am not sure when exactly the wrap happens.
- start any app using Location.time. My app https://github.com/wrohdewald/gps_forwarder writes a log, here is an excerpt:

This app uses the Location PASSIVE_PROVIDER, the gps fixes are requested by google maps.

2018 16.12 01:30:59.547 TID=2   2018 13.12 13:28:50.119 Boot time
2018 16.12 01:30:59.552 TID=2   2018 16.12 01:30:50.984 System time
2018 16.12 01:30:59.556 TID=2   2018 16.12 01:22:07.465 Boot time + location.elapsed
2018 16.12 01:30:59.559 TID=2   2018 13.12 01:22:07.000 Location time
2018 16.12 01:30:59.563 TID=2  Adding 3 days to GPS times

Full source code see github. This is the relevant part:

fun Location.logTimes() {
val bootTime = java.lang.System.currentTimeMillis() - android.os.SystemClock.elapsedRealtime()
val sysTime = System.currentTimeMillis()
val gpsEtToTime = bootTime + elapsedRealtimeNanos / 1000000L
logError { "${bootTime.asDateTimeString()} Boot time" }
logError { "${sysTime.asDateTimeString()} System time" }
logError { "${gpsEtToTime.asDateTimeString()} Boot time + location.elapsed" }
logError("${time.asDateTimeString()} Location time")

You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.