2017-02-25 4 views
-1

Ich mache einen einfachen Root-Checker zu Beginn meiner Anwendung, es funktioniert gut, vorausgesetzt, Sie haben SuperSU installiert, aber es funktioniert nicht für andere Root-Manager wie KingRoot etc ...Android Root Checker, Java Probleme

Ich brauche es für jeden Root-Manager zu arbeiten!

Ich kann das Problem nicht sehen, weil es nur eine Datei als Root-Prozess schreibt und überprüft dann den Exit-Codes .. also hypothetisch sollte es für jeden Manager arbeiten, aber es funktioniert nicht ...

Bitte helfen Sie mir ... Der Code ich verwende

try 
     { 
      Process p = Runtime.getRuntime().exec("su"); 
      DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
      os.writeBytes("echo \"TEST\" > /system/temp.txt\n"); 
      os.writeBytes("exit\n"); 
      os.flush(); 
      try 
      { 
       p.waitFor(); 
       if (p.exitValue() == 1) 
       { 

       } 
       else if (p.exitValue() == 0) 
       { 
        AlertDialog.Builder alertDial = new AlertDialog.Builder(this); 
        alertDial.setCancelable(false); 
        alertDial.setTitle("PRE-ROOT CHECK"); 
        alertDial.setMessage("You don't have root access ! \nThis is a not going to work !"); 
        alertDial.setPositiveButton("                   Exit                   ", new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) 
          { 
           System.exit(0); 
          } 
         }); 
        alertDial.setIcon(R.drawable.ic_launcher); 
        alertDial.show(); 
       } 
      } 
      catch (InterruptedException e) 
      { 
       System.exit(0); 
      } 
     } 
     catch (IOException e) 
     { 
      System.exit(0); 
     } 

Antwort

0

starten:

/** 
    * Checks if the device is rooted. 
    * 
    * @return <code>true</code> if the device is rooted, <code>false</code> otherwise. 
    */ 
    public static boolean isRooted() { 

    // get from build info 
    String buildTags = android.os.Build.TAGS; 
    if (buildTags != null && buildTags.contains("test-keys")) { 
     return true; 
    } 

    // check if /system/app/Superuser.apk is present 
    try { 
     File file = new File("/system/app/Superuser.apk"); 
     if (file.exists()) { 
     return true; 
     } 
    } catch (Exception e1) { 
     // ignore 
    } 

    // try executing commands 
    return canExecuteCommand("/system/xbin/which su") 
     || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su"); 
    } 

    // executes a command on the system 
    private static boolean canExecuteCommand(String command) { 
    boolean executedSuccesfully; 
    try { 
     Runtime.getRuntime().exec(command); 
     executedSuccesfully = true; 
    } catch (Exception e) { 
     executedSuccesfully = false; 
    } 

    return executedSuccesfully; 
    }