Thursday, March 5, 2015

How to check whether device is rooted in Android

Normally we detect whether device is rooted by checking for su binary. Problem is su binary can be in many location based on rooting techniques.

  protected static boolean checkForRoot()
  {
    String[] arrayOfString = new String[8];
    arrayOfString[0] = "/sbin/";
    arrayOfString[1] = "/system/bin/";
    arrayOfString[2] = "/system/xbin/";
    arrayOfString[3] = "/data/local/xbin/";
    arrayOfString[4] = "/data/local/bin/";
    arrayOfString[5] = "/system/sd/xbin/";
    arrayOfString[6] = "/system/bin/failsafe/";
    arrayOfString[7] = "/data/local/";
 
    int j = arrayOfString.length;
    int i = 0;
 
    while (i < j)
    {
      String str = arrayOfString[i];
      if (new File(str + "su").exists()) {
        return true;
      }
      i += 1;
    }
    return false;
  }

No comments:

Post a Comment