Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify AOSP to allow specific apps to get root access?

I'm working on AOSP. I've successfully added my apk to build. Now I want to give root access to my app. I don't want to provide root access to other apps or to install the Superuser app in my build. I just want to add my app to get root access. How can I achieve that?

I went through the su.c file in path system/extras/su but I'm unable to understand the whole code.

When I went through the code, I think my objective can be achieved if I could modify su.c to provide root access to my app,compile it and add the binary to the build. Am I right?

like image 421
Neji Avatar asked Dec 10 '12 14:12

Neji


People also ask

How do I grant an app to root access?

In most versions of Android, that goes like this: Head to Settings, tap Security, scroll down to Unknown Sources and toggle the switch to the on position. Now you can install KingoRoot. Then run the app, tap One Click Root, and cross your fingers. If all goes well, your device should be rooted within about 60 seconds.


2 Answers

You're moving in the right direction. You need to check the sources for su.c The only problem that you can face is how to run your program as root. To do this you need to set SUID sticky bit for the executable of your application. To do this you need to modify system/core/include/private/android_filesystem_config.h file (structure android_files[]), for instance for su program you can see how this bit is set:

{ 06755, AID_ROOT,      AID_ROOT,      "system/xbin/su" },
like image 78
Yury Avatar answered Sep 22 '22 18:09

Yury


ChainFire has written a a guide on su and how to use it for normal apps. If you're intending on working with anything other than your own phone I suggest this is the approach you follow.

like image 43
stsquad Avatar answered Sep 23 '22 18:09

stsquad