forked from upstream-mirrors/OpenTracks
Bugfix: PublicAPI stop should not start TrackRecordingService in foreground.
Actually, TrackRecordingService will only be start in foreground if needed. Fixes #1824.
This commit is contained in:
@@ -159,7 +159,7 @@ public class TrackListActivity extends AbstractTrackDeleteActivity implements Co
|
||||
if (gpsStatusValue.isGpsStarted()) {
|
||||
recordingStatusConnection.stopService(this);
|
||||
} else {
|
||||
TrackRecordingServiceConnection.execute(this, (service, connection) -> service.tryStartSensors());
|
||||
TrackRecordingServiceConnection.executeForeground(this, (service, connection) -> service.tryStartSensors());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -178,7 +178,7 @@ public class TrackListActivity extends AbstractTrackDeleteActivity implements Co
|
||||
// Not Recording -> Recording
|
||||
Log.i(TAG, "Starting recording");
|
||||
updateGpsMenuItem(false, true);
|
||||
TrackRecordingServiceConnection.execute(this, (service, connection) -> {
|
||||
TrackRecordingServiceConnection.executeForeground(this, (service, connection) -> {
|
||||
Track.Id trackId = service.startNewTrack();
|
||||
|
||||
Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackRecordingActivity.class);
|
||||
|
||||
@@ -201,7 +201,7 @@ public class TrackRecordedActivity extends AbstractTrackDeleteActivity implement
|
||||
}
|
||||
|
||||
if (item.getItemId() == R.id.track_detail_resume_track) {
|
||||
TrackRecordingServiceConnection.execute(this, (service, connection) -> {
|
||||
TrackRecordingServiceConnection.executeForeground(this, (service, connection) -> {
|
||||
service.resumeTrack(trackId);
|
||||
|
||||
Intent newIntent = IntentUtils.newIntent(TrackRecordedActivity.this, TrackRecordingActivity.class)
|
||||
|
||||
@@ -136,7 +136,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements
|
||||
}
|
||||
|
||||
private void resumeTrackAndFinish() {
|
||||
TrackRecordingServiceConnection.execute(this, (service, connection) -> {
|
||||
TrackRecordingServiceConnection.executeForeground(this, (service, connection) -> {
|
||||
service.resumeTrack(trackId);
|
||||
|
||||
Intent newIntent = IntentUtils.newIntent(TrackStoppedActivity.this, TrackRecordingActivity.class)
|
||||
|
||||
+24
-2
@@ -42,6 +42,8 @@ public class TrackRecordingServiceConnection {
|
||||
|
||||
private static final String TAG = TrackRecordingServiceConnection.class.getSimpleName();
|
||||
|
||||
private static final int SERVICE_BIND_FLAG = BuildConfig.DEBUG ? Context.BIND_DEBUG_UNBIND : 0;
|
||||
|
||||
private final Callback callback;
|
||||
|
||||
private TrackRecordingService trackRecordingService;
|
||||
@@ -81,8 +83,19 @@ public class TrackRecordingServiceConnection {
|
||||
}
|
||||
|
||||
Log.i(TAG, "Binding the service.");
|
||||
int flags = BuildConfig.DEBUG ? Context.BIND_DEBUG_UNBIND : 0;
|
||||
context.bindService(new Intent(context, TrackRecordingService.class), serviceConnection, flags);
|
||||
|
||||
context.bindService(new Intent(context, TrackRecordingService.class), serviceConnection, SERVICE_BIND_FLAG);
|
||||
}
|
||||
|
||||
public void bindWithStart(@NonNull Context context) {
|
||||
if (trackRecordingService != null) {
|
||||
callback.onConnected(trackRecordingService, this);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Binding and starting the service (not in foreground).");
|
||||
|
||||
context.bindService(new Intent(context, TrackRecordingService.class), serviceConnection, Context.BIND_AUTO_CREATE + SERVICE_BIND_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +148,15 @@ public class TrackRecordingServiceConnection {
|
||||
}
|
||||
|
||||
public static void execute(Context context, Callback callback) {
|
||||
Callback withUnbind = (service, connection) -> {
|
||||
callback.onConnected(service, connection);
|
||||
connection.unbind(context);
|
||||
};
|
||||
new TrackRecordingServiceConnection(withUnbind)
|
||||
.bindWithStart(context);
|
||||
}
|
||||
|
||||
public static void executeForeground(Context context, Callback callback) {
|
||||
Callback withUnbind = (service, connection) -> {
|
||||
callback.onConnected(service, connection);
|
||||
connection.unbind(context);
|
||||
|
||||
Reference in New Issue
Block a user