Ronnie414 / roottools

Automatically exported from code.google.com/p/roottools
1 stars 0 forks source link

waitForFinish() does not wait for finish. #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to get a listing with waitForFinish:
    public static String getFirefoxCache() throws InterruptedException, IOException, TimeoutException, RootDeniedException {
        final StringBuffer out = new StringBuffer();
        String val = "";
        Command command = new Command(0,"ls /data/data/org.mozilla.firefox/files/mozilla/") {
            @Override
            public void output(int arg0, String dir) {
                //synchronized (out) {
                    if (dir.endsWith(".default")) {//TODO what if it's not on default profile?
                        out.append(dir);
                    }
                //}
            }
        };
        RootTools.getShell(true).add(command).waitForFinish();
        //synchronized(out) {
            val = out.toString();
        //}

        return val;
    }

What is the expected output? What do you see instead?
Instead of waiting for finish, waitForFinish() apparently does nothing but run 
the command.

What version of the product are you using? On what operating system?
2.6 on Android 2.2.2.

Please provide any additional information below.
Here's a more detailed description of the problem: 
http://stackoverflow.com/questions/16229891/concurrent-modification-exception-de
spite-waiting-for-finish

Original issue reported on code.google.com by luke...@msn.com on 19 Jun 2013 at 6:24

GoogleCodeExporter commented 8 years ago
How are you coming to the conclusion that waitForFinish is not waiting?

Can you turn debug mode on for RootTools and capture a log?

Original comment by Stericso...@gmail.com on 19 Jun 2013 at 1:08

GoogleCodeExporter commented 8 years ago
I know it's not waiting because it returns blank string, if it waited it would 
return the user profile directory of Firefox on the device. Setting breakpoints 
in output function, and after waitForFinish, confirms that not all output() are 
processed before the waitForFinish.

I'm seeing this in the logcat:
06-19 23:10:25.508: D/RootTools v2.6(25904): Command 0finished.
06-19 23:10:25.508: D/RootTools v2.6(25904): Using Existing Root Shell!
06-19 23:10:25.508: D/RootTools v2.6(25904): Sending command(s): ls 
/data/data/org.mozilla.firefox/files/mozilla/
06-19 23:10:25.528: D/RootTools v2.6(25904): Command 0finished.
06-19 23:10:25.538: D/RootTools v2.6(25904): Using Existing Root Shell!
06-19 23:10:25.538: D/RootTools v2.6(25904): Sending command(s): 
07uxqsq0.default

I wonder if existing shell could be the problem?

Original comment by luke...@msn.com on 20 Jun 2013 at 6:15

GoogleCodeExporter commented 8 years ago
Can you try this version for me?

This is scheduled to be v3.0

Let me know if the same issue exists.

Original comment by Stericso...@gmail.com on 20 Jun 2013 at 1:59

GoogleCodeExporter commented 8 years ago
It's still happening, but not all the time. Sometimes the line after 
waitForFinish is first to run, sometimes the output() are called before the 
lines after waitForFinish.

Original comment by luke...@msn.com on 22 Jun 2013 at 7:04

GoogleCodeExporter commented 8 years ago
This has been fixed. I believe that what is happening is that you are being hit 
by the timeout exception.

This is not always obvious however because of a design flaw in the application.

In this new version please note that I have deprecated waitForFinish(), you can 
still use it if you like but I strongly recommend not using it.

Also, please notice that you need to implement two methods when extending 
Command, commandTerminated and commandCompleted. These methods will allow you 
to determine if a command has executed correctly or it was terminated for some 
reason, like a timeout exception.

If you are running long operations in the shell, consider increasing the 
timeout by passing it into the timeout constructor. The default is 50000 
seconds which should be enough for normal operations.

Original comment by Stericso...@gmail.com on 27 Jun 2013 at 4:24

GoogleCodeExporter commented 8 years ago
Sorry, that should have been "Command constructor" instead of "timeout 
constructor"

Original comment by Stericso...@gmail.com on 27 Jun 2013 at 4:29

GoogleCodeExporter commented 8 years ago
Updated the binary to address another issue. When a command has been terminated 
output from the shell will stop immediately upon that termination.

Original comment by Stericso...@gmail.com on 27 Jun 2013 at 4:52

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks, it seems to be working now. I noticed both waitForFinish and exitCode() 
are deprecated, so what is the recommended way of running a Command now? I'm 
curious how the exit code could be sent to the app, when the output is not yet 
processed, but I guess that's some sort of Java buffer/output thing?

Original comment by luke...@msn.com on 28 Jun 2013 at 5:29

GoogleCodeExporter commented 8 years ago
waitForFinish never executed the command.

The shell is constantly executing commands as they are added to it. So when you 
call add(command) the command get's put into a que and will be the executed as 
soon as it can be executed.

You should extend Command and implement the three methods there. Two of the 
methods, commandTerminated and commandFinished, will let you know when your 
command has finished. commandFinished will also return to you the exitcode for 
the command in question.

I also uploaded the most recent version that I have built, it has the method 
getExitCode() that you can use to fetch the exitcode after the command has 
finished.

Hope that helps.

Original comment by Stericso...@gmail.com on 28 Jun 2013 at 1:49

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by Stericso...@gmail.com on 28 Jun 2013 at 6:41

GoogleCodeExporter commented 8 years ago
Thanks, but I'm having one big problem in converting code to this new working 
3.0

Previously you could waitforFinish a number of tasks, and do something when 
they finished.

Now I don't know if this is possible - I know there's join on thread, but this 
isn't exactly a thread. Is something like this possible? 
http://stackoverflow.com/questions/17418194/multiple-callback-waiting-in-android
-java

Original comment by luke...@msn.com on 3 Jul 2013 at 2:24

GoogleCodeExporter commented 8 years ago
I posted an answer here: 
http://stackoverflow.com/questions/17418194/multiple-callback-waiting-in-android
-java/17438858#17438858

Original comment by Stericso...@gmail.com on 3 Jul 2013 at 2:45