简单的防止虚拟定位(安卓)

项目里用到过定位签到的功能,但不免有一些用户投机取巧的作弊,毕竟是我们代码不够严谨,也不怨用户,大神太多,所以我们只能简单的防范一下。

    private static boolean isInstallVirtual(Context context) {
        Map<String, String> packageNames = getVirtualPackageNames();

        PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        for (int i = 0; i < pinfo.size(); i++) {
            if (packageNames.get(pinfo.get(i).packageName) != null) {
                return true;
            }
        }
        return false;
    }

以下是一些特定的虚拟定位软件 (如有侵犯隐私请私信联系删除 谢谢)

 private static Map<String, String> getVirtualPackageNames() {
        Map<String, String> packageNames = new HashMap<>();
        packageNames.put("com.lerist.fakelocation", "com.lerist.fakelocation");// Fake-location虚拟定位
        packageNames.put("top.a1024bytes.mockloc.ca.pro", "top.a1024bytes.mockloc.ca.pro");// 天下任我行
        packageNames.put("com.qgwapp.shadowside", "com.qgwapp.shadowside");// 任我行免ROOT
        packageNames.put("net.superal", "net.superal");// 超级神行者
        packageNames.put("com.deniu.daniu", "com.deniu.daniu");// 大牛
        packageNames.put("com.deniu.multi", "com.deniu.multi");// 大牛助手
        packageNames.put("com.txy.anywhere", "com.txy.anywhere");// 天下游
        packageNames.put("de.robv.android.xposed.installer", "de.robv.android.xposed.installer");// Xposed
        packageNames.put("github.tornaco.xposedmoduletest", "github.tornaco.xposedmoduletest");// 应用管理Xposed
        return packageNames;
    }
if (isInstallVirtual(mContext)) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setMessage("签到失败,不允许使用虚拟定位软件。为防止信息被窃取,请卸载虚拟定位软件。");
                        builder.setPositiveButton("我知道了", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        });
                        builder.setCancelable(false);
                        builder.show();
                    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容