├── .gitattributes ├── android ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── mocklocation │ │ └── reactnative │ │ ├── RNMockLocationDetectorPackage.java │ │ └── RNMockLocationDetectorModule.java ├── build.gradle ├── gradlew.bat └── gradlew ├── index.d.ts ├── index.js ├── .gitignore ├── package.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adkandari/react-native-mock-location-detector/HEAD/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare const RNMockLocationDetector: { 2 | checkMockLocationProvider: () => Promise; 3 | }; 4 | 5 | export default RNMockLocationDetector; 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | import { NativeModules } from 'react-native'; 3 | 4 | const { RNMockLocationDetector } = NativeModules; 5 | 6 | export default RNMockLocationDetector; 7 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Android/IntelliJ 14 | # 15 | build/ 16 | .idea 17 | .gradle 18 | local.properties 19 | *.iml 20 | 21 | # BUCK 22 | buck-out/ 23 | \.buckd/ 24 | *.keystore 25 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-detect-mock-location", 3 | "version": "1.0.0", 4 | "description": "Detects if the device is using mock location app to spoof it's real location. In that case user will be prompted to fix the mock location settings first before using the app.", 5 | "main": "index.js", 6 | "scripts": {}, 7 | "keywords": [ 8 | "react native", 9 | "location spoofing", 10 | "mock location" 11 | ], 12 | "author": "Zain Ul Abdin ", 13 | "license": "MIT", 14 | "homepage": "https://github.com/zainkhas/react-native-detect-mock-location", 15 | "bugs": { 16 | "url": "https://github.com/zainkhas/react-native-detect-mock-location/issues" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/zainkhas/react-native-detect-mock-location.git" 21 | }, 22 | "peerDependencies": { 23 | "react-native": "^0.41.2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | google() 6 | } 7 | 8 | dependencies { 9 | classpath("com.android.tools.build:gradle:3.5.3") 10 | } 11 | } 12 | 13 | apply plugin: 'com.android.library' 14 | 15 | android { 16 | compileSdkVersion 29 17 | buildToolsVersion = "29.0.2" 18 | 19 | defaultConfig { 20 | minSdkVersion 21 | targetSdkVersion 29 22 | versionCode 1 23 | versionName "1.0" 24 | } 25 | lintOptions { 26 | abortOnError false 27 | } 28 | } 29 | 30 | repositories { 31 | mavenCentral() 32 | mavenLocal() 33 | google() 34 | jcenter() 35 | maven { url "https://jitpack.io" } 36 | maven { url "https://maven.google.com" } 37 | } 38 | 39 | dependencies { 40 | implementation 'com.facebook.react:react-native:+' 41 | implementation 'com.google.android.gms:play-services-location:21.0.1' 42 | } 43 | -------------------------------------------------------------------------------- /android/src/main/java/com/mocklocation/reactnative/RNMockLocationDetectorPackage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.mocklocation.reactnative; 3 | 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | public class RNMockLocationDetectorPackage implements ReactPackage { 14 | @Override 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | return Arrays.asList(new RNMockLocationDetectorModule(reactContext)); 17 | } 18 | 19 | // Deprecated from RN 0.47 20 | public List> createJSModules() { 21 | return Collections.emptyList(); 22 | } 23 | 24 | @Override 25 | public List createViewManagers(ReactApplicationContext reactContext) { 26 | return Collections.emptyList(); 27 | } 28 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Hi, I am sorry I am not maintaining this library from quite sometime now. You can check a new fork of this one https://github.com/jpudysz/react-native-turbo-mock-location-detector, looks like it is maintained regularly. Thanks to https://github.com/jpudysz 2 | 3 | ## React Native Mock Location Detector / Location Spoof Apps Detector 4 | 5 | ⚠️ A fork of [react-native-mock-location-detector](https://github.com/adkandari/react-native-mock-location-detector) but with fixes. 6 | 7 | If you are building a location based app in RN, you have to validate if the user is using location spoofing apps or not. This library doesn't let the user use the app if any mock location apps are active on the device 8 | 9 | ![Image description](https://i.imgur.com/iT7OpSs.gif) 10 | 11 | ## Getting started 12 | 13 | `$ npm install react-native-detect-mock-location --save` 14 | 15 | ### Mostly automatic installation 16 | 17 | `$ react-native link react-native-detect-mock-location` 18 | 19 | ### Manual installation 20 | 21 | #### Android 22 | 23 | 1. Open up `android/app/src/main/java/[...]/MainActivity.java` 24 | 25 | - Add `import com.mocklocation.reactnative.RNMockLocationDetectorPackage;` to the imports at the top of the file 26 | 27 | - Add `new RNMockLocationDetectorPackage()` to the list returned by the `getPackages()` method 28 | 29 | 2. Append the following lines to `android/settings.gradle`: 30 | 31 | ``` 32 | 33 | include ':react-native-mock-location-detector' 34 | 35 | project(':react-native-mock-location-detector').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mock-location-detector/android') 36 | 37 | ``` 38 | 39 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: 40 | 41 | ``` 42 | 43 | implementation project(':react-native-mock-location-detector') 44 | 45 | ``` 46 | 47 | ## Usage 48 | 49 | 1. Make sure your app has location permission, before calling this function. 50 | 51 | 2. Arguments of function checkMockLocationProvider: Dailogbox Title, Dialogbox Text, Dialogbox Button Text 52 | 53 | ```javascript 54 | import RNMockLocationDetector from "react-native-detect-mock-location"; 55 | 56 | const isLocationMocked: boolean = 57 | await RNMockLocationDetector.checkMockLocationProvider(); 58 | 59 | if (isLocationMocked) { 60 | // Location is mocked or spoofed 61 | 62 | return; 63 | } 64 | 65 | // Location is fine 66 | ``` 67 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /android/src/main/java/com/mocklocation/reactnative/RNMockLocationDetectorModule.java: -------------------------------------------------------------------------------- 1 | package com.mocklocation.reactnative; 2 | 3 | import android.widget.Toast; 4 | import com.facebook.react.bridge.NativeModule; 5 | import com.facebook.react.bridge.ReactApplicationContext; 6 | import com.facebook.react.bridge.ReactContext; 7 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 8 | import com.facebook.react.bridge.ReactMethod; 9 | import com.facebook.react.bridge.Callback; 10 | import com.facebook.react.bridge.Promise; 11 | import java.util.Map; 12 | import java.util.HashMap; 13 | import android.Manifest; 14 | import android.content.Context; 15 | import android.content.pm.ApplicationInfo; 16 | import android.content.pm.PackageInfo; 17 | import android.content.pm.PackageManager; 18 | import android.location.Location; 19 | import android.location.LocationManager; 20 | import android.os.Build; 21 | import android.provider.Settings; 22 | import androidx.annotation.RequiresApi; 23 | import androidx.core.app.ActivityCompat; 24 | import androidx.appcompat.app.AppCompatActivity; 25 | import android.os.Bundle; 26 | import android.util.Log; 27 | import android.widget.Toast; 28 | import android.content.DialogInterface; 29 | import androidx.appcompat.app.AlertDialog; 30 | 31 | import com.google.android.gms.location.FusedLocationProviderClient; 32 | import com.google.android.gms.location.LocationServices; 33 | import com.google.android.gms.tasks.OnSuccessListener; 34 | 35 | import java.util.List; 36 | 37 | public class RNMockLocationDetectorModule extends ReactContextBaseJavaModule { 38 | 39 | private final ReactApplicationContext reactContext; 40 | public static Promise promise; 41 | 42 | public RNMockLocationDetectorModule(ReactApplicationContext reactContext) { 43 | super(reactContext); 44 | this.reactContext = reactContext; 45 | } 46 | 47 | @Override 48 | public String getName() { 49 | return "RNMockLocationDetector"; 50 | } 51 | 52 | @ReactMethod 53 | public void checkMockLocationProvider(final Promise promise) { 54 | this.promise = promise; 55 | if (ActivityCompat.checkSelfPermission(getCurrentActivity(), 56 | Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && 57 | ActivityCompat.checkSelfPermission(getCurrentActivity(), 58 | Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 59 | return RNMockLocationDetectorModule.promise.resolve(false); 60 | } 61 | FusedLocationProviderClient mFusedLocationClient; 62 | mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getCurrentActivity()); 63 | reactContext.runOnUiQueueThread(()->{ 64 | mFusedLocationClient.getLastLocation().addOnSuccessListener(getCurrentActivity(), 65 | new OnSuccessListener < Location > () { 66 | @Override 67 | public void onSuccess(Location location) { 68 | if (location == null) { 69 | RNMockLocationDetectorModule.promise.resolve(false); 70 | } 71 | else if (isLocationFromMockProvider(getCurrentActivity(), location)) { 72 | RNMockLocationDetectorModule.promise.resolve(true); 73 | } else{ 74 | RNMockLocationDetectorModule.promise.resolve(false); 75 | } 76 | } 77 | }); 78 | }); 79 | } 80 | 81 | public boolean isLocationFromMockProvider(Context context, Location location) { 82 | if (android.os.Build.VERSION.SDK_INT >= 18) { 83 | return location.isFromMockProvider(); 84 | } 85 | if (Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0")) { 86 | return false; 87 | } 88 | return true; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | --------------------------------------------------------------------------------