Magazine High tech

Gain root access for your Android app

Publié le 18 mars 2011 par Romainbochet

If you are an Android developer, you may want to create applications which need to be root to work properly. Most of the time, everything you want to make can be achieved using the good permission, but some "advanced" things cannot be done in user space, for instance use the ad-hoc WiFi mode. In this case, you have no choice but ask for running your application with the root privileges on the clients handsets.

So, you want your app to be root on the handset. But do you really need it? It's perhaps not the world's best idea. Here's why you should not do it and how to do the trick...

Ask root

The software who "rooted" the device allows other apps to get root privileges.

Why you should think twice about asking for running as root:

  • It will exclude lots of users -- the "normal" ones, those who don't want to hack their phones;
  • It will -legitimately- scare the user : "Why this application need to be root? How can I be sure that it won't destroy my operating system?"
  • Your application will be a threat for the whole handset; if you made a mistake, or if the phone is different and reacts in another way, you can break the user's system. Furthermore, the user will probably think than your app is responsible if such a problem occurs;
  • For the moment, Android Market accepts applications that ask for running as root  -- and reject the "rooting" ones--, but this can change. And detecting such a behavior is very easy, it doesn't even require to run the app.

If you still want to make your application ask for running as root, here is the one-line snippet:

Sounds logical, right?

As far I know, it's the only option you have to gain root credentials. When I was looking for a solution, I went through the official documentation, and I found a page which mentions a root permission:

public static final String FACTORY_TEST

Since: API Level 1

Run as a manufacturer test application, running as the root user. Only available when the device is running in manufacturer test mode.

Constant Value: "android.permission.FACTORY_TEST"

Unfortunately, such a permission is only for manufacturer and cannot be granted to a standard SDK application.
In fact, to be able to use this permission, the device should be in factory test mode, and this mode cannot be activated without modifying the Android software, as you can see in the source code (thanks CommonsWare from StackOverflow for the pointer).


Retour à La Une de Logo Paperblog

A propos de l’auteur


Romainbochet 5 partages Voir son profil
Voir son blog

l'auteur n'a pas encore renseigné son compte l'auteur n'a pas encore renseigné son compte

Dossiers Paperblog

Magazine