forked from upstream-mirrors/OpenTracks
TrackRecordingService: removed race conditions workarounds.
Part of #1187.
This commit is contained in:
@@ -112,10 +112,7 @@ class TrackRecordingManager implements SharedPreferences.OnSharedPreferenceChang
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Track, Pair<TrackPoint, SensorDataSet>> getDataForUI(TrackPointCreator trackPointCreator) {
|
Pair<Track, Pair<TrackPoint, SensorDataSet>> getDataForUI(@NonNull TrackPointCreator trackPointCreator) {
|
||||||
if (trackPointCreator == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
TrackStatisticsUpdater tmpTrackStatisticsUpdater = new TrackStatisticsUpdater(trackStatisticsUpdater);
|
TrackStatisticsUpdater tmpTrackStatisticsUpdater = new TrackStatisticsUpdater(trackStatisticsUpdater);
|
||||||
Pair<TrackPoint, SensorDataSet> current = trackPointCreator.createCurrentTrackPoint(lastTrackPointUIWithSpeed, lastTrackPointUIWithAltitude, lastStoredTrackPointWithLocation);
|
Pair<TrackPoint, SensorDataSet> current = trackPointCreator.createCurrentTrackPoint(lastTrackPointUIWithSpeed, lastTrackPointUIWithAltitude, lastStoredTrackPointWithLocation);
|
||||||
|
|
||||||
|
|||||||
@@ -71,13 +71,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
public void run() {
|
public void run() {
|
||||||
updateRecordingDataWhileRecording();
|
updateRecordingDataWhileRecording();
|
||||||
|
|
||||||
Handler localHandler = TrackRecordingService.this.handler;
|
TrackRecordingService.this.handler.postDelayed(this, RECORDING_DATA_UPDATE_INTERVAL.toMillis());
|
||||||
if (localHandler == null) {
|
|
||||||
// when this happens, no recording is running and we should not send any notifications.
|
|
||||||
//TODO This implementation is not a good idea; rather solve the issue for this properly
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
localHandler.postDelayed(this, RECORDING_DATA_UPDATE_INTERVAL.toMillis());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,11 +131,9 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
notificationManager = null;
|
notificationManager = null;
|
||||||
|
|
||||||
egm2008CorrectionManager = null;
|
egm2008CorrectionManager = null;
|
||||||
try {
|
|
||||||
voiceAnnouncementManager.stop();
|
voiceAnnouncementManager.stop();
|
||||||
} finally {
|
voiceAnnouncementManager = null;
|
||||||
voiceAnnouncementManager = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should be the next to last operation
|
// This should be the next to last operation
|
||||||
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
||||||
@@ -272,13 +264,8 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newGpsStatus(GpsStatusValue gpsStatusValue) {
|
public void newGpsStatus(GpsStatusValue gpsStatusValue) {
|
||||||
|
notificationManager.updateContent(getString(gpsStatusValue.message));
|
||||||
//TODO This check should not be necessary, but prevents a crash; somehow the shutdown is not working correctly as we should not receive a notification then.
|
gpsStatusObservable.postValue(gpsStatusValue);
|
||||||
// It is likely a race condition as the LocationManager provides location updates without using the Handler.
|
|
||||||
if (gpsStatusObservable != null) {
|
|
||||||
notificationManager.updateContent(getString(gpsStatusValue.message));
|
|
||||||
gpsStatusObservable.postValue(gpsStatusValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
|
public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
|
||||||
@@ -316,15 +303,6 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute temporary track statistics using sensorData and update time.
|
// Compute temporary track statistics using sensorData and update time.
|
||||||
|
|
||||||
TrackPointCreator localTrackPointCreator = this.trackPointCreator;
|
|
||||||
VoiceAnnouncementManager localVoiceAnnouncementManager = this.voiceAnnouncementManager;
|
|
||||||
if (localTrackPointCreator == null || localVoiceAnnouncementManager == null) {
|
|
||||||
// when this happens, no recording is running and we should not send any notifications.
|
|
||||||
//TODO This implementation is not a good idea; rather solve the issue for this properly
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pair<Track, Pair<TrackPoint, SensorDataSet>> data = trackRecordingManager.getDataForUI(trackPointCreator);
|
Pair<Track, Pair<TrackPoint, SensorDataSet>> data = trackRecordingManager.getDataForUI(trackPointCreator);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
Log.w(TAG, "Requesting data if not recording is taking place, should not be done.");
|
Log.w(TAG, "Requesting data if not recording is taking place, should not be done.");
|
||||||
@@ -333,7 +311,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
TrackPoint trackPoint = data.second.first;
|
TrackPoint trackPoint = data.second.first;
|
||||||
egm2008CorrectionManager.correctAltitude(this, trackPoint);
|
egm2008CorrectionManager.correctAltitude(this, trackPoint);
|
||||||
|
|
||||||
localVoiceAnnouncementManager.update(this, data.first);
|
voiceAnnouncementManager.update(this, data.first);
|
||||||
|
|
||||||
recordingDataObservable.postValue(new RecordingData(data.first, trackPoint, data.second.second));
|
recordingDataObservable.postValue(new RecordingData(data.first, trackPoint, data.second.second));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user