From 8675f816decbeec60671be2a2de0844c8383cdff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 24 Nov 2025 20:12:34 +0000 Subject: [PATCH] Fix code review feedback: improve error handling and service logic Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com> --- .../securesms/geolocation/DcLocationManager.java | 2 +- .../securesms/geolocation/LocationBackgroundService.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/geolocation/DcLocationManager.java b/src/main/java/org/thoughtcrime/securesms/geolocation/DcLocationManager.java index a9b1bbcf7..f253014f6 100644 --- a/src/main/java/org/thoughtcrime/securesms/geolocation/DcLocationManager.java +++ b/src/main/java/org/thoughtcrime/securesms/geolocation/DcLocationManager.java @@ -65,7 +65,7 @@ public class DcLocationManager implements Observer { } public void stopLocationEngine() { - if (serviceBinder == null && !serviceBound) { + if (serviceBinder == null || !serviceBound) { return; } try { diff --git a/src/main/java/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java b/src/main/java/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java index 6d61b8927..4162dda5a 100644 --- a/src/main/java/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java +++ b/src/main/java/org/thoughtcrime/securesms/geolocation/LocationBackgroundService.java @@ -53,15 +53,16 @@ public class LocationBackgroundService extends Service { // Create notification channel if needed createNotificationChannel(); - // Start foreground service with notification - startForeground(NotificationCenter.ID_LOCATION, createNotification()); - locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE); if (locationManager == null) { Log.e(TAG, "Unable to initialize location service"); + stopSelf(); return; } + // Start foreground service with notification after successful initialization + startForeground(NotificationCenter.ID_LOCATION, createNotification()); + locationListener = new ServiceLocationListener(); Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (lastLocation != null) {