Aarogyasetu_android: Check for mock location is not present

Created on 26 May 2020  路  3Comments  路  Source: nic-delhi/AarogyaSetu_Android

Anyone can easily change there location by using mock locations apps. Check if any other apps from the device is using in ACCESS_MOCK_LOCATION Permission.

Most helpful comment

`public static boolean isMockSettingsON(Context context) {
    // returns true if mock location enabled, false if not enabled.
    if (Settings.Secure.getString(context.getContentResolver(),
                                Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
        return false;
    else
        return true;
}


`//something like this?

All 3 comments

`public static boolean isMockSettingsON(Context context) {
    // returns true if mock location enabled, false if not enabled.
    if (Settings.Secure.getString(context.getContentResolver(),
                                Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
        return false;
    else
        return true;
}


`//something like this?

There can be two way to do so..

One check is device has any app which is using MOCK Location permission
Second Is system is mocking location?

For One:-
static boolean isMockLocationOn(Location location, Context context) {
return location.isFromMockProvider();
}

For Second :- static boolean areThereMockPermissionApps(Context context) {
int count = 0;

    PackageManager pm = context.getPackageManager();
    List<ApplicationInfo> packages =
            pm.getInstalledApplications(PackageManager.GET_META_DATA);

    for (ApplicationInfo applicationInfo : packages) {
        try {
            PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName,
                    PackageManager.GET_PERMISSIONS);

            // Get Permissions
            String[] requestedPermissions = packageInfo.requestedPermissions;

            if (requestedPermissions != null) {
                for (int i = 0; i < requestedPermissions.length; i++) {
                    if (requestedPermissions[i]
                            .equals("android.permission.ACCESS_MOCK_LOCATION")
                            && !applicationInfo.packageName.equals(context.getPackageName())) {
                        count++;
                    }
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("Got exception " , e.getMessage());
        }
    }

    if (count > 0)
        return true;
    return false;
}

Yup I can easily use a fake GPS app and keep switching my location. If you have used the UTS app in Mumbai to book a local train ticket then the app stops you from booking a ticket if you're using using mock location.
Aarogya Setu can do something like that too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tachyons picture tachyons  路  3Comments

r-ush picture r-ush  路  3Comments

PatilShreyas picture PatilShreyas  路  5Comments

Demon-stare picture Demon-stare  路  4Comments

rejuls picture rejuls  路  5Comments