forked from upstream-mirrors/OpenTracks
Bugfix: PublicAPI StartRecording recorded no data.
Problem was that the TrackRecordingService was not started as a ForegroundService anymore. Fixes #1904.
This commit is contained in:
@@ -31,13 +31,7 @@ public class PublicApiTest {
|
|||||||
|
|
||||||
private final Context context = ApplicationProvider.getApplicationContext();
|
private final Context context = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
@Test
|
//NOTE: this doesn't check if the TrackRecordingService was started in foreground.
|
||||||
public void StartTest() {
|
|
||||||
PreferencesUtils.setBoolean(R.string.publicapi_enabled_key, true);
|
|
||||||
|
|
||||||
context.startActivity(IntentUtils.newIntent(context, StartRecording.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void StartStopTest() throws InterruptedException {
|
public void StartStopTest() throws InterruptedException {
|
||||||
PreferencesUtils.setBoolean(R.string.publicapi_enabled_key, true);
|
PreferencesUtils.setBoolean(R.string.publicapi_enabled_key, true);
|
||||||
|
|||||||
@@ -33,11 +33,15 @@ public abstract class AbstractAPIActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
|
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
splashScreen.setKeepOnScreenCondition(() -> true );
|
splashScreen.setKeepOnScreenCondition(() -> true);
|
||||||
|
|
||||||
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.");
|
||||||
TrackRecordingServiceConnection.execute(this, serviceConnectedCallback);
|
if (requiresForeground()) {
|
||||||
|
TrackRecordingServiceConnection.executeForeground(this, serviceConnectedCallback);
|
||||||
|
} else {
|
||||||
|
TrackRecordingServiceConnection.execute(this, serviceConnectedCallback);
|
||||||
|
}
|
||||||
} 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.");
|
||||||
@@ -48,4 +52,8 @@ public abstract class AbstractAPIActivity extends AppCompatActivity {
|
|||||||
protected abstract void execute(TrackRecordingService service);
|
protected abstract void execute(TrackRecordingService service);
|
||||||
|
|
||||||
protected abstract boolean isPostExecuteStopService();
|
protected abstract boolean isPostExecuteStopService();
|
||||||
|
|
||||||
|
protected boolean requiresForeground() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,9 @@ public class StartRecording extends AbstractAPIActivity {
|
|||||||
protected boolean isPostExecuteStopService() {
|
protected boolean isPostExecuteStopService() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean requiresForeground() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user