- Add ability to detect if location was mocked

Summary:
Since API 18, Android locations have had the `isFromMockProvider()` function, to verify the validity of a provided location.  This was one of many methods one could verify location data, but as of Marshmallow, the other ways of detecting if "Mock Locations" is on in developer settings has been deprecated or defunct.

This means some devices can only detect location mocking by exposing the method on the location object.

This change provides that exposure.
Closes https://github.com/facebook/react-native/pull/9390

Differential Revision: D3858205

Pulled By: bestander

fbshipit-source-id: 3bae429cc0596ea01926c5be204f4403e4a2414f
This commit is contained in:
Gant Laborde 2016-09-20 05:46:59 -07:00 committed by Facebook Github Bot 1
parent f839627605
commit c6024f6391
3 changed files with 23 additions and 1 deletions

View File

@ -31,7 +31,7 @@ type GeoOptions = {
} }
/** /**
* The Geolocation API follows the web spec: * The Geolocation API extends the web spec:
* https://developer.mozilla.org/en-US/docs/Web/API/Geolocation * https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
* *
* As a browser polyfill, this API is available through the `navigator.geolocation` * As a browser polyfill, this API is available through the `navigator.geolocation`
@ -48,6 +48,9 @@ type GeoOptions = {
* *
* `<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />` * `<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />`
* *
* Android API >= 18 Positions will also contain a `mocked` boolean to indicate if position
* was created from a mock provider.
*
*/ */
var Geolocation = { var Geolocation = {

View File

@ -214,6 +214,11 @@ public class LocationModule extends ReactContextBaseJavaModule {
coords.putDouble("speed", location.getSpeed()); coords.putDouble("speed", location.getSpeed());
map.putMap("coords", coords); map.putMap("coords", coords);
map.putDouble("timestamp", location.getTime()); map.putDouble("timestamp", location.getTime());
if (android.os.Build.VERSION.SDK_INT >= 18) {
map.putBoolean("mocked", location.isFromMockProvider());
}
return map; return map;
} }

14
flow/Position.js Normal file
View File

@ -0,0 +1,14 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
declare class Position {
coords: Coordinates,
timestamp: number,
mocked: boolean,
}