Skip to content

Colota - Android GPS Location tracker

feat: log tracking lifecycle events for troubleshooting (#339)

Max Dietrichebaa007160c5
diff --git a/apps/mobile/src/contexts/TrackingProvider.tsx b/apps/mobile/src/contexts/TrackingProvider.tsx
index 6f18bc8c..42713c9c 100644
--- a/apps/mobile/src/contexts/TrackingProvider.tsx
+++ b/apps/mobile/src/contexts/TrackingProvider.tsx
@@ -171,7 +171,7 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) {
// when permission is revoked, leaving tracking_enabled stale
const perms = await checkPermissions()
if (!perms.location) {
- logger.debug("[TrackingContext] Permission lost, clearing stale tracking state")
+ logger.warn("[TrackingContext] Location permission lost, clearing stale tracking state")
await NativeLocationService.saveSetting("tracking_enabled", "false")
return
}
@@ -181,6 +181,7 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) {
// Restore active profile name from the running service
const profileName = await NativeLocationService.getActiveProfileName()
+ logger.debug(`[TrackingContext] Active profile on reconnect: ${profileName ?? "(default)"}`)
if (isMountedRef.current) {
setActiveProfileName(profileName)
}
@@ -220,7 +221,7 @@ export function TrackingProvider({ children }: { children: React.ReactNode }) {
useEffect(() => {
const listener = DeviceEventEmitter.addListener("onProfileSwitch", (event) => {
if (isMountedRef.current) {
- setActiveProfileName(event.profileName ?? null)
+ setActiveProfileName(event?.profileName ?? null)
}
})
return () => listener.remove()
diff --git a/apps/mobile/src/hooks/useLocationTracking.ts b/apps/mobile/src/hooks/useLocationTracking.ts
index 5b5d6cf3..1a74aa27 100644
--- a/apps/mobile/src/hooks/useLocationTracking.ts
+++ b/apps/mobile/src/hooks/useLocationTracking.ts
@@ -105,7 +105,7 @@ export function useLocationTracking(settings: Settings): LocationTrackingResult
return () => {
if (listenerRef.current) {
- logger.debug("[useLocationTracking] Detaching native listener")
+ logger.debug("[useLocationTracking] Removing JS event listener (foreground service unaffected)")
listenerRef.current.remove()
listenerRef.current = null
}
@@ -327,7 +327,7 @@ export function useLocationTracking(settings: Settings): LocationTrackingResult
*/
useEffect(() => {
return () => {
- logger.debug("[useLocationTracking] Component unmounted, service remains active")
+ logger.debug("[useLocationTracking] React component unmounted (foreground service still running)")
restartQueuedRef.current = false
restartingRef.current = false
}
diff --git a/apps/mobile/src/screens/DashboardScreen.tsx b/apps/mobile/src/screens/DashboardScreen.tsx
index 1b988685..cfa56915 100644
--- a/apps/mobile/src/screens/DashboardScreen.tsx
+++ b/apps/mobile/src/screens/DashboardScreen.tsx
@@ -161,6 +161,11 @@ export function DashboardScreen({ navigation }: ScreenProps) {
useEffect(() => {
const listener = DeviceEventEmitter.addListener("onLocationStateChanged", (data: { locationEnabled: boolean }) => {
+ if (data.locationEnabled) {
+ logger.debug("[Dashboard] Location services enabled")
+ } else {
+ logger.warn("[Dashboard] Location services disabled - GPS will not produce fixes until re-enabled")
+ }
setLocationEnabled(data.locationEnabled)
})
const appStateSub = AppState.addEventListener("change", (state) => {