AOSP Framework & Internals
3 min read

LocationManagerService

Learn about LocationManagerService.

LocationManagerService (LMS) is the central coordinator for location-based services in Android. It acts as a multiplexer, taking location requests from multiple applications, routing them to the appropriate hardware or software providers, and dispatching the resulting coordinates back to the requesters.

Location Providers: GPS, Network, Fused

LMS does not compute locations directly. It relies on Location Providers:

  • GPS Provider: Communicates directly with the GNSS (Global Navigation Satellite System) hardware abstraction layer (HAL) via GnssLocationProvider. It provides highly accurate but battery-intensive coordinates.
  • Network Provider: Uses Wi-Fi MAC addresses and cell tower IDs. It sends this data to a remote server (like Google's location servers) to resolve coordinates.
  • Fused Location Provider (FLP): A smart aggregator. FLP intelligently combines GPS, Network, and sensor data (like accelerometers) to provide the best location quickly while optimizing battery life. On devices with Google Mobile Services (GMS), FLP is implemented within Google Play Services.

Location Updates and Callbacks

When an app requests location updates via LocationManager.requestLocationUpdates(), it specifies a provider, a minimum time interval, and a minimum distance.

  1. Request Registration: LMS receives the request via Binder, verifies permissions (ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION), and creates a LocationRequestRecord.
  2. Provider Activation: LMS evaluates all active requests for a provider and calculates the most demanding requirement (e.g., the shortest interval). It then configures the actual provider (like waking up the GNSS chip).
  3. Delivery: When the provider generates a Location object, it passes it to LMS. LMS iterates through all matching LocationRequestRecord instances and uses ILocationListener.onLocationChanged() to push the data across the Binder boundary to the app's callback.

Geofencing

Geofencing allows an app to register a geographical circle and be notified when the device enters or exits that circle.

Instead of waking the AP (Application Processor) continuously to check coordinates, modern Android delegates geofencing to the hardware (like the Wi-Fi chip or a low-power sensor hub) via the IGnssGeofencing HAL interface. GeofenceManager within LMS orchestrates this. When the hardware detects a boundary crossing, it sends an interrupt, waking the AP to dispatch the PendingIntent to the app.

Privacy: Location Access Gating

Starting with Android 10, location access is strictly gated. AppOpsManager works alongside LMS to enforce "Foreground Only" versus "Background" location access.

If an app requests a location while in the background without the ACCESS_BACKGROUND_LOCATION permission, LMS simply ignores the request or delivers a cached, coarse location depending on the exact OS version.

Furthermore, if the user toggles the global Location switch off in Quick Settings, LMS immediately stops all providers and ceases all callbacks, regardless of app-level permissions. You can inspect the current state of location requests using:

adb shell dumpsys location