chore: generic LstForegroundService housekeeping

This commit is contained in:
2026-03-22 09:20:13 +01:00
parent 708249a5ba
commit b6df86f49a
2 changed files with 11 additions and 6 deletions

View File

@@ -23,6 +23,8 @@ import androidx.core.app.NotificationCompat;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import at.lockstep.filter.StepDetector;
import at.lockstep.pb.PlaybackEngine;
@@ -129,7 +131,7 @@ public class LstForegroundService extends Service implements SensorEventListener
return;
}
startForeground(NOTIFICATION_ID, buildNotification("Lockstep is reading your steps ..."));
startForeground(NOTIFICATION_ID, buildNotification());
if (wakeLock != null && !wakeLock.isHeld()) {
// TODO: provide a timeout reasonable for a run
@@ -137,6 +139,8 @@ public class LstForegroundService extends Service implements SensorEventListener
}
if (accelerometer != null && sensorManager != null) {
// TODO: use a HandlerThread to handle sensor events in background thread, not the main thread
// see https://stackoverflow.com/q/17681870/1616948
sensorManager.registerListener(
this,
accelerometer,
@@ -200,11 +204,11 @@ public class LstForegroundService extends Service implements SensorEventListener
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
private Notification buildNotification(String contentText) {
private Notification buildNotification() {
return new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Lockstep is reading your pace.")
.setContentText(contentText)
.setSmallIcon(android.R.drawable.ic_menu_compass)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.notification_text))
.setSmallIcon(getApplicationInfo().icon)
.setOngoing(true)
.build();
}
@@ -213,7 +217,7 @@ public class LstForegroundService extends Service implements SensorEventListener
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Lockstep",
getString(R.string.app_name),
NotificationManager.IMPORTANCE_LOW
);

View File

@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Lockstep</string>
<string name="notification_text">Reading your steps …</string>
</resources>