0
echo 0 > /sys/class/leds/button-backlight/brightness

The above command is working perfectly through adb shell.But when I try to run through my code there is no effect.Here is my code.

Process mSuProcess;
mSuProcess = Runtime.getRuntime().exec("su"); 
DataOutputStream mSuDataOutputStream = new DataOutputStream(mSuProcess.getOutputStream()); 
mSuDataOutputStream.writeBytes("echo 0 > /sys/class/leds/button-backlight/brightness \n");
mSuDataOutputStream.flush();
mSuDataOutputStream.close();

Please help me out on this.

1
  • 1
    Although you say you are 'rooted' that does not necessarily mean you have an su binary usable for this purpose. See if you can manage to capture the stdout /stderr of the su process. Also consider installing something like connectbot and trying your commands in an interactive shell on the device, which will run as an application userid and thus give you a more comparable case than adb does. Commented May 22, 2013 at 15:28

2 Answers 2

2

If the device which you are working on is not rooted then this may not work..

Sign up to request clarification or add additional context in comments.

4 Comments

Run shell instead of su, like; Process mSuProcess; mSuProcess = Runtime.getRuntime().exec("sh");
try this one please mSuProcess.getOutputStream().writeBytes("echo 0 > /sys/class/leds/button-backlight/brightness \n"); and keep it through "su"
Refer this.. hopefully will help you
Your code should work.. i dont see any reason why this is happening.. best luck
1

The google original su binary checks for UID and only works if run by root or shell users. This is why it works when you run your command from adb shell interactively. In order to run this code from a java app you need to use a patched su binary - without UID checks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.