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

View File

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