Geo Tracking - Specs

Android tracking

Location service, permissions, persistence, synchronization, and limitations of the Kotlin implementation.

Native implementation

Android uses the local GeoMonitoring Expo module. GeoMonitoringModule exposes methods to JavaScript; TrackingEngine manages the session, queue, and transport; TrackingForegroundService requests positions from the Fused Location Provider.

The implementation uses com.google.android.gms:play-services-location:21.3.0, as declared in the module dependencies. This implementation depends on Google location services; no alternative provider is implemented for devices without this component.

Engine operations are serialized through an executor. Another executor handles network requests. Responses return to the owning executor before modifying configuration, counts, and state.

Permissions and local startup

The interface guides authorization in this order:

  1. Checks location authorization status.
  2. Requests access while using the app when necessary.
  3. Requests background location access and requires the background status before proceeding.
  4. Requests notifications when that permission exists on Android.
  5. Calls startTracking() after checking for cancellation.

The native check in TrackingEngine.start() requires ACCESS_FINE_LOCATION. The full flow also requires the background status at the application layer; this should not be confused with a second identical check inside that method.

Permission or settingUse in the project
ACCESS_FINE_LOCATIONPrecise positions; checked before startup and new requests
ACCESS_COARSE_LOCATIONRequested together with location access while using the app
ACCESS_BACKGROUND_LOCATIONBackground authorization flow
FOREGROUND_SERVICEForeground service
FOREGROUND_SERVICE_LOCATIONLocation service type
POST_NOTIFICATIONSExplicit request on Android 13 and later
INTERNET and ACCESS_NETWORK_STATETransport and connectivity recovery

If notification permission is denied, the flow records the result but does not treat it as a blocker equivalent to denied location access. Execution remains subject to the system rules for foreground services.

The application instructs the user to start with the screen open. If the initial call to startForegroundService throws an exception, the engine rolls back the newly saved local authorization and returns an error. If the failure occurs later, when promoting the service with startForeground, the service stops and records a collection error, but local authorization remains. An authorized session therefore does not prove that the service is collecting positions.

Service and notification

The manifest declares a non-exported service with foregroundServiceType="location" and stopWithTask="false". The service creates a low-importance channel and displays a persistent notification.

The notification shows whether the service is preparing, actively collecting, or paused, and includes a Stop tracking action. This action invokes the engine's same local stop operation: it revokes authorized, removes updates, and stops the service.

The service returns START_STICKY during normal startup. If the system recreates it, the engine checks the persisted authorization. A session without authorization or a configured connection causes the service to stop again.

START_STICKY does not guarantee execution after every termination. The module does not implement a boot receiver to restore tracking; the RECEIVE_BOOT_COMPLETED permission present in the application does not perform that restoration on its own.

Requesting positions

Each new collection configuration first removes the previous request. A generation counter prevents the delayed completion of an old request from restarting collection with outdated parameters.

Option sent to the providerApplied value
PriorityPRIORITY_HIGH_ACCURACY
Requested intervalintervalSeconds × 1000
Minimum intervalSame as the requested interval
Minimum distancedistanceFilterMeters
Maximum batch delayZero
Maximum initial ageZero
Wait for a more accurate positionDisabled

These options guide the provider but do not guarantee an exact cadence or fixed accuracy. The current strategy stays at high accuracy; it does not switch based on motion detection.

In the callback, the engine only accepts positions while local authorization, remote permission to collect, available storage, and an associated service are all present. Positions without reported accuracy are ignored. Latitude, longitude, accuracy, and date are validated when constructing the event.

The native event uses the Android position's own timestamp and provider:native. Each position receives a new UUID; retries preserve the same persisted event.

On-device persistence

The actual queue is stored in geo-tracking.db. SQLite uses WAL and synchronous=FULL; each insertion writes the position and the latest-position metadata in a transaction.

The tables are locations, with a local sequence and unique event_id, and metadata, with remote configuration, counts, and synchronization information. The next batch contains the first 100 rows in insertion order.

The endpoint, identifier, token, and local authorization are stored in private SharedPreferences, in the geoTrackingCredentials set. Native storage of this token does not use Android Keystore or encrypted preferences in the current code. The installation enrollment key uses the enrollment layer's secure mechanism; these are separate storage mechanisms.

The application sets allowBackup=false. State sent to JavaScript does not contain the token.

If saving a location fails, the engine marks storage as blocked, pauses collection, and preserves the existing queue. After resolving the cause, the message instructs the user to start again. There is no automatic cleanup of pending records based on age or count.

Synchronization and remote configuration

The engine attempts synchronization after captures, injections, configuration, startup, and manual requests. It also performs native checks every 15 seconds while there is an authorized session or pending records.

When connectivity becomes available, it clears the retry wait and triggers an attempt. This requires the process to be running; it is not a persistent scheduler independent of the process.

With an empty queue, the transport makes a configuration GET request. With positions, it makes a batch POST request and receives the configuration along with the acknowledged IDs. Older configurations are ignored; configurations with the same or a higher version may be applied.

Failures lead to waits of 2, 4, 8 seconds, and so on. Because the counter saturates at 8, the effective wait stabilizes at 256 seconds. There is one scheduled attempt and only one request in flight.

The transport uses HttpURLConnection, connection and read timeouts of 15 seconds, responses of up to 1,000,000 bytes, and disabled redirects. The token is sent in the Bearer header.

Pausing, stopping, and switching devices

A remote pause removes location updates and keeps the service running with a paused message. This preserves the local session and allows it to check for configuration changes while the process remains active.

A local stop persists authorized=false, removes updates, and stops the service. It does not remove pending positions; the engine may deliver them later.

Changing the endpoint or deviceId requires a stopped session, an empty queue, and no synchronization in progress. This prevents records from one device from being sent to another device's destination. The change clears metadata associated with the previous device. Renewing the token for the same identity does not erase the queue.

Evidence and limitations

The repository contains instrumented tests for the queue, position validation, and remote configuration, as well as records of emulator trials with the app on the HOME screen, an offline queue, lost ACKs, and local stopping.

These results do not prove operation across every device brand. Force-stop, reboot, extended power-saving periods, and battery consumption require specific evaluation. See Tests and Field testing.

The polygon service uses GeofencingClient and separate storage. Its events and limitations are covered in Polygons; they are not the SQLite route queue.

Repository sources

  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/GeoMonitoringModule.kt
  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingEngine.kt
  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingForegroundService.kt
  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingStore.kt
  • geo-demo/modules/geo-monitoring/android/src/main/java/expo/modules/geomonitoring/TrackingTransport.kt
  • geo-demo/modules/geo-monitoring/android/src/main/AndroidManifest.xml
  • geo-demo/android/app/src/main/AndroidManifest.xml
  • geo-demo/src/features/tracking/start-tracking.ts

On this page