Detecting Root on Andorid


In this tutorial, we will learn how to determine whether an Android device has root access.

 

WHAT IS ROOT/ROOTED?

Rooting is the process of allowing users of smartphones, tablets and other devices running the Android mobile operating system to attain privileged control (known as root access) over various Android subsystems. As Android uses the Linux kernel, rooting an Android device gives similar access to administrative (superuser) permissions as on Linux or any otherUnix-like operating system such as FreeBSD or OS X.

 

Rooting is often performed with the goal of overcoming limitations that carriers and hardware manufacturers put on some devices. Thus, rooting gives the ability (or permission) to alter or replace system applications and settings, run specialized applications (“apps”) that require administrator-level permissions, or perform other operations that are otherwise inaccessible to a normal Android user. On Android, rooting can also facilitate the complete removal and replacement of the device’s operating system, usually with a more recent release of its current operating system. Read more.

 

This tutorial is not about how to Root your device, its about Detecting Root Access from inside an application.

 

Overview:

Three methods were used to detect root:

  1. Check if the system OS was built with test-keys
  2. Check if the file “/system/app/Superuser.apk” exists
  3. Check if the “su” command was successful

If any of these three methods were true, then the device has Root Access.

 

Check if the system OS was built with test-keys:

By default, stock Android ROMs from Google are built with release-keys tags. If test-keys are present, this can mean that the Android build on the device is either a developer build or an unofficial Google build. My Nexus 5 is running stock Android from Google’s (Android Open Source Project) AOSP. This is why my build tags show release-keys.

 

Check if the file “/system/app/Superuser.apk” exists:

This package is most often looked for on rooted devices. Superuser allows the user to authorize applications to run as root on the device.

 

Check if the “su” command was successful:

Execute su and then id to check if the current user has a uid of 0 or if it contains (root).

 

Complete Source:

 

ScreenShot:

root_success root_failure

 

Complete Source code available here.

Source:    http://stackoverflow.com

About Durga Chiranjeevi

I’m a normal guy, engineer by education who is passionate about Programming and Internet. An android enthusiast, now moving for cross platforms and game development.