### Detect Apps with Mock Location Permissions Source: https://context7.com/smarques84/mocklocationdetector/llms.txt This method scans all installed applications on the device to identify any that have requested the `ACCESS_MOCK_LOCATION` permission. This is useful for identifying potential GPS spoofing tools. ```APIDOC ## Detect Apps with Mock Location Permissions ### Description Scans all installed applications on the device to identify apps that have requested the `ACCESS_MOCK_LOCATION` permission in their manifest. Useful for detecting potential GPS spoofing tools installed on the device. ### Method `MockLocationDetector.checkForAllowMockLocationsApps(Context context)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import android.content.Context; import com.inforoeste.mocklocationdetector.MockLocationDetector; // Check once during app initialization or periodically public void checkDeviceSecurity() { Context context = getApplicationContext(); // Scan all installed apps for mock location permissions boolean hasMockLocationApps = MockLocationDetector.checkForAllowMockLocationsApps(context); if (hasMockLocationApps) { // Device has apps capable of mocking locations Log.w("Security", "Found apps with mock location permissions installed"); // Show warning dialog to user new AlertDialog.Builder(this) .setTitle("Security Warning") .setMessage("Apps with location spoofing capabilities detected on your device. " + "This may affect location accuracy.") .setPositiveButton("OK", null) .show(); // Optionally restrict certain features or increase verification enableStrictLocationVerification(); } else { Log.i("Security", "No mock location apps detected"); disableStrictLocationVerification(); } } ``` ### Response #### Success Response (boolean) - **hasMockLocationApps** (boolean) - Returns `true` if any installed app has the `ACCESS_MOCK_LOCATION` permission, `false` otherwise. #### Response Example ```json { "hasMockLocationApps": true } ``` ``` -------------------------------- ### Real-time Mock Location Detection with Google Location Services (Java) Source: https://context7.com/smarques84/mocklocationdetector/llms.txt This example demonstrates real-time mock location detection using Google Play Services FusedLocationApi. It requires an Android Activity that implements GoogleApiClient callbacks and LocationListener. The output updates a TextView with location data and mock status, processing genuine locations and rejecting mock ones. ```java import android.location.Location; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.inforoeste.mocklocationdetector.MockLocationDetector; public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener { private GoogleApiClient mGoogleApiClient; private Location mCurrentLocation; private TextView mLocationStatus; private LocationRequest mLocationRequest; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLocationStatus = (TextView) findViewById(R.id.txt_location_status); // Initialize Google API Client if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); } } @Override public void onConnected(Bundle connectionHint) { // Configure location request for high accuracy updates mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(2000); // 2 seconds mLocationRequest.setFastestInterval(1000); // 1 second mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Start receiving location updates LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this); } @Override public void onLocationChanged(Location location) { mCurrentLocation = location; // Detect if location is mocked boolean isMock = MockLocationDetector.isLocationFromMockProvider(this, mCurrentLocation); boolean hasMockApps = MockLocationDetector.checkForAllowMockLocationsApps(this); // Update UI with location validation results String status = String.format( "Lat: %.6f, Lon: %.6f\nMock: %s\nMock Apps: %s", mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude(), isMock ? "DETECTED" : "No", hasMockApps ? "Present" : "None" ); mLocationStatus.setText(status); // Color-code based on detection if (isMock || hasMockApps) { mLocationStatus.setTextColor(0xFFFF0000); // Red // Reject mock location and don't process further return; } else { mLocationStatus.setTextColor(0xFF00FF00); // Green // Process valid location processLocation(mCurrentLocation); } } @Override protected void onStart() { super.onStart(); mGoogleApiClient.connect(); } @Override protected void onStop() { super.onStop(); LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this); mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int i) { } @Override public void onConnectionFailed(ConnectionResult connectionResult) { } private void processLocation(Location location) { // Process genuine location data // Send to server, update map, calculate distance, etc. } } ``` -------------------------------- ### Detect Apps with Mock Location Permissions (Java) Source: https://context7.com/smarques84/mocklocationdetector/llms.txt Scans all installed Android applications to find those requesting the `ACCESS_MOCK_LOCATION` permission. This is useful for identifying potential GPS spoofing tools. It requires an Android Context and returns a boolean indicating the presence of such apps. For API 23+, checking system settings for mock location enablement is deprecated. ```java import android.content.Context; import com.inforoeste.mocklocationdetector.MockLocationDetector; // Check once during app initialization or periodically public void checkDeviceSecurity() { Context context = getApplicationContext(); // Scan all installed apps for mock location permissions boolean hasMockLocationApps = MockLocationDetector.checkForAllowMockLocationsApps(context); if (hasMockLocationApps) { // Device has apps capable of mocking locations Log.w("Security", "Found apps with mock location permissions installed"); // Show warning dialog to user new AlertDialog.Builder(this) .setTitle("Security Warning") .setMessage("Apps with location spoofing capabilities detected on your device. " + "This may affect location accuracy.") .setPositiveButton("OK", null) .show(); // Optionally restrict certain features or increase verification enableStrictLocationVerification(); } else { Log.i("Security", "No mock location apps detected"); disableStrictLocationVerification(); } } ``` -------------------------------- ### Add MockLocationDetector Library Dependency to Gradle (Gradle) Source: https://context7.com/smarques84/mocklocationdetector/llms.txt This snippet shows how to add the MockLocationDetector library and its required dependencies to an Android project's build.gradle file. Ensure your `compileSdkVersion` and `targetSdkVersion` are compatible with the library and Google Play Services. ```gradle dependencies { // Add MockLocationDetector library compile 'com.inforoeste.mocklocationdetector:mock-location-detector:1.0.0' // Required dependencies for location services compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.google.android.gms:play-services-location:11.0.4' } android { compileSdkVersion 23 defaultConfig { minSdkVersion 15 // Library supports API 15+ targetSdkVersion 23 } } ``` -------------------------------- ### Check System Mock Location Setting (Deprecated) - Java Source: https://context7.com/smarques84/mocklocationdetector/llms.txt This Java method checks if the 'Allow Mock Locations' system setting is enabled. It is deprecated and only reliable on API levels 17 and lower. For API 23 and above, it always returns false due to changes in the Android system. It logs warnings or informational messages based on the setting's state and the Android version. ```java import android.content.Context; import com.inforoeste.mocklocationdetector.MockLocationDetector; import android.os.Build; @SuppressWarnings("deprecation") public void checkSystemSettings() { Context context = getApplicationContext(); // Check system-wide mock location setting (deprecated, API <= 22 only) boolean isMockLocationsEnabled = MockLocationDetector.isAllowMockLocationsOn(context); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { if (isMockLocationsEnabled) { Log.w("Settings", "Allow Mock Locations is enabled in system settings"); // On older devices, this indicates mock locations are system-enabled showWarning("Developer options may allow location spoofing"); } else { Log.i("Settings", "Allow Mock Locations is disabled"); } } else { // On API 23+, this method always returns false Log.i("Settings", "Mock location setting check not available on Android 6.0+"); // Use isLocationFromMockProvider() instead for modern Android versions } } ``` -------------------------------- ### Check if Location is from Mock Provider (Java) Source: https://context7.com/smarques84/mocklocationdetector/llms.txt Determines if a given Android Location object originates from a mock provider. It utilizes the native `isFromMockProvider()` method for API 18+ and falls back to checking system settings for older versions. It takes an Android Context and a Location object as input and returns a boolean indicating if the location is mocked. ```java import android.content.Context; import android.location.Location; import com.inforoeste.mocklocationdetector.MockLocationDetector; // In your Activity or Service with location updates public void onLocationChanged(Location location) { Context context = getApplicationContext(); // Check if the received location is from a mock provider boolean isMockLocation = MockLocationDetector.isLocationFromMockProvider(context, location); if (isMockLocation) { // Handle mock location detected Log.w("Location", "Mock location detected! Latitude: " + location.getLatitude() + ", Longitude: " + location.getLongitude()); showWarningToUser("Location spoofing detected"); // Optionally reject the location or take corrective action } else { // Location is genuine, proceed with normal processing Log.i("Location", "Genuine location: " + location.getLatitude() + ", " + location.getLongitude()); processValidLocation(location); } } ``` -------------------------------- ### Check if Location is from Mock Provider Source: https://context7.com/smarques84/mocklocationdetector/llms.txt This method checks if a given Location object originates from a mock location provider. It utilizes native Android APIs for API level 18+ and falls back to checking system settings for older versions. ```APIDOC ## Check if Location is from Mock Provider ### Description Primary method to detect if a specific location object originates from a mock provider. On API 18+, it uses the native `isFromMockProvider()` method. On lower API levels, it falls back to checking system settings for mock location enablement. ### Method `MockLocationDetector.isLocationFromMockProvider(Context context, Location location)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import android.content.Context; import android.location.Location; import com.inforoeste.mocklocationdetector.MockLocationDetector; // In your Activity or Service with location updates public void onLocationChanged(Location location) { Context context = getApplicationContext(); // Check if the received location is from a mock provider boolean isMockLocation = MockLocationDetector.isLocationFromMockProvider(context, location); if (isMockLocation) { // Handle mock location detected Log.w("Location", "Mock location detected! Latitude: " + location.getLatitude() + ", Longitude: " + location.getLongitude()); showWarningToUser("Location spoofing detected"); // Optionally reject the location or take corrective action } else { // Location is genuine, proceed with normal processing Log.i("Location", "Genuine location: " + location.getLatitude() + ", " + location.getLongitude()); processValidLocation(location); } } ``` ### Response #### Success Response (boolean) - **isMockLocation** (boolean) - Returns `true` if the location is from a mock provider, `false` otherwise. #### Response Example ```json { "isMockLocation": true } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.