How to stop fake locations using LocationClient on Android - android

I'm working on a GPS game, similar to geocaching, which requires the devices accurate GPS cordinates.
I am using LocationClient and not LocationManager.
Early in testing, a friend pointed out that the location can be faked using free apps on the play store. A bit of research shows that without root, these apps require Mock Location to be enabled. So I started with a simple check to see if mock location was enabled, and if it was then the app would not allow the user to play until it is disabled.
This got me thinking though, users who are rooted could still fake their location without having mock location enabled, however most of these apps still have the MOCK_LOCATION permission regardless if the device is rooted or not. So I used a method that detects any apps that require Mock Location. The problem is, even on my non rooted Note 3, there appears to be several pre-installed apps that require Mock Location for some reason, which then prevents game play. So this solution wont work.
Is there any other way to check if a location might be faked using LocationClient?

In API 18+ you can use Location.isFromMockProvider to check if a particular location is mocked. This flag will be set to true if an app is providing mocked (fake) locations or if you are using a mock provider in your own app.
Of course, rooted phones can bypass this.

In your device, go to settings >> developer options >> allow mock locations
This option must be checked in you device that's why you are getting mock location updates. To stop receiving just uncheck it.
In your code, you can also set mLocationClinet.setMockMode(false); in your onCreate() method of Location tracking activity.
I hope it works :)

Related

Android - Appium's mocked location will be overwritten by Wi-Fi, Bluetooth and mobile networks

Within my Appium tests for an Android app I am using Appium's setLocation() of AndroidDriver to mock a location. This works properly, but since the app is requiring "High Accuracy" as location method the mocked location will be overwritten after a few seconds by the location which is generated by Wi-Fi, Bluetooth and mobile networks.
Is there any solution or workaround for this kind of issue? I want to set the location permantly (for the whole duration of the test), but can't change that the app is forcing the user to enable "High accuracy" mode.
Btw: I'm testing on a lot of different real devices and not on emulators.
First enable developer option in your phone.
Go to your phone Settings > About > Tap Rapidly on Build Number until it says “You are now a developer.”
Then go into your Developer Setting and check Allow mock locations.
Now you need to Download App that will allow you to fake the GPS location. There are several different apps that can do this. You can find free app in play store.
Finally you can select a random spot somewhere in the world and activate the fake location using the app.

Run own app on an Android device that mocks GPS location

Is there a reliable way to mock GPS location on an Android device (rather than emulator)? I know there are several ways how to do it in the emulator, but I'd like to run my app on the device. I am not interested in existing apps like "Fake GPS location" etc., I want to get my hands dirty by logging actual GPS data and then "playing" it back with various adjustments, so I need to write my own code.
I see on my Android 7.0 device that there is a setting "Select mock location app" under the Developer options in Settings. Strangely, it lets me to select Samsung "Messages" app as the mocker app, I can't imagine why and how exactly this app would do the location mocking. Anyway, it seems that if I learn how to manifest in my code that I want to mock GPS location, my app would hopefully appear in this list available for selection.
I read that things have changed in this area over years, so online references might not be up-to-date and bring more confusion than help.

Is there a way to detect Location is OFF on Android Wear Watch as opposed to not present

I have developed a Referee Watch (https://play.google.com/store/apps/details?id=com.pipperpublishing.soccerrefpro) which tracks referees field coverage and other fitness stats using the watch GPS. This is NOT a question about ACCESS_FINE_LOCATION permissions which I am handling just fine.
I understand I can use getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPSto determine if the Watch has GPS. However, if a user accidentally turns OFF Settings>Location on the Watch, is there a way of detecting it? I suspect the watch will report TRUE for the above call, but then attempt to deliver location using the Fused Location Provider from the phone wifi/gps/cell. That of course is useless once you are running on the field with the phone in the bag.
I have tried looking at the Fitness Sensor sources and determining whether the source is Local or not, but that doesn't seem to work.
If you've already determined whether your Android Wear device has a built-in GPS sensor using the hasSystemFeature() method, then you can proceed with handling disconnection events.
You may want to implement onPeerDisconnected() method so that your app should be able to handle loss of location data in case the wear device loses connection with its paired device.
Also, check this SO post for additonal insights on how to trigger a system UI to get that permission to enable location dialog.

Android show android natice pop up settings/cancel to enable location service

I am working on an android application that uses geo location services, when the user accesses such service if location access is disabled on the device i want to call android native pop up that guides user to enabled location access. Is it possible to do this ?
I noticed there's even better way to achieve good location settings, without "guiding" user to turn them on, mentioned in this question:
Enabling Location with mode High Accuracy or Battery saving without user needing to visit Settings
Since Google Play Services 7.0 you can ask system to offer user turning the settings on with one touch. It's how Google Maps are doing it.

Using Android internal API to turn on GPS

Is there any hidden (internal) API function for turning on/off the GPS? Is it a valid solution (legally and safely) to use android internal API's? If it is not valid, how can I obtain a license/signature for using those API's?
I have already tried the methods using SDK/NDK and I understood that it is not possible to turn GPS on with the SDK/NDK (I know that we can bring up the settings screen). I want to know whether there is any hidden/internal API's for doing that. Also I am not interested in using any vulnerabilities in Android as a solution.
You need root privileges. Mandatory. Period.
And yes there is API to enable/disable GPS. But the application must receive SuperAdmin privileges. To obtain it either root or custom ROM required.
Sample: https://github.com/sms2000/GPSToggler
There is no hidden API for controlling the GPS. There is no valid solution.
(Like you mentioned), the correct thing to do is ask the user to turn it on. If an app could override the users option, there would be no point in it being an option and this would be a huge security rick.
If the user chooses to keep the GPS off then your apps should do the same thing it would do if the GPS was on but couldn't get a lock. Not respecting their wished to keep it off would be malicious even if you don't plan on doing anything morally wrong with the data.
If you have some client that wants their employees to not be able to turn off the GPS, then you need to give them phones with custom roms.
If you are trying to make a security app that reports location you can use wifi location and last known location too in addition to GPS.

Categories

Resources