forked from upstream-mirrors/OpenTracks
TrackRecordingService: always starts as foreground service.
This commit is contained in:
@@ -191,7 +191,7 @@ public class TrackListActivity extends AbstractTrackDeleteActivity implements Co
|
|||||||
startActivity(newIntent);
|
startActivity(newIntent);
|
||||||
|
|
||||||
connection.unbind(this);
|
connection.unbind(this);
|
||||||
}).startAndBind(this, true);
|
}).startAndBind(this);
|
||||||
});
|
});
|
||||||
viewBinding.trackListFabAction.setOnLongClickListener((view) -> {
|
viewBinding.trackListFabAction.setOnLongClickListener((view) -> {
|
||||||
if (!recordingStatus.isRecording()) {
|
if (!recordingStatus.isRecording()) {
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public class TrackRecordedActivity extends AbstractTrackDeleteActivity implement
|
|||||||
|
|
||||||
connection.unbind(this);
|
connection.unbind(this);
|
||||||
finish();
|
finish();
|
||||||
}).startAndBind(this, true);
|
}).startAndBind(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ public class TrackStoppedActivity extends AbstractTrackDeleteActivity implements
|
|||||||
|
|
||||||
connection.unbind(this);
|
connection.unbind(this);
|
||||||
finish();
|
finish();
|
||||||
}).startAndBind(this, true);
|
}).startAndBind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public abstract class AbstractAPIActivity extends AppCompatActivity {
|
|||||||
if (PreferencesUtils.isPublicAPIenabled()) {
|
if (PreferencesUtils.isPublicAPIenabled()) {
|
||||||
Log.i(TAG, "Received and trying to execute requested action.");
|
Log.i(TAG, "Received and trying to execute requested action.");
|
||||||
new TrackRecordingServiceConnection(serviceConnectedCallback)
|
new TrackRecordingServiceConnection(serviceConnectedCallback)
|
||||||
.startAndBind(this, isStartServiceForeground());
|
.startAndBind(this);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, getString(R.string.settings_public_api_disabled_toast), Toast.LENGTH_LONG).show();
|
Toast.makeText(this, getString(R.string.settings_public_api_disabled_toast), Toast.LENGTH_LONG).show();
|
||||||
Log.w(TAG, "Public API is disabled; ignoring request.");
|
Log.w(TAG, "Public API is disabled; ignoring request.");
|
||||||
@@ -46,10 +46,6 @@ public abstract class AbstractAPIActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isStartServiceForeground() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void execute(TrackRecordingService service);
|
protected abstract void execute(TrackRecordingService service);
|
||||||
|
|
||||||
protected abstract boolean isPostExecuteStopService();
|
protected abstract boolean isPostExecuteStopService();
|
||||||
|
|||||||
@@ -62,9 +62,4 @@ public class StartRecording extends AbstractAPIActivity {
|
|||||||
protected boolean isPostExecuteStopService() {
|
protected boolean isPostExecuteStopService() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isStartServiceForeground() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-16
@@ -82,23 +82,13 @@ public class TrackRecordingServiceConnection {
|
|||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void startAndBind(Context context) {
|
||||||
* Starts and binds the service.
|
|
||||||
*
|
|
||||||
* @param foreground is the service expected to call `startForeground()`?
|
|
||||||
*/
|
|
||||||
public void startAndBind(Context context, boolean foreground) {
|
|
||||||
if (trackRecordingService != null) {
|
if (trackRecordingService != null) {
|
||||||
// Service is already started and bound.
|
// Service is already started and bound.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Starting the service.");
|
ContextCompat.startForegroundService(context, new Intent(context, TrackRecordingService.class));
|
||||||
if (foreground) {
|
|
||||||
ContextCompat.startForegroundService(context, new Intent(context, TrackRecordingService.class));
|
|
||||||
} else {
|
|
||||||
context.startService(new Intent(context, TrackRecordingService.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
startConnection(context);
|
startConnection(context);
|
||||||
}
|
}
|
||||||
@@ -112,7 +102,7 @@ public class TrackRecordingServiceConnection {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public void startAndBindWithCallback(Context context) {
|
public void startAndBindWithCallback(Context context) {
|
||||||
if (trackRecordingService == null) {
|
if (trackRecordingService == null) {
|
||||||
startAndBind(context, false);
|
startAndBind(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
@@ -151,13 +141,12 @@ public class TrackRecordingServiceConnection {
|
|||||||
|
|
||||||
private void setTrackRecordingService(TrackRecordingService value) {
|
private void setTrackRecordingService(TrackRecordingService value) {
|
||||||
trackRecordingService = value;
|
trackRecordingService = value;
|
||||||
if (callback != null) {
|
if (callback != null && value != null) {
|
||||||
if (value != null) {
|
|
||||||
callback.onConnected(value, this);
|
callback.onConnected(value, this);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO Move to some other place; not needed here.
|
||||||
@Nullable
|
@Nullable
|
||||||
public Marker.Id addMarker(Context context, String name, String category, String description, String photoUrl) {
|
public Marker.Id addMarker(Context context, String name, String category, String description, String photoUrl) {
|
||||||
if (trackRecordingService == null) {
|
if (trackRecordingService == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user