0

So, I need to copy a file to /system, and have to use shell commands, because the application is not running with enough privileges (and is not even installed to /system/apps at that time) - so its impossible to write to /system directly.

String cmd = String.format("\"/bin/sh -c \'cp %s %s'", tempPath, out);
p = Runtime.getRuntime().exec(new String[] { "su", "-c", cmd });

However, SuperSU pop-up informs me, that following application was granted to run as root:

/bin/sh -c _cp %s %s_.

So ' are replaced with _, and eventually command takes no effect. What is a proper way to run a command having so much quotes ("" and '' for a single argument to su)?


I know of using su's stdin to run commands separated by \n, but it seems to be having its own problems (and was not working too).

Community
  • 1
  • 1
kagali-san
  • 2,964
  • 7
  • 48
  • 87
  • By the way, even once you get `su` to work, this likely will not succeed -- most devices have `/system` mounted read-only. – Adam Bliss Jan 19 '14 at 04:56

1 Answers1

0

If you're calling through SuperSU, there are a ton of pitfalls, and the recommended way is to use libsuperuser. See http://su.chainfire.eu/ for details.

Adam Bliss
  • 645
  • 4
  • 9
  • This one is pretty bad, trying to tell ME what to do with MY phone: "should consider the su command to be equivalent to a blocking I/O call, like disk or network access. These should not be done from the main thread either - in fact, on newer Android versions, performing network I/O in the main thread will (intentionally) crash your app, and in strict mode the screen will flash red if you perform any disk I/O on the main thread to warn you of your error. ". Hey, I'll be running a floating point math calculation on main thread for hours if I'll need to! – kagali-san Jan 18 '14 at 23:48
  • 3
    I'm afraid not, unless you write your OWN operating system for YOUR device. If you block the main thread for more than five seconds or so, Android will interrupt your process. This is done so that the phone never (in theory) becomes unresponsive. Which is nice when you have to, say, call an ambulance or something. – Adam Bliss Jan 19 '14 at 04:39