RootTools
RootTools copied to clipboard
commandOutput is not called in every lines
I'm working with roottols 4. If I call "getevent" command and I pass the "touch_dev" device the "commandOutput" doesn't return me every lines. Especially if I make single tap. And with "gpio-keys" device it returns nothing. However with the terminal emulator app it works well.
CODE: ("device" for me is "/dev/input/event5" but if you run "getevent" in adb shell you can find your "touch_dev" device)
private Command command;
public GetTouch(String device)
{
command = new Command(0, 0, "getevent " + device)
{
@Override
public void commandOutput(int id, String line)
{
System.out.println(line);
}
@Override
public void commandTerminated(int id, String reason)
{
// TODO Auto-generated method stub
}
@Override
public void commandCompleted(int id, int exitCode)
{
// TODO Auto-generated method stub
}
};
}
public void run() throws RootDeniedException
{
try
{
RootTools.getShell(true).add(command);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (TimeoutException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Can you show us your code you are using?
Ok. I've update the post
You are missing the super calls.
Add:
super.commandOutput(id, line);
as the last line in your commandOutput method.
I can't, eclipse says:
Cannot directly invoke the abstract method commandOutput(int, String) for the type
Are you sure you are using 4.0/4.1? commandOutput is not an abstract method anymore.
Yes, in roottools .ipr file is there
<project version="4">
it should be the beta version
I don't think you have version 4. That line doesn't have anything to do with the actual version number.
Additionally, commandOutput is not abstract in version 4.0 or 4.1.
I've downloaded the latest version and commandOutput is not abstract. However I still have the same problem also calling super.commandOutput(id, line); at the least line in my commandOutput method.
Ok, let me try and test this myself.
Hmmm, I can't seem to find a "touch_dev" on my device when I do getevent.
"touch_dev" there isn't in all devices (it might have an other name) but you can most likely find the event that say when an hardware button is pressed and use it to test. Its name can depend by device and you should try each event. I've the same problem also with that event.
I think part of the problem is that you are setting the timeout to 0.
I didn't really account for keeping a command running indefinitely....
Let me add this in and I'll give you a new version to test.
Can you try using this version?
Keep in mind you'll need to call cmd.terminate() when you want it to finish.
Once you confirm this is working I'll add in some better support for this use case.
https://drive.google.com/open?id=0B5Amguus3csDZzNMems4Zm5kNU0&authuser=0
I tried also with different values it's the same.
Can you give me the source code of the project because if I use the jar I get “Conversion to Dalvik format failed with error 1” when I try to run.
You may need to clean your project and rebuild it when adding the jar.
I'll check in the changes to the repos, there are changes to both RootShell and RootTools so you'll have to compile both and combine both into a jar or include both in your project.
Also, I added better support for this use case.
When you are done with a command you can either call:
cmd.finish();
OR
cmd.terminate();
One indicates that the command finished as desired and the other indicates that some problem occurred.
All code checked in.
@Stericson Does .finish() / .terminate() really kill/stop the process executing? Because it doesn't seem to do that for me (e.g. executing "logcat *:V" with a timeout of 10 sec, callback commandOutput still gets called after timeout with new data). Btw (not sure if it's relevant) - I'm using my own "su" binary, which just runs a root shell (/system/bin/sh).
I use RootTools 4.2, and have the same problem with @andrea993 . It seems that commandOutput
can't return until certain number of lines.
So, I run getevent /dev/input/event5 > /storage/sdcard0/input.txt
instead, no problem with output, but, I can't stop outputing with finish()
or terminate()
, just as @kostaspl 's problem. isFinished()
returns true
, and isExecuting()
returns false
, but input.txt continues increasing.
So, I'd like to know how did you solve these problem, thank you! @andrea993 @kostaspl @Stericson
@zhuoensea It's been a long time since then, but I think I just used this way: http://stackoverflow.com/a/10225072