Android app crashes when adding commands to RootTools v4.2 shell

438 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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());
}
}