Skip to content

Commit

Permalink
Fix GPS Week Number Rollover on devices manufactured between 2006 and…
Browse files Browse the repository at this point in the history
… 2016.
  • Loading branch information
zamojski committed Mar 21, 2020
1 parent ce84c46 commit 1878e02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ android {
// Other
buildConfigField "String", "UPDATE_CHECK_FEED_URI", props['other_updateCheckFeedUri']
buildConfigField "String", "CONTACT_EMAIL", rot135(props['other_contactEmail'])
buildConfigField "Long", "BUILD_DATE_TIME", String.format("%dL", new Date().getTime())
}
signingConfigs {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package info.zamojski.soft.towercollector.collector.parsers;

import org.greenrobot.eventbus.EventBus;

import info.zamojski.soft.towercollector.BuildConfig;
import info.zamojski.soft.towercollector.MyApplication;
import info.zamojski.soft.towercollector.collector.ParseResult;
import info.zamojski.soft.towercollector.collector.validators.ConditionsValidator;
Expand Down Expand Up @@ -71,11 +73,19 @@ protected void updateMeasurementWithLocation(Measurement measurement, Location l
protected void fixMeasurementTimestamp(Measurement measurement, Location location) {
// update timestamp if user has incorrect system time in phone
// that means if earlier than fix or later by one day
// but only if gps time later than app build time
long systemTimestamp = measurement.getMeasuredAt();
long gpsTimestamp = location.getTime();
if (!systemTimeValidator.isValid(systemTimestamp, gpsTimestamp)) {
Timber.d("fixMeasurementTimestamp(): Fixing measurement time = %s, gps time = %s", systemTimestamp, gpsTimestamp);
measurement.setMeasuredAt(gpsTimestamp);
long appBuildTimestamp = BuildConfig.BUILD_DATE_TIME;
Timber.i("fixMeasurementTimestamp(): Fixing measurement time = %s, gps time = %s, app time = %s", systemTimestamp, gpsTimestamp, appBuildTimestamp);
// starting on November 3, 2019, mobile devices manufactured between 2006 and 2016 may have their GPS accuracy impacted due to GPS Rollover issue
if (gpsTimestamp >= appBuildTimestamp) {
measurement.setMeasuredAt(gpsTimestamp);
Timber.i("fixMeasurementTimestamp(): Fixed measurement time using gps time");
} else if (systemTimestamp < appBuildTimestamp) {
throw new IllegalStateException("System (" + systemTimestamp + ") and GPS (" + gpsTimestamp + ") timestamps are older than app build time (" + appBuildTimestamp + ")");
}
}
}

Expand Down

0 comments on commit 1878e02

Please sign in to comment.