1

I'm having an issue with mock location providers. I have an app that needs to get accurate valid locations, and I don't want the user to be able to spoof them. So I have a check for the mock locations enabled setting, which works fine.

However there is a problem with the location provider. If you enable mock locations, set a location with a gps faker app, then disable mock locations and all other location providers, the location manager still has a reference to the mock location provider. So although mock locations are disabled, the location manager tells me that gps is enabled, and serves mocked location data.

I know that you can clear test providers from the location manager, but mock locations must be enabled to do this

Anyone ever come across this, or have a work around?

Theblacknight
  • 575
  • 5
  • 12

2 Answers2

3

Think I found a way to get an accurate reading whether GPS/Network provider are enabled or not:

ContentResolver contentResolver = context.getContentResolver();
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.GPS_PROVIDER);
boolean networkEnabled = Settings.Secure.isLocationProviderEnabled(contentResolver, LocationManager.NETWORK_PROVIDER);
Theblacknight
  • 575
  • 5
  • 12
1

Are you sure you've called :

  • removeUpdates()
  • removeTestProvider()
  • setTestProviderEnabled() with false
  • clearTestProviderEnabled() ?

Look at how LocationManagerTest does this.

// disable mocking. 
Settings.Secure.putString(getContentResolver(),
       Settings.Secure.ALLOW_MOCK_LOCATION, "0");
Reno
  • 33,594
  • 11
  • 89
  • 102
  • The problem with calling these methods is that you need mock locations to be enabled for it to work.. I guess I could clear out the location manager in the onResume of my activities, but I don't want to be hassling the user to enable mock locations. – Theblacknight Oct 21 '11 at 09:47
  • You can enable and disable this setting silently, see my edit. – Reno Oct 21 '11 at 10:59
  • 1
    Oh, cool .. will try this out when I get a chance. Didn't think you could disable system settings like this.. – Theblacknight Oct 21 '11 at 14:13
  • To do this I need the WRITE_SECURE_SETTINGS permission, which I won't be able to get my hands on: http://stackoverflow.com/questions/5034160/how-can-i-get-the-dreaded-write-secure-settings-permission-for-my-android-app – Theblacknight Oct 21 '11 at 18:15