4

I am building an "embedded" system, based on Android, and at the moment I'm trying to implement updating the firmware of an audio module.
There is a binary which does that, but the catch is that it needs root access to do it ( it can't access GPIOs otherwise ).
So the problem now has shifted to giving the executable ( and just that executable, mustn't do full root) root access.
I've been at this for a few days, and have tried a bunch of things, with no success.
Things I've already tried :

I have run out of ideas or things to try. What else can I do ?

EDIT
I was not able to make the binary run as root, but was able to run a shell script after boot from init.rc , where there is root access, and export/change the permissions of the specific gpio I needed. This made it possible to access it without root access needed later on.

Rick Sanchez
  • 4,528
  • 2
  • 27
  • 53
  • 1
    I am not an linux expert but have you tried to simply change the owner of your executable(chown) to root via an init.rc file ? – IIIIIIIIIIIIIIIIIIIIII Jun 09 '17 at 10:46
  • Check the first bullet point. Adding the entry to android_filesystem_config.h made the root be the owner. ls -l for it returns : "-rwsr-sr-x root root" – Rick Sanchez Jun 09 '17 at 10:48

2 Answers2

2

Alex Cohn's answer https://stackoverflow.com/a/44456378/215266 is correct but here's more details.

The init process runs as root and can spawn other root processes. You can use a oneshot service that is disabled by default and kicked off by setting a system property to some value such as 1.

For example in https://android.googlesource.com/device/google/marlin/+/refs/heads/android10-mainline-a-release/init.common.rc :

service vendor.power_sh /vendor/bin/init.power.sh
    class main
    user root
    group root system
    disabled
    oneshot

on property:sys.boot_completed=1
    start vendor.power_sh

Programs started by init are not Android services they are traditional command line applications. The above example is a shell script but you can use C/C++ or Java if you like. The am command for example is primarily written Java, if you do adb shell cat /system/bin/am you will see:

#!/system/bin/sh

if [ "$1" != "instrument" ] ; then
    cmd activity "$@"
else
    base=/system
    export CLASSPATH=$base/framework/am.jar
    exec app_process $base/bin com.android.commands.am.Am "$@"
fi

The source for the Am code is here and you can see it has a traditional main method: https://android.googlesource.com/platform/frameworks/base/+/742a67127366c376fdf188ff99ba30b27d3bf90c/cmds/am/src/com/android/commands/am/Am.java

satur9nine
  • 13,927
  • 5
  • 80
  • 123
1

You can start your app, or service, or executable from init.rc.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I can't find anything on the document on how to start an app. Also the executable has to be used later after OS boot, so no point of running it now. That leaves the service ? Is this a regular Java System service ? Because based on the link on my question I know how to make a system service on java side, but not in native side ? Thank you ): – Rick Sanchez Jun 09 '17 at 14:16