12

Is there any way that I intentionally grant root permission to some app? Not automatically via SuperSU when a specific app asks for root permission, but in a way to pick an app via some tool and grant it root permissions.

For example, I add my favourite text app to the approved list and then I can open root files via that app.

2 Answers 2

14

No. You should request the app developer to do so.

On UNIX like systems, permissions are managed with something called UIDs.

Every process has one and it dictates what they can access. Moreover, there are also groups that have permission that their members can use. When an app has permissions like Write to SD card they're put into a group that has this permission.

The root permissions are an exception since they are not declared in the app's manifest, but rather in its code. Root is also not a group but a separate UID (as it is a separate user) so it's not that easy for an app to use it. Apps that have root rights need to be explicitly written to do so.

The way this works is every time an app wants to do something as root, it has to request the su binary to do it instead. su will then ask the app that manages these permissions (e.g., SuperSU) whether the app is allowed to gain root access. If it isn't, it'll prompt you to allow or deny it. Then the action is carried out as root, not as the app user. These actions are not an integral part of the app but rather an external executable.

While theoretically it is possible to add this to an app, this would be a non-trivial process requiring knowledge of writing smali code, which is the internal format of the Dalvik virtual machine (the part of the system that runs the apk file) called smali. And even then, there'd be a huge security risk if the app allows other apps to access it: it wouldn't know how to keep the privileged root access separate from its normal access. So in reality this isn't really feasible.

9
  • 2
    For those who don't know what smali is: It's the assembly dialect for Android's dalvik virtual machine code and used often in reverse engineering dex files. What might be a little unclear: The app has to itself take care of becoming root programmatically. That's why the developer has to include it. Adding it to SuperSU doesn't help as long as the app does not exercise its root rights.
    – ce4
    Jul 18, 2012 at 7:48
  • So I cannot open some root text file via my favourite text editor if the programmers did not code the app to accept opening of root files?
    – AnDroDroo
    Jul 18, 2012 at 8:12
  • 2
    Absolutely correct. To give an example: if the app will not be started with root, and tries to open some "root file", it would simply get a "permission denied" -- as accessing the file will still be done with the apps UID (it will not ask for superuser permissions to open it). On the other hand, if the app is started using the root UID (i.e. su <app>), it will access that root file as root, and thus get permission.
    – Izzy
    Jul 18, 2012 at 9:18
  • 2
    @Izzy AFAIK you can not execute an regular Android app with root UID, or change the UID of an running app. The only thing you can do is execute command line programs with su and therefore execute commands with admin permissions.
    – Robert
    Jul 18, 2012 at 13:10
  • 1
    @Robert my description was intentionally using simple words to make it understood easily. Sure it's not 100% precise, but rawly explains the "why can't I..." of the questioner. To explain the entire principle would not fit in a simple comment :)
    – Izzy
    Jul 18, 2012 at 13:14
2

I have found a way that may help you. I used this to grant root access to Tasker.

If you use the terminal emulator to grant read but not write access to a folder using

  • su
  • chmod 775 /location/of/folder/

then your text editor will be able to read that directory and so if you can then try to save a file in the folder then it will try to request root permission.

It may also just give a write error.

1
  • All directories in /location/of/folder/ from root to top must be readable/traversable. Also SELinux may deny access. So this approach is rarely practical. Mar 6, 2020 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .