Android SU permissions: How to use them?

2019-03-16 15:37发布

There is a situation here, I'm developing an Android application, using Java. I'm pretty familiar with all this stuff, but now it's the first time when I need to use SU permissions. I just need to replace (actually, rename) the file in system/app directory, but it looks like I'm not able to perform it in a usual way (renameTo method in File class), it just returns me FALSE, which means that there was some error in operation.

So can anybody tell me how to use SU? My test phone is fully rooted with SU 3.0.3.2, any app that require SU works perfectly fine.

Shall I use the same method but with some additions in manifest? Shall I use busybox in some way?

I already googled for this, and I can't find any useful information. And also, there is no documentation on official Android Superuser website.

Thanks in advance!

1条回答
霸刀☆藐视天下
2楼-- · 2019-03-16 16:23

You'll probably also need to remount the filesystem as RW since /system is read-only. So you might need to call SU with a similar command below:

mount -o r,remount -t yaffs2 /dev/block/mtdblock3 /system

To execute the command, you can try two ways (I've notice in android sometimes one works and the other won't )

Process p = Runtime.getRuntime().exec(new String[]{"su", "-c", "mount -o r,remount -t yaffs2 /dev/block/mtdblock3 /system"});

Or you can do

Process p =  Runtime.getRuntime().exec("su");
p.getOutputStream().write("mount -o r,remount -t yaffs2 /dev/block/mtdblock3 /system".getBytes());
p.getOutputStream().write(<my next command>);
查看更多
登录 后发表回答