forked from upstream-mirrors/OpenTracks
TrackRecordingService: call stopSelf after triggering post-workout export.
Might fix #1080.
This commit is contained in:
+2
-2
@@ -132,7 +132,7 @@ public class TrackRecordingServiceTestStateMachine {
|
||||
assertEquals(GpsStatusValue.GPS_ENABLED, service.getGpsStatusObservable().getValue());
|
||||
|
||||
// when
|
||||
service.stopSensors(true);
|
||||
service.stopSensorsAndShutdown();
|
||||
Thread.sleep(1000);
|
||||
|
||||
// then
|
||||
@@ -252,7 +252,7 @@ public class TrackRecordingServiceTestStateMachine {
|
||||
assertEquals(GpsStatusValue.GPS_ENABLED, service.getGpsStatusObservable().getValue());
|
||||
|
||||
// when
|
||||
service.stopSensors(false); //TODO Should be ignored as service is recording
|
||||
service.stopSensors(); //TODO Should be ignored as service is recording
|
||||
Thread.sleep(1000);
|
||||
|
||||
// then
|
||||
|
||||
@@ -161,24 +161,6 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
return binder;
|
||||
}
|
||||
|
||||
@Deprecated //TODO Should be @VisibleForTesting
|
||||
public boolean isRecording() {
|
||||
return recordingStatus.isRecording();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public boolean isPaused() {
|
||||
return recordingStatus.isPaused();
|
||||
}
|
||||
|
||||
public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
|
||||
if (!isRecording() || isPaused()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trackRecordingManager.insertMarker(name, category, description, photoUrl);
|
||||
}
|
||||
|
||||
public Track.Id startNewTrack() {
|
||||
if (isRecording()) {
|
||||
Log.w(TAG, "Ignore startNewTrack. Already recording.");
|
||||
@@ -256,6 +238,8 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
endRecording(true);
|
||||
|
||||
ExportUtils.postWorkoutExport(this, trackId);
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||
@@ -275,11 +259,6 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
notificationManager.updateContent(getString(R.string.generic_paused));
|
||||
}
|
||||
|
||||
/**
|
||||
* Common code for ending a track or pausing a track.
|
||||
*
|
||||
* @param trackStopped true if track is stopped, false if track is paused
|
||||
*/
|
||||
private void endRecording(boolean trackStopped) {
|
||||
stopUpdateRecordingData();
|
||||
if (!trackStopped) {
|
||||
@@ -293,22 +272,23 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
// Update instance variables
|
||||
trackPointCreator.stop();
|
||||
|
||||
stopSensors(trackStopped);
|
||||
stopSensors();
|
||||
}
|
||||
|
||||
public void stopSensorsAndShutdown() {
|
||||
stopSensors(true);
|
||||
if (isRecording()) {
|
||||
return;
|
||||
}
|
||||
stopSensors();
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
void stopSensors(boolean shutdown) {
|
||||
void stopSensors() {
|
||||
if (!isRecording()) return;
|
||||
|
||||
trackPointCreator.stop();
|
||||
showNotification(false);
|
||||
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
||||
if (shutdown) {
|
||||
stopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -346,6 +326,14 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
}
|
||||
}
|
||||
|
||||
public Marker.Id insertMarker(String name, String category, String description, String photoUrl) {
|
||||
if (!isRecording() || isPaused()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trackRecordingManager.insertMarker(name, category, description, photoUrl);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@VisibleForTesting
|
||||
public TrackPointCreator getTrackPointCreator() {
|
||||
@@ -409,4 +397,14 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
recordingStatus = status;
|
||||
recordingStatusObservable.postValue(recordingStatus);
|
||||
}
|
||||
|
||||
@Deprecated //TODO Should be @VisibleForTesting
|
||||
public boolean isRecording() {
|
||||
return recordingStatus.isRecording();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public boolean isPaused() {
|
||||
return recordingStatus.isPaused();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user