don11995 don11995 - 3 months ago 55
Linux Question

How can I get root to work for system app in Android?

I need to mount nfs share from the system app to sdcard or to mnt folder, but

works only with root access granted. How can I do this? (This is not only the one program, that not work without root. For example, I also need root to use
to flash custom recovery on my system)

I downloaded AOSP Marshmallow sources, I added su and all it needs to /system/xbin folder. When I try to run
it prints me
"Permission denied"
, but via
adb shell
root works normally (I can run it in xbin folder). What permissions I need to add to run my system apps as root? Thanks.

System and system apps built and signed with the platform key. App that I am testing has
property in


The only solution that works for me is the server binary that launched by init as root process. I wrote simple server binary that can be connected via LocalSocket from java side and I can send it some commands. To start server binary on system start, I added next lines to init.rc script:

service suservice /system/bin/suservice
   class core
   user root
   group root
   socket suservice stream 0600 system system

On java side I wrote simple library that works via callback interface and receives data from this service or error if something wrong.

Now only apps that started as system:system can use this local socket to run root commands. User apps receive Permission denied as expexted.

P.S. There is no need to run or keep su binary now at all, because server binary already runs as root. I can completly remove su binary from the system now.