Skip to content

Commit

Permalink
Add fix for GPS rollover bug, closes #78
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabiszewski committed Aug 23, 2020
1 parent c39c3a9 commit b4ce161
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/src/main/java/net/fabiszewski/ulogger/LocationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class LocationHelper {
private final Context context;
private final LocationManager locationManager;

// millis 1999-08-21T23:59:42+00:00
private static final long FIRST_ROLLOVER_TIMESTAMP = 935279982000L;
// millis 2019-04-06T23:59:42+00:00
private static final long SECOND_ROLLOVER_TIMESTAMP = 1554595182000L;
// 1024 weeks in milliseconds
private static final long ROLLOVER_MILLIS = 1024 * 7 * 24 * 60 * 60 * 1000L;

private boolean liveSync = false;
private int maxAccuracy;
private float minDistance;
Expand Down Expand Up @@ -249,6 +256,20 @@ boolean isLiveSync() {
return liveSync;
}


/**
* Fix GPS week count rollover bug if needed
* https://galileognss.eu/gps-week-number-rollover-april-6-2019/
* @param location Location
*/
static void handleRolloverBug(Location location) {
long gpsTime = location.getTime();
if (gpsTime > FIRST_ROLLOVER_TIMESTAMP && gpsTime < SECOND_ROLLOVER_TIMESTAMP) {
if (Logger.DEBUG) { Log.d(TAG, "[Fixing GPS rollover bug: " + gpsTime + "]"); }
location.setTime(gpsTime + ROLLOVER_MILLIS);
}
}

/**
* Logger exceptions
*/
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/net/fabiszewski/ulogger/LoggerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ private class mLocationListener implements LocationListener {
public void onLocationChanged(Location location) {
if (Logger.DEBUG) { Log.d(TAG, "[location changed: " + location + "]"); }

LocationHelper.handleRolloverBug(location);

if (meetsCriteria(location)) {
lastLocation = location;
DbAccess.writeLocation(LoggerService.this, location);
Expand Down

0 comments on commit b4ce161

Please sign in to comment.