Created
May 20, 2019 14:11
-
-
Save kjromero/d4891678b1780cb417c36f70c6f56933 to your computer and use it in GitHub Desktop.
Funtions Fake GPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Verifica si el celular está usando algún tipo de aplicación para enviar ubicaciones falsas, como Fake GPS | |
| * | |
| * @param context El contexto de la aplicación | |
| * @param location La última ubicación recibida por el GPS | |
| * @return true si se está usando alguna aplicación para enviar ubicaciones falsas, false en caso contrario | |
| */ | |
| public static boolean isFakeLocation(Context context, Location location) { | |
| if (Build.VERSION.SDK_INT >= 18) { | |
| return location.isFromMockProvider(); | |
| } else if (Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0")) { | |
| return false; | |
| } else { | |
| PackageManager packageManager = context.getPackageManager(); | |
| List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); | |
| for (ApplicationInfo applicationInfo : packages) { | |
| try { | |
| PackageInfo packageInfo = packageManager.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS); | |
| String[] requestedPermission = packageInfo.requestedPermissions; | |
| if (requestedPermission != null) { | |
| for (String permission : requestedPermission) { | |
| if (permission.equals("android.permission.ACCESS_MOCK_LOCATION") && !applicationInfo.packageName.equals(context.getPackageName())) { | |
| return true; | |
| } | |
| } | |
| } | |
| } catch (PackageManager.NameNotFoundException e) { | |
| Crashlytics.logException(e); | |
| } | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment