I have a partition in Android that’s not mounted because it doesn’t have a file system, and I need to write a string into it. I tried three different methods, and only the first (from adb) works. I need to do this under program control, which is what the second and third methods do, but both fail. I tried adding system permissions to my app, but that didn’t help. Do I need root permission to do this from a program?
First Method –
adb shell "echo test > /cache/command"
adb shell dd if=/cache/command of=/dev/block/mmcblk3p3 bs=4096 seek=1
Second Method –
java.lang.Process p = Runtime.getRuntime().exec(
"dd if=/cache/command of=/dev/block/mmcblk3p3 bs=4096 seek=1");
Third Method –
File fileName = new File("/dev/block/mmcblk3p3");
String cmd = "test";
FileOutputStream fos = new FileOutputStream(fileName);
fos.write(cmd.getBytes(), 4096, cmd.length());
fos.flush();
The second method gives no feedback, even though it failed to work. The third method gives the following output:
W/System.err( 1014): java.io.FileNotFoundException:
/dev/block/mmcblk3p3 (Permission denied)
I should warn you about the risks you may have enabling liberal permissions on partitions that should not be accessed by applications. Having said that and assuming you know the risks, what you can do is to change the permissions, if you want to do it permanently you can add
to
init.rc.There are sections containing other chmod commands where you can put yours.