RootTools icon indicating copy to clipboard operation
RootTools copied to clipboard

commandOutput is not called in every lines

Open andrea993 opened this issue 10 years ago • 20 comments

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

andrea993 avatar Jan 06 '15 00:01 andrea993

Can you show us your code you are using?

Stericson avatar Jan 06 '15 00:01 Stericson

Ok. I've update the post

andrea993 avatar Jan 06 '15 01:01 andrea993

You are missing the super calls.

Add:

super.commandOutput(id, line);

as the last line in your commandOutput method.

Stericson avatar Jan 07 '15 21:01 Stericson

I can't, eclipse says:

Cannot directly invoke the abstract method commandOutput(int, String) for the type 

andrea993 avatar Jan 09 '15 17:01 andrea993

Are you sure you are using 4.0/4.1? commandOutput is not an abstract method anymore.

Stericson avatar Jan 09 '15 17:01 Stericson

Yes, in roottools .ipr file is there

<project version="4">

it should be the beta version

andrea993 avatar Jan 09 '15 17:01 andrea993

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.

Stericson avatar Jan 09 '15 17:01 Stericson

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.

andrea993 avatar Jan 10 '15 18:01 andrea993

Ok, let me try and test this myself.

Stericson avatar Jan 12 '15 15:01 Stericson

Hmmm, I can't seem to find a "touch_dev" on my device when I do getevent.

Stericson avatar Jan 12 '15 15:01 Stericson

"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.

andrea993 avatar Jan 12 '15 16:01 andrea993

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.

Stericson avatar Jan 12 '15 17:01 Stericson

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

Stericson avatar Jan 12 '15 17:01 Stericson

I tried also with different values it's the same.

andrea993 avatar Jan 12 '15 17:01 andrea993

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.

andrea993 avatar Jan 12 '15 17:01 andrea993

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.

Stericson avatar Jan 12 '15 17:01 Stericson

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 avatar Jan 12 '15 17:01 Stericson

@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).

kostaspl avatar Apr 08 '15 11:04 kostaspl

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 avatar Jul 20 '16 15:07 zhuoensea

@zhuoensea It's been a long time since then, but I think I just used this way: http://stackoverflow.com/a/10225072

kostaspl avatar Jul 20 '16 19:07 kostaspl