3

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?

Goin
  • 3,856
  • 26
  • 44

2 Answers2

2

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

Luke Duncan
  • 461
  • 2
  • 6
  • you can't ensure whether the current location is mock by this method ... what it basically does is if my app is asking for mock location permission then it will return true even though the app is not setting mock location ...and if the other apps setting mock location it will return false ... – AgentP May 30 '20 at 14:00
  • I saw this example in this link: https://www.it-swarm.dev/es/android/deshabilitarverificar-la-ubicacion-simulada-evitar-la-simulacion-de-gps/940536196/ But there is a typo error in my link ".equals("Android.permission.ACCESS_MOCK_LOCATION")" Android instead of android. I don't want this exactly por example in my case three apps have ACCESS_MOCK_LOCATION: com.gsmartstudio.fakegps (fake gps app), com.lexa.fakegps (fake gps app) com.oem.oemlogkit (OnePlusLogKit). But thanks it is more than nothing – Goin Jun 02 '20 at 10:21
1

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...

AgentP
  • 6,261
  • 2
  • 31
  • 52
  • I'm sorry but your answer is not an answer. I knew everything you say... For this reason my question starts with: "I know the recomended way to know in Android..." But why can I not know the value of a developer configuration? I understand the recomendation to determine fake gps is isFromMockProvider method. But if I want to do stats, or anticipate to request location? is it a stupid thing? o_O Imagine a process with 10 steps and in the last step app needs location. And then app says you: "Your location is fake bla bla". I think if app says something in first step we get more usability – Goin Jun 02 '20 at 10:32
  • @Goin As I said Basically just by knowing that variable value you can't determine wheather the location is mock or not may be due to that it might be removed ... and moreover there are other methods to collect stats from your users ... we should consider those keeping user privacy in mind ... if someone want my location I must be aware that they want to know my location that's why developer must request runtime permission. I don't want any app that usually keep an eye on my location without asking me. Even if it is for good – AgentP Jun 02 '20 at 13:09
  • 1. yes, you said "knowing that variable value you can't determine wheather the location is mock or not " but it is not my question. 2. Why can I read for example if I have enabled "USB debugging" and I can not read "Select mock location app"? Why can I read every Android developer settings and I can not read "Select mock location app"? – Goin Jun 02 '20 at 15:06
  • 1
    @Goin I think we should ask this to the android team. In my opinion, there is no point in knowing it at all programmatically ...I will update you if I find anything regarding the same – AgentP Jun 02 '20 at 15:09
  • Thanks and keep your mind open. Even if it was an error... I should be able read this configuration. – Goin Jun 02 '20 at 15:19