Fix #5535 - do not use getTime from location comparing with system time
This commit is contained in:
parent
cd289316dd
commit
82626aa84c
2 changed files with 13 additions and 11 deletions
|
@ -78,12 +78,16 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
private AtomicInteger locationRequestsCounter = new AtomicInteger();
|
private AtomicInteger locationRequestsCounter = new AtomicInteger();
|
||||||
private AtomicInteger staleLocationRequestsCounter = new AtomicInteger();
|
private AtomicInteger staleLocationRequestsCounter = new AtomicInteger();
|
||||||
|
|
||||||
private net.osmand.Location cachedLocation;
|
|
||||||
|
|
||||||
private long lastTimeGPSLocationFixed = 0;
|
private long lastTimeGPSLocationFixed = 0;
|
||||||
|
private long lastTimeLocationFixed = 0;
|
||||||
private boolean gpsSignalLost;
|
private boolean gpsSignalLost;
|
||||||
private SimulationProvider simulatePosition = null;
|
private SimulationProvider simulatePosition = null;
|
||||||
|
|
||||||
|
private long cachedLocationTimeFix = 0;
|
||||||
|
private net.osmand.Location cachedLocation;
|
||||||
|
|
||||||
private boolean sensorRegistered = false;
|
private boolean sensorRegistered = false;
|
||||||
private float[] mGravs = new float[3];
|
private float[] mGravs = new float[3];
|
||||||
private float[] mGeoMags = new float[3];
|
private float[] mGeoMags = new float[3];
|
||||||
|
@ -578,7 +582,8 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
lastTimeGPSLocationFixed = location.getTime();
|
// lastTimeGPSLocationFixed = location.getTime();
|
||||||
|
lastTimeGPSLocationFixed = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if(!locationSimulation.isRouteAnimating()) {
|
if(!locationSimulation.isRouteAnimating()) {
|
||||||
setLocation(convertLocation(location, app));
|
setLocation(convertLocation(location, app));
|
||||||
|
@ -766,7 +771,10 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
if(location == null){
|
if(location == null){
|
||||||
updateGPSInfo(null);
|
updateGPSInfo(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(location != null) {
|
if(location != null) {
|
||||||
|
// // use because there is a bug on some devices with location.getTime()
|
||||||
|
lastTimeLocationFixed = System.currentTimeMillis();
|
||||||
simulatePosition = null;
|
simulatePosition = null;
|
||||||
if(gpsSignalLost) {
|
if(gpsSignalLost) {
|
||||||
gpsSignalLost = false;
|
gpsSignalLost = false;
|
||||||
|
@ -811,12 +819,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIfLastKnownLocationIsValid() {
|
|
||||||
net.osmand.Location loc = getLastKnownLocation();
|
|
||||||
if (loc != null && (System.currentTimeMillis() - loc.getTime()) > INTERVAL_TO_CLEAR_SET_LOCATION) {
|
|
||||||
setLocation(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigationInfo getNavigationInfo() {
|
public NavigationInfo getNavigationInfo() {
|
||||||
return navigationInfo;
|
return navigationInfo;
|
||||||
|
@ -867,7 +869,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
int counter = locationRequestsCounter.incrementAndGet();
|
int counter = locationRequestsCounter.incrementAndGet();
|
||||||
if (counter >= REQUESTS_BEFORE_CHECK_LOCATION && locationRequestsCounter.compareAndSet(counter, 0)) {
|
if (counter >= REQUESTS_BEFORE_CHECK_LOCATION && locationRequestsCounter.compareAndSet(counter, 0)) {
|
||||||
if (System.currentTimeMillis() - loc.getTime() > LOCATION_TIMEOUT_TO_BE_STALE) {
|
if (System.currentTimeMillis() - lastTimeGPSLocationFixed > LOCATION_TIMEOUT_TO_BE_STALE) {
|
||||||
location = null;
|
location = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -882,12 +884,13 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
int counter = staleLocationRequestsCounter.incrementAndGet();
|
int counter = staleLocationRequestsCounter.incrementAndGet();
|
||||||
if (counter >= REQUESTS_BEFORE_CHECK_LOCATION && staleLocationRequestsCounter.compareAndSet(counter, 0)) {
|
if (counter >= REQUESTS_BEFORE_CHECK_LOCATION && staleLocationRequestsCounter.compareAndSet(counter, 0)) {
|
||||||
net.osmand.Location cached = cachedLocation;
|
net.osmand.Location cached = cachedLocation;
|
||||||
if (cached != null && System.currentTimeMillis() - cached.getTime() > STALE_LOCATION_TIMEOUT_TO_BE_GONE) {
|
if (cached != null && System.currentTimeMillis() - cachedLocationTimeFix > STALE_LOCATION_TIMEOUT_TO_BE_GONE) {
|
||||||
cachedLocation = null;
|
cachedLocation = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cachedLocation = newLoc;
|
cachedLocation = newLoc;
|
||||||
|
cachedLocationTimeFix = lastTimeLocationFixed;
|
||||||
}
|
}
|
||||||
return cachedLocation;
|
return cachedLocation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -655,7 +655,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.getLocationProvider().checkIfLastKnownLocationIsValid();
|
|
||||||
// for voice navigation
|
// for voice navigation
|
||||||
ApplicationMode routingAppMode = getRoutingHelper().getAppMode();
|
ApplicationMode routingAppMode = getRoutingHelper().getAppMode();
|
||||||
if (routingAppMode != null && settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode) != null) {
|
if (routingAppMode != null && settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode) != null) {
|
||||||
|
|
Loading…
Reference in a new issue