Goin
Goin

Reputation: 3964

is there any way to read "select mock location app" from Android developer settings?

I know the recomended way to know in Android if a location is a fake point is something like this:

boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
    isMock = location.isFromMockProvider();
} else { // Old Android versions (<6)
    isMock = !Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}

So, for current Androids I have to request location permission to know if this is a mock location. But I think it is not necessary if I can read "select mock location app".

hunk of Android developer options huk

Also, if you want to show an alert message you can custom this message. e.g.: You could say something like this: "Please remove com.lexa.fakegps app". And when user clicks on "Accept", you could redirect to next link: https://play.google.com/store/apps/details?id=com.lexa.fakegps

Also, there are fake gps apps that return false in the isFromMockProvider method.

Also, you can do stats with apps more use for yours users.

And finally, I don't understood why you can read every setting of developer settings except "select mock location app":

https://developer.android.com/reference/android/provider/Settings

Is there any solution? Or simply is it a stupid impossible thing?

Upvotes: 3

Views: 5408

Answers (2)

AgentP
AgentP

Reputation: 7240

So first of all... by using the following code

boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
    isMock = location.isFromMockProvider();
} else { // Old Android versions (<6)
    isMock = !Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}

you can't ensure the device location is faked all the time.

For older versions of android

isMock = !Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");

is being used but what it does basically it just gives whether the user turned on the settings for allowing mock location... so it just acts as a filter to check

So if I am using an old phone and turn this setting on even if I am not using fake location it still returns true

For latest versions of android

isMock = location.isFromMockProvider();

it is buggy ... may not always return correct answer i.e even if you set the location using mock location app sometimes it may return false.

Conclusion:

To conclude reading the "select mock location app" setting and making a decision on its value is just a stupid thing. and you can't write software that is always bug-free.

I personally tried and tested with some of the fake GPS apps like
Lexa Fake GPS Location
Fake GPS

for me during my tests isFromMockProvider() always returned me the correct output So I found it the probability of finding the bug is rare.

And in order to make sure it's a buggy value I found this remedy on this post : Location on Android: Stop Mocking Me! I quote remedy from this article

Since most location readings are correctly labeled, it’s not too difficult to identify and reject the false negatives. I chose the following strategy:

  • Remember the most recent location labeled as a mock

  • If a new “non-mock” reading is within 1km of the last mock, reject it.

  • Only clear the last mock location after 20 consecutive “non-mock” readings.

And I also recommend you to go through FauChristian Answer for Detect or prevent if the user uses fake location

Thank you...

Upvotes: 1

Luke Duncan
Luke Duncan

Reputation: 471

I haven't tested this but this looks legit. I spent an hour or so trying to come up with my own solution and it was right there on GitHub.

https://github.com/GantMan/jail-monkey/blob/master/android/src/main/java/com/gantix/JailMonkey/MockLocation/MockLocationCheck.java

Upvotes: 2

Related Questions