How to prevent the use of Android phones with installed applications?

The goal in this context is to prevent false records from appearing in LeaderBoard (my application is a game). This happened for Flappy Birds - see this link - http://www.androidpit.com/forum/589832/flappy-bird-high-score-cheat-set-your-own-high-score

Since the root user can do whatever he wants with his mobile device, I believe that no other workarounds will work, and the only solution is to prevent users from installing the application. I'm right? Is there any way to do this?

PS: My game doesn’t always need an Internet connection, so the results reports received when it happens on another server are not viable. The best results are reported to the leaderboard only if you have an Internet connection.

+10
source share
4 answers

I had a similar requirement. I could not achieve that the application should not be installed on the root device, but I used the work for this:

  • Make sure your device is embedded in your business onResume.
  • If it is rooted, just show him the warning "This device is embedded, you cannot use this application" and exit the application.

Example:

@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();
}

DeviceUtis.java Utility, , .

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");
    }
}

5 , 2 . , .

, .

P.S: onResume, ( ) , , .

+16

. , , - , ?

(!) ? ?

, , .

Edit:

, . . . , .

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

        return executedSuccesfully;
    }
+2

PlayStore SafetyNet, , PlayStore .

API Safety Net Google Play, , /.

, , : fooobar.com/questions/8702892/...

0

Source: https://habr.com/ru/post/1568087/


All Articles