Reputation: 56
I basically want to start a process which resides in /system/bin/...
from the Application java
command.
I tried all types of Runtime.process.exec()
options
Tried the su
and ouputStream
combination as well, but nothing is able to start the application.
I am using the code in device and emulators, no luck in both.
I am able to run the same commands from ADB Shell successfully (as it has root permissions).
The device is rooted, I am able to see the # when I use adb to debug my device and it also can go into su via adb. based on my searching I found that (after doing ps from adb shell) I am able to run any command with lrwz--x--x permission such as (ls->toolbox, ps->toolbox) from the application layer but I am not able to execute any other commands which are not linked to the toolbox.
This doesn't execute ls
:
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os=new DataOutputStream(p.getOutputStream());
os.writeBytes("ls \n");
os.flush();
But this does execute ls
:
Process p = Runtime.getRuntime().exec("ls");
I would really appreciate if I can get any help on this here! I am posting this after doing lots of research.
Upvotes: 1
Views: 3992
Reputation: 104080
Rather than sending ls \n
to the su
command's standard input, try running:
su -c ls
The -c
option to su(1)
asks it to run a command with elevated privileges rather than starting an interactive shell.
Upvotes: 2
Reputation: 1261
Try creating a shell script file(eg: init.sh) and write following commands in it:
su
reboot
Now try executing this shell script by Runtime.getRuntime().exec("sh init.sh");
If this restarted your droid then you can write your required code in init.sh file & run it.
Upvotes: 0