Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What happened to "waitForFinish" ? #10

Closed
AndroidDeveloperLB opened this issue Apr 29, 2014 · 4 comments
Closed

What happened to "waitForFinish" ? #10

AndroidDeveloperLB opened this issue Apr 29, 2014 · 4 comments

Comments

@AndroidDeveloperLB
Copy link

I haven't updated the library in a while.
I want to perform some root operations via a background thread, and found out this function is missing.

What should I use instead?
How can I perform multiple commands, and wait for all to finish?

@AndroidDeveloperLB
Copy link
Author

That's really weird. At least give people choice, or put documentation (the old ones still exist), or deprecate it...

I used this library to make things a bit easier, but if the minimal thing is not possible, I think I will make my own solution. It's not the hardest thing to do.
The license is also a weird thing to ask for. It's such a small code...

Anyway, I think I will make my own solution. I just need the root stuff.

@AndroidDeveloperLB
Copy link
Author

I always put credits to all libraries that I use, even in code (so that it will be easier to find) . This is my app:
https://play.google.com/store/apps/details?id=com.lb.app_manager

@chenxiaolong
Copy link

Another method is to take advantage of Java's threading wait() and notify() methods.

    public static class RootCommandRunner extends Thread {
        @Override
        public void run() {
            try {
                Command command = new Command(0, "root command here") {
                    @Override
                    public void commandOutput(int id, String line) {
                    }

                    @Override
                    public void commandCompleted(int id, int exitCode) {
                        synchronized (RootCommandRunner.this) {
                            RootCommandRunner.this.notify();
                        }
                    }

                    @Override
                    public void commandTerminated(int id, String reason) {
                        synchronized (RootCommandRunner.this) {
                            RootCommandRunner.this.notify();
                        }
                    }
                };

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

                synchronized (this) {
                    wait();
                }

                // Anything here will execute after the command is finished
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (TimeoutException e) {
                e.printStackTrace();
            } catch (RootDeniedException e) {
                e.printStackTrace();
            }
        }
    }

@AndroidDeveloperLB
Copy link
Author

@chenxiaolong If you want to use a wait-notifier mechanism , I think this is the correct way to do it:
http://tutorials.jenkov.com/java-concurrency/thread-signaling.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants