forked from upstream-mirrors/OpenTracks
Cleanup: GPS Status only reports current status.
This commit is contained in:
@@ -189,7 +189,7 @@ public class GPSManager implements SensorConnector, LocationListenerCompat, GpsS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGpsStatusChanged(GpsStatusValue prevStatus, GpsStatusValue currentStatus) {
|
public void onGpsStatusChanged(GpsStatusValue currentStatus) {
|
||||||
trackPointCreator.sendGpsStatus(currentStatus);
|
trackPointCreator.sendGpsStatus(currentStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import de.dennisguse.opentracks.settings.PreferencesUtils;
|
|||||||
/**
|
/**
|
||||||
* This class handle GPS status according to received locations` and some thresholds.
|
* This class handle GPS status according to received locations` and some thresholds.
|
||||||
*/
|
*/
|
||||||
//TODO should handle sharedpreference changes
|
|
||||||
class GpsStatus {
|
class GpsStatus {
|
||||||
|
|
||||||
private static final String TAG = GpsStatus.class.getSimpleName();
|
private static final String TAG = GpsStatus.class.getSimpleName();
|
||||||
@@ -66,23 +65,21 @@ class GpsStatus {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
thresholdHorizontalAccuracy = PreferencesUtils.getRecordingDistanceInterval();
|
onRecordingDistanceChanged(PreferencesUtils.getRecordingDistanceInterval());
|
||||||
|
onMinRecordingIntervalChanged(PreferencesUtils.getMinRecordingInterval());
|
||||||
Duration minRecordingInterval = PreferencesUtils.getMinRecordingInterval();
|
|
||||||
signalLostThreshold = SIGNAL_LOST_THRESHOLD.plus(minRecordingInterval);
|
|
||||||
|
|
||||||
gpsStatusHandler = new Handler();
|
gpsStatusHandler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
client.onGpsStatusChanged(GpsStatusValue.GPS_NONE, GpsStatusValue.GPS_ENABLED);
|
client.onGpsStatusChanged(GpsStatusValue.GPS_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client that uses GpsStatus has to call this method to stop the Runnable if needed.
|
* The client that uses GpsStatus has to call this method to stop the Runnable if needed.
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
client.onGpsStatusChanged(gpsStatus, GpsStatusValue.GPS_NONE);
|
client.onGpsStatusChanged(GpsStatusValue.GPS_NONE);
|
||||||
client = null;
|
client = null;
|
||||||
if (gpsStatusRunner != null) {
|
if (gpsStatusRunner != null) {
|
||||||
gpsStatusRunner.stop();
|
gpsStatusRunner.stop();
|
||||||
@@ -136,22 +133,21 @@ class GpsStatus {
|
|||||||
private void checkStatusFromLastLocation() {
|
private void checkStatusFromLastLocation() {
|
||||||
if (Duration.between(lastTrackPoint.getTime(), Instant.now()).compareTo(signalLostThreshold) > 0 && gpsStatus != GpsStatusValue.GPS_SIGNAL_LOST) {
|
if (Duration.between(lastTrackPoint.getTime(), Instant.now()).compareTo(signalLostThreshold) > 0 && gpsStatus != GpsStatusValue.GPS_SIGNAL_LOST) {
|
||||||
// Too much time without receiving signal -> signal lost.
|
// Too much time without receiving signal -> signal lost.
|
||||||
GpsStatusValue oldStatus = gpsStatus;
|
setGpsStatus(GpsStatusValue.GPS_SIGNAL_LOST);
|
||||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_LOST;
|
|
||||||
sendStatus(oldStatus, gpsStatus);
|
|
||||||
stopStatusRunner();
|
stopStatusRunner();
|
||||||
} else if (lastTrackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy) && gpsStatus != GpsStatusValue.GPS_SIGNAL_BAD) {
|
return;
|
||||||
|
}
|
||||||
|
if (lastTrackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy) && gpsStatus != GpsStatusValue.GPS_SIGNAL_BAD) {
|
||||||
// Too little accuracy -> bad signal.
|
// Too little accuracy -> bad signal.
|
||||||
GpsStatusValue oldStatus = gpsStatus;
|
setGpsStatus(GpsStatusValue.GPS_SIGNAL_BAD);
|
||||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_BAD;
|
|
||||||
sendStatus(oldStatus, gpsStatus);
|
|
||||||
startStatusRunner();
|
startStatusRunner();
|
||||||
} else if (lastTrackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy) && gpsStatus != GpsStatusValue.GPS_SIGNAL_FIX) {
|
return;
|
||||||
|
}
|
||||||
|
if (lastTrackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy) && gpsStatus != GpsStatusValue.GPS_SIGNAL_FIX) {
|
||||||
// Gps okay.
|
// Gps okay.
|
||||||
GpsStatusValue oldStatus = gpsStatus;
|
setGpsStatus(GpsStatusValue.GPS_SIGNAL_FIX);
|
||||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_FIX;
|
|
||||||
sendStatus(oldStatus, gpsStatus);
|
|
||||||
startStatusRunner();
|
startStatusRunner();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +160,7 @@ class GpsStatus {
|
|||||||
Duration elapsed = Duration.between(lastValidTrackPoint.getTime(), Instant.now());
|
Duration elapsed = Duration.between(lastValidTrackPoint.getTime(), Instant.now());
|
||||||
if (signalLostThreshold.minus(elapsed).isNegative()) {
|
if (signalLostThreshold.minus(elapsed).isNegative()) {
|
||||||
// Too much time without locations -> lost signal? (wait signalLostThreshold from last valid location).
|
// Too much time without locations -> lost signal? (wait signalLostThreshold from last valid location).
|
||||||
GpsStatusValue oldStatus = gpsStatus;
|
setGpsStatus(GpsStatusValue.GPS_SIGNAL_LOST);
|
||||||
gpsStatus = GpsStatusValue.GPS_SIGNAL_LOST;
|
|
||||||
sendStatus(oldStatus, gpsStatus);
|
|
||||||
stopStatusRunner();
|
stopStatusRunner();
|
||||||
lastValidTrackPoint = null;
|
lastValidTrackPoint = null;
|
||||||
}
|
}
|
||||||
@@ -177,36 +171,37 @@ class GpsStatus {
|
|||||||
* Anyway, it checks that GPS is enabled because the client assumes that if it's on then GPS is enabled but user can disable GPS by hand.
|
* Anyway, it checks that GPS is enabled because the client assumes that if it's on then GPS is enabled but user can disable GPS by hand.
|
||||||
*/
|
*/
|
||||||
public void onGpsEnabled() {
|
public void onGpsEnabled() {
|
||||||
if (gpsStatus != GpsStatusValue.GPS_ENABLED) {
|
if (gpsStatus == GpsStatusValue.GPS_ENABLED) {
|
||||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
return;
|
||||||
if (locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
}
|
||||||
GpsStatusValue oldStatus = gpsStatus;
|
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
gpsStatus = GpsStatusValue.GPS_ENABLED;
|
if (locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||||
sendStatus(oldStatus, gpsStatus);
|
setGpsStatus(GpsStatusValue.GPS_ENABLED);
|
||||||
startStatusRunner();
|
startStatusRunner();
|
||||||
} else {
|
} else {
|
||||||
onGpsDisabled();
|
onGpsDisabled();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method must be called from service every time the GPS sensor is disabled.
|
* This method must be called from service every time the GPS sensor is disabled.
|
||||||
*/
|
*/
|
||||||
public void onGpsDisabled() {
|
public void onGpsDisabled() {
|
||||||
if (gpsStatus != GpsStatusValue.GPS_DISABLED) {
|
if (gpsStatus == GpsStatusValue.GPS_DISABLED) {
|
||||||
GpsStatusValue oldStatus = gpsStatus;
|
return;
|
||||||
gpsStatus = GpsStatusValue.GPS_DISABLED;
|
|
||||||
sendStatus(oldStatus, gpsStatus);
|
|
||||||
lastTrackPoint = null;
|
|
||||||
lastValidTrackPoint = null;
|
|
||||||
stopStatusRunner();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGpsStatus(GpsStatusValue.GPS_DISABLED);
|
||||||
|
lastTrackPoint = null;
|
||||||
|
lastValidTrackPoint = null;
|
||||||
|
stopStatusRunner();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendStatus(GpsStatusValue prev, GpsStatusValue current) {
|
private void setGpsStatus(GpsStatusValue current) {
|
||||||
|
gpsStatus = GpsStatusValue.GPS_DISABLED;
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
client.onGpsStatusChanged(prev, current);
|
client.onGpsStatusChanged(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,11 +223,7 @@ class GpsStatus {
|
|||||||
return signalLostThreshold;
|
return signalLostThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GpsStatusValue getGpsStatus() {
|
|
||||||
return gpsStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface GpsStatusListener {
|
public interface GpsStatusListener {
|
||||||
void onGpsStatusChanged(GpsStatusValue prevStatus, GpsStatusValue currentStatus);
|
void onGpsStatusChanged(GpsStatusValue currentStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user