How BrokerOS tracks field agent locations in the background every minute using Expo TaskManager, SecureStore persistence, and low-power foreground services.
BrokerOS automatically monitors the real-time geographic location of field agents (Sales Executives, Sourcing Managers, and Closing Managers) during their scheduled working shifts.This tracking provides two core enterprise capabilities:
Live Management Oversight: Sales managers can view their entire field team on an interactive Google Maps overlay in the web dashboard.
Site Visit Validation: Real-time coordinates verify that sales executives were physically present at designated project sites during client meetings.
When the mobile application is minimized or the device screen is locked, Android spawns a headless JavaScript context to execute location updates. In this headless environment:
React state, context hooks, and component memory do not exist
Active session objects and web clients are uninitialized
To ensure the backend knows which employee is broadcasting coordinates, the dashboard shell writes the authenticated userId to expo-secure-store during boot. The headless task reads USER_ID_KEY from disk on every execution tick.
To prevent the Android operating system from killing the tracking process during background battery optimization, BrokerOS runs an Android Foreground Service with a persistent notification:
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { accuracy: Location.Accuracy.Balanced, timeInterval: 1 * 60 * 1000, // Executes every 1 minute distanceInterval: 0, // Triggers even if stationary deferredUpdatesInterval: 1 * 60 * 1000, showsBackgroundLocationIndicator: true, foregroundService: { notificationTitle: 'Live Tracking Active', notificationBody: 'Your location is being shared with the dashboard.', notificationColor: '#2563eb', },});
This persistent notification informs field employees that their location is being actively logged and ensures continuous execution across all Android OEM battery managers (Samsung, Xiaomi, OnePlus, Google Pixel).
Skips redundant backend API calls if the agent has moved less than 10 meters since the previous recorded ping:
const dist = getDistanceMeters(Number(lastLat), Number(lastLng), lat, lng);if (dist < 10) { // Movement under 10 meters. Skip API transmission to save battery. return;}
Requested upon initial dashboard mount. Provides high-precision coordinates.
Background Location
ACCESS_BACKGROUND_LOCATION
Prompts user to select βAllow all the timeβ in Android system settings.
Foreground Service
FOREGROUND_SERVICE_LOCATION
Required for continuous location broadcast notifications on Android 14+.
If an employee revokes background location permissions, tracking terminates when the app is minimized. The management dashboard will display their last known pin with a βLocation Staleβ warning indicator.