4

I have an Android application utilizing RootTools v4.2 (the latest I know of) and I have followed their documentation on how to execute shell commands as root. Sometimes the commands execute just fine, other times the app crashes with the following exception.

java.lang.IllegalStateException: Unable to add commands to a closed shell

Here is the actual code the exception is being throw on:

RootTools.getShell(true).add(cmd);

So I'm wondering since the docs make no mention of this sort of problem if there is something else I'm doing wrong? Looking through the docs I see nothing on how to ensure I get an open shell before I start adding commands.

Ryan
  • 6,756
  • 13
  • 49
  • 68
  • Are you closing the shell somewhere? Check the logcat for `"Request to close shell!"`. https://github.com/Stericson/RootTools/blob/master/RootShell%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstericson%2Frootshell%2Fexecution%2FShell.java#L251 – Jared Rummler Mar 07 '16 at 23:29
  • Thanks Jared. I'm not making any explicit calls to close the shell. It would seem that the shell closes itself at some point. – Ryan Mar 08 '16 at 11:56

1 Answers1

0

This code is working with me . Try to install the Library again may be its not vaild .

if(RootTools.isAccessGiven()){
try {
    Shell shell = RootTools.getShell(true);
    JavaCommand cmd = new JavaCommand(0,this,"input keyevent 26");
    shell.add(cmd);
}
catch (Exception e){
    Log.d("ERRORS : ",e.getMessage());
}
}