5

I have a rooted phone Samsung N7100 (kitkat 4.4.2). After 6 April 2019 I started getting locations with date of 1999 year.

Sometimes locations come with a date of 2019, but after that the device stops receiving any locations.

Only the adb comand helps, but after some time the device stops receiving any locations.

settings put secure location_providers_allowed -gps
settings put secure location_providers_allowed +gps

I have tried update firmware to android 6 and 7. Nothings helps.

mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, this);
....

public void onLocationChanged(Location location) {
  Log.d(TAG, (new Date(location.getTime())).toLocaleString());
}
Gallyamov
  • 162
  • 2
  • 9
  • It is the [week number rollover bug](https://www.theverge.com/2019/3/8/18255847/gps-week-rollover-issue-2019-garmin-tomtom-devices-affected). Don't think you can do anything about it. – TDG May 16 '19 at 18:10
  • Seems like the binary driver (/bin/gpsd) isn't prepared for the WNRO. Without help from at least Samsung (and Broadcom) this can't be fixed (unless maybe you are able to reverse engineer or write your own driver). – TJJ Oct 28 '19 at 12:18

3 Answers3

7

This is related to the GPS Week Number Rollover issue that appears on some types of GPS chips.

One way to work around it by detecting that the value returned from location.getTime() is too old (say, before 2019) and if so - add the difference (1024 weeks).

This code should work for the next ~20 years:

long gpsTime = location.getTime();

// Adding 1024 weeks to fix Week Number Rollover issue for old GPS chips
// 619315200000L = 1024 * 7 * 24 * 60 * 60 * 1000   ->  means 1024 weeks
// Note: This fix works for next 20 years since provided timestamp below
// See: https://stackoverflow.com/questions/56147606/
// See: https://www.cisa.gov/gps-week-number-roll-over
if ((gpsTime > 0) && (gpsTime < 1673000000000L))
  gpsTime += 619315200000L;
Homayoon Ahmadi
  • 1,181
  • 1
  • 12
  • 24
uri2x
  • 3,162
  • 1
  • 11
  • 25
3

Had the same issue recently in an app I develop (October 2022). A few phones showed a date which was roughly 20 years back. Phones included Galaxy Note 9, Galaxy S7.

This question helped and this is how I fixed it while implementing a location listener:

override fun onLocationChanged(location: Location) {
    //GPS Week rollover fix. Add 1024 weeks if OS time is off by more than ~992 weeks
    //https://stackoverflow.com/questions/56147606/
    val c = Calendar.getInstance()
    if (c.time.time - location.time > 600000000000L) {
        location.time = location.time + 619315200000L
    }
    processLocation(location)
}
CaptainNemo
  • 1,532
  • 2
  • 22
  • 45
0

Had a similar problem. I had an app which initially used the Google Play Services library location provider to fetch GPS location, and everything went well.

However, after removing the Google Play Services dependency, I started using the location data fetched from the device LocationManager, and this problem started.

It turns out that if you use the Google Play Services location provider this problem doesn't happen. Looks like this fix (or similar) is already done in the library

BTW: Seen this problem on a Samsung Galaxy S8, June 2023

BamsBamx
  • 4,139
  • 4
  • 38
  • 63