Android SU Permissions: How to use them?

There is a situation here, I am developing an Android application using Java. I am very familiar with all this, but now this is the first time I need to use SU permissions. I just need to replace (in fact, rename) the file in the system / app directory, but it seems that I cannot execute it in the usual way (the renameTo method in the File class), it just returns FALSE to me, which means there was some error in the work.

So can someone tell me how to use SU? My test phone is completely rooted with SU 3.0.3.2, any application requiring SU works fine.

Is it possible to use the same method, but with some additions in the manifest? Should I use busybox in some way?

I have already searched for this information, and I cannot find any useful information. In addition, there is no documentation on the official Android Superuser website.

Thanks in advance!

+6
source share
1 answer

You probably also need to remount the file system as RW, since / the system is read-only. Therefore, you may need to call SU with a similar command below:

mount -or,remount -t yaffs2 /dev/block/mtdblock3 /system

To execute the command, you can try two ways (I noticed that it sometimes works in Android, but the other will not)

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

Or you can do

 Process p = Runtime.getRuntime().exec("su"); p.getOutputStream().write("mount -or,remount -t yaffs2 /dev/block/mtdblock3 /system".getBytes()); p.getOutputStream().write(<my next command>); 
+8
source

Source: https://habr.com/ru/post/905256/


All Articles