17829

Android device rooted check

Question:

I want to check my device is rooted or not. When I try this code below in real device is not rooted, its ok. But Non rooted emulator break in this line

if (new File(path).exists()) return true;

"/system/xbin/su" path is exists.

private static boolean isRooted() { String[] paths = { "/system/app/Superuser.apk", "/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", "/su/bin/su"}; for (String path : paths) { if (new File(path).exists()) return true; } return false; }

Genymotion or Android studio's emulator always break in code block.

Is all android emulators rooted?

Answer1:

You can check the device is rooted or not by below method:

public static boolean isRootedDevice(Context context) { boolean rootedDevice = false; String buildTags = android.os.Build.TAGS; if (buildTags != null && buildTags.contains("test-keys")) { Log.e("Root Detected", "1"); rootedDevice = true; } // check if /system/app/Superuser.apk is present try { File file = new File("/system/app/Superuser.apk"); if (file.exists()) { Log.e("Root Detected", "2"); rootedDevice = true; } } catch (Throwable e1) { //Ignore } //check if SU command is executable or not try { Runtime.getRuntime().exec("su"); Log.e("Root Detected", "3"); rootedDevice = true; } catch (IOException localIOException) { //Ignore } //check weather busy box application is installed String packageName = "stericson.busybox"; //Package for busy box app PackageManager pm = context.getPackageManager(); try { Log.e("Root Detected", "4"); pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); rootedDevice = true; } catch (PackageManager.NameNotFoundException e) { //App not installed } return rootedDevice; }

It will return true if the device is rooted else false.

Recommend

  • Cannot read property 'push' of undefined in react
  • Is Apache Commons Codec Base64 a drop-in replacement for sun.misc.BASE64?
  • removeFromSuperview UIImageView not working
  • Scala: Re-use generic resulting from path-dependent type in path-dependent context
  • Is it possible in Java to initialise a final data member based on constructor call?
  • Java: Open default mail application and create new mail and populate To and Subject fields
  • RequireJS - Isolating jQuery versions and plugins within contexts
  • Validation is not working in codeigniter
  • AJAX POST and PHP
  • How to change servlet request body in java filter?
  • Swift: How to continuously send an action from a NSTextField
  • Get URL from Opera browser
  • How to reload “index.html” in angularJS without manual intervention?
  • how to save settings of eclipse?
  • How can I make masonry and Imagesloaded work correct. (wordpress)
  • How to detect a process cpu/memory usage and kill it when it exceeds a certain value? [closed]
  • Dropbox API: how can I get the amount of remaining free space?
  • Control access to WebDav/Apache using Python
  • UITextField get focus and then lose focus immediately due to return YES in textFieldShouldReturn
  • How to pass a parameter to an included page with JSF 1.2
  • Javascript getting the value of an input in a table [duplicate]
  • Authorization Policies/Gates for Laravel 5.3 web app consuming own API w/ Passport
  • Customize jQuery submenu positioning
  • How to add multiple legend titles (columns) in ggplot
  • Detect when MathJax has finished loading in UIWebView
  • Anaconda + Apache + mod_wsgi + Ubuntu
  • Sorting Custom Listview Items Using Spinner Android
  • Javascript inside HTML import not affecting imported HTML
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • Multiplying polynomials/simplifying like terms
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • php “page caching” solution suggestions for CMS Applications
  • Excel VBA : conditional formatting of sheet1 cells from sheet2 values in excel 2007
  • Jersey serializes character value to ASCII equivalent numeric string
  • How to use FirstOrDefault inside Include
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • XSLT Transformation to validate rules in XML document