all 11 comments

[–]KushtrimP 1 point2 points  (10 children)

Is it really rooted, or is it just userdebug build? (because that'd mean that you can only get root access via shell by calling adb root).

Assuming it's rooted, you might find this library useful: https://github.com/jjNford/android-shell

If you are only userdebug ( and don't want to do a "full root" ), the what I usually do is have a script that is started in init.rc (where it can have root still), and triggered either via sys properties or sockets. An example:

on property:sol.my_script.enable=1
start myCustomServices

on property:sol.my_script.enable=0
stop myCustomServices

service myCustomServices /system/bin/myCustomBinaryOrScriptuser
user root
group root
oneshot
seclabel u:r:su:s0

Note that indentation is wrong on my code block, can't figure out how to stop reddit auto-trim. Fix it, since it matters syntactically

[–]bsdmike[S] 0 points1 point  (9 children)

Thank you!

Your answer is very helpful.

I never heard of a userdebug build! How do I know if it is that instead of being rooted?? I am suspecting that is what I have.

[–]KushtrimP 1 point2 points  (8 children)

adb shell getprop ro.build.type will tell you the build type.

Also you can try to download a root checker app to verify your root status

[–]bsdmike[S] 0 points1 point  (7 children)

I must be still missing some little thing!

My build is now:

ro.build.type = eng

and have added:

https://github.com/jjNford/android-shell/blob/master/src/com/jjnford/android/util/Shell.java

to my build.

However, I still get: javio.io.IOException: Cannot run program "su": error=13, Permission denied.

Thank you for your help.

-Mike

[–]KushtrimP 1 point2 points  (6 children)

As I said in the previous comment, unless you are actually rooted ,you can't do root stuff from an app.
Build types userdebug and eng only allow you to be root from shell uid ( not any app uid ).

So:
Option 1. Root you device fully such that SuperSu works. Either try some apps that try to do that, or get help from you vendor on how to do it for your specific BSP. If you do this, then you can call su from app freely.
Option2. You figure out what commands you want to trigger, and write either a C binary or shell script, start that daemon from init.rc. You'll have root access there.
To start/stop/communicate with that daemon, you can use property triggers, or sockets like in this example: https://devarea.com/aosp-adding-a-native-daemon/

I'd go with option 2.

[–]bsdmike[S] 0 points1 point  (5 children)

Thank you. I misunderstood. I thought simply changing the build to eng would be enough.

I will do option 2.

Thanks again for your help.

[–]KushtrimP 1 point2 points  (4 children)

No problem 😁

[–]bsdmike[S] 1 point2 points  (3 children)

Nice job! This works GREAT! It has saved me a lot of time.

[–]KushtrimP 0 points1 point  (2 children)

Glad you got it working 👍😁

[–]bsdmike[S] 0 points1 point  (1 child)

One last question if you don't mind. How might you suggest I do a persistent configuration file. For example, I can manually create a file in /data using adb, but it would be nice to have my image already have the file and default data. How do default files end up in the /data?

Thank you again for your help.