Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SU permissions: How to use them?

Tags:

java

android

root

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!

like image 591
Adiost Avatar asked Jan 05 '12 22:01

Adiost


1 Answers

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>);
like image 84
user931366 Avatar answered Sep 18 '22 21:09

user931366