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());
|
assertEquals(GpsStatusValue.GPS_ENABLED, service.getGpsStatusObservable().getValue());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
service.stopSensors(true);
|
service.stopSensorsAndShutdown();
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@@ -252,7 +252,7 @@ public class TrackRecordingServiceTestStateMachine {
|
|||||||
assertEquals(GpsStatusValue.GPS_ENABLED, service.getGpsStatusObservable().getValue());
|
assertEquals(GpsStatusValue.GPS_ENABLED, service.getGpsStatusObservable().getValue());
|
||||||
|
|
||||||
// when
|
// 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);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
|||||||
@@ -161,24 +161,6 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
return binder;
|
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() {
|
public Track.Id startNewTrack() {
|
||||||
if (isRecording()) {
|
if (isRecording()) {
|
||||||
Log.w(TAG, "Ignore startNewTrack. Already recording.");
|
Log.w(TAG, "Ignore startNewTrack. Already recording.");
|
||||||
@@ -256,6 +238,8 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
endRecording(true);
|
endRecording(true);
|
||||||
|
|
||||||
ExportUtils.postWorkoutExport(this, trackId);
|
ExportUtils.postWorkoutExport(this, trackId);
|
||||||
|
|
||||||
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||||
@@ -275,11 +259,6 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
notificationManager.updateContent(getString(R.string.generic_paused));
|
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) {
|
private void endRecording(boolean trackStopped) {
|
||||||
stopUpdateRecordingData();
|
stopUpdateRecordingData();
|
||||||
if (!trackStopped) {
|
if (!trackStopped) {
|
||||||
@@ -293,22 +272,23 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
// Update instance variables
|
// Update instance variables
|
||||||
trackPointCreator.stop();
|
trackPointCreator.stop();
|
||||||
|
|
||||||
stopSensors(trackStopped);
|
stopSensors();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopSensorsAndShutdown() {
|
public void stopSensorsAndShutdown() {
|
||||||
stopSensors(true);
|
if (isRecording()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stopSensors();
|
||||||
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopSensors(boolean shutdown) {
|
void stopSensors() {
|
||||||
if (!isRecording()) return;
|
if (!isRecording()) return;
|
||||||
|
|
||||||
trackPointCreator.stop();
|
trackPointCreator.stop();
|
||||||
showNotification(false);
|
showNotification(false);
|
||||||
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
||||||
if (shutdown) {
|
|
||||||
stopSelf();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Deprecated
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public TrackPointCreator getTrackPointCreator() {
|
public TrackPointCreator getTrackPointCreator() {
|
||||||
@@ -409,4 +397,14 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
recordingStatus = status;
|
recordingStatus = status;
|
||||||
recordingStatusObservable.postValue(recordingStatus);
|
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