Friday, 1 May 2015

check android Device is Rooted or not ?

       
/**
* Integrated One Method Calling for Result
**/

public static boolean isDeviceRooted()
       {
             return      Methodtestkeys()
                          || MethodcheckSuperuserfileexist()
                          || MethodChekingByExicutingcommandOnKernel()
                          || MethodcheckingPathForSU();
       }


/**
* testing using test-keys method
**/
public static boolean Methodtestkeys()
      {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
       }


/**
* Testing by using superuser.apk file exist
*/
public static boolean MethodcheckSuperuserfileexist()
    {
        return new File("/system/app/Superuser.apk").exists();
    }


/**
* Testing by searching Su in System Directory
**/
public static boolean MethodcheckingPathForSU()
{
       String[] paths = { "/sbin/su",
                  "/system/bin/su",
                  "/system/xbin/su",
                  "/data/local/xbin/su",
                  "/data/local/bin/su",
                  "/system/sd/xbin/su",
                          "/system/bin/failsafe/su",
                          "/data/local/su"
                         };
     
       for (String path : paths)
       {
           if (new File(path).exists())
              return true;
       }
       return false;
}


/**
 * Testing By executing Command oN Kernel
 */
public static boolean MethodChekingByExicutingcommandOnKernel()
{
       Process process = null;
       try
       {
           process = Runtime.getRuntime().exec(new String[]
                                                 { "/system/xbin/which", "su" });
           BufferedReader in = new BufferedReader(
                                                 new InputStreamReader(process.getInputStream()));
         
           if (in.readLine() != null)
            return true;
         
           return false;
       }
       catch (Throwable t)
       {
           return false;
       }
       finally
       {
           if (process != null)
            process.destroy();
       }
   }

No comments:

Post a Comment