MockLocationDetector Android Library

repository·master·Indexed 23 days ago

https://github.com/smarques84/mocklocationdetector

An Android library for detecting if a device is using mock locations. It provides methods to determine if a specific Location object is from a mock provider via isLocationFromMockProvider, check for apps with ALLOW_MOCK_LOCATIONS permissions using checkForAllowMockLocationsApps, and check the system-wide 'Allow Mock Locations' setting.

Tokens
350
Snippets
1
Records
4
Agent score
33%

What's inside MockLocationDetector

  1. Detect if a specific location is from a mock provider

    master

    Use isLocationFromMockProvider to determine if a received Location object was generated by a mock provider.

    Behavior by API level:

    • API 18+: Returns whether the specific location object is a mock.
    • API 17 and lower: Returns whether the system setting 'Allow Mock Locations' is currently enabled.

    This is the recommended method for most use cases.

  2. Check for apps with Mock Location permissions

    master

    Call checkForAllowMockLocationsApps to check if there are any applications installed on the user's device that have the ALLOW_MOCK_LOCATIONS permission declared in their manifest.

    This is useful for detecting attempts to bypass location security on older devices (API 17 or lower) where root access might be used to manipulate mock location settings at runtime. Note that on Android Marshmallow (API 23) and above, it is no longer possible to enable/disable mock locations at runtime via root permissions.