如何防止Root Android手机安装我的应用程序?

Dro*_*ven 10 mobile android anti-cheat

在这种情况下,目的是防止在LeaderBoard中报告错误的高分(我的应用程序是游戏).Flappy Birds发生了这种情况 - 请看这个链接 - http://www.androidpit.com/forum/589832/flappy-bird-high-score-cheat-set-your-own-high-score

由于root用户可以使用他的移动设备做任何他想做的事情,我想其他任何工作都不会起作用,唯一的解决方案是阻止root用户安装应用程序.我对吗?有办法吗?

PS:我的游戏总是不需要互联网连接,因此当它发生在另一台服务器上时报告分数是不可行的.只有在互联网连接可用时,才会向排行榜报告高分.

Mys*_*icϡ 17

我有类似的要求.我无法实现该应用程序不应该安装在root设备上,但我使用了一个解决方法:

  • 检查您的设备是否植根于您的活动中onResume.
  • 如果它有根,只要告诉他"此设备已植根.您无法使用此应用程序.",并退出应用程序.

例:

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    if(new DeviceUtils().isDeviceRooted(getApplicationContext())){
        showAlertDialogAndExitApp("This device is rooted. You can't use this app.");
    }
}


public void showAlertDialogAndExitApp(String message) {

    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle("Alert");
    alertDialog.setMessage(message);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    finish();
                }
            });

    alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)

DeviceUtis.java 是一个Utility类,如果设备是否为root,则返回.

public class DeviceUtils {

    public Boolean isDeviceRooted(Context context){
        boolean isRooted = isrooted1() || isrooted2();
        return isRooted;
    }

    private boolean isrooted1() {

        File file = new File("/system/app/Superuser.apk");
        if (file.exists()) {
            return true;
        }
        return false;
    }

    // try executing commands
    private boolean isrooted2() {
        return canExecuteCommand("/system/xbin/which su")
                || canExecuteCommand("/system/bin/which su")
                || canExecuteCommand("which su");
    }
}
Run Code Online (Sandbox Code Playgroud)

我们使用了5种方法进行测试,我刚刚在这里展示了2种.您可以使用任何您认为合适的方法.

希望这可以帮助.

PS:我把这个调用放在所有活动中,onResume因为用户(有黑客意图)可以安装应用程序,导航到其他一些活动,然后根设备.


小智 5

private static boolean canExecuteCommand(String command) {
        boolean executedSuccesfully;
        try {
            Runtime.getRuntime().exec(command);
            executedSuccesfully = true;
        } catch (Exception e) {
            executedSuccesfully = false;
        }

        return executedSuccesfully;
    }
Run Code Online (Sandbox Code Playgroud)