Giter Club home page Giter Club logo

Comments (9)

Chainfire avatar Chainfire commented on July 2, 2024

I'm not really sure I understand the problem...

from libsuperuser.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024

@Chainfire Which part of it didn't you understand?
I wanted to get root and perform the (background) operations right after I got it (and maybe more later)...

Anyway, since there wasn't a response about it so far, I had to come up with a different solution:
http://stackoverflow.com/a/24391772/878126
The calls to the other functions when I got root are done on a background thread and I always use the same session that I got from the library.
Also, since "addCommand" needs a listener, I wait for it to return a value on the same thread that called it, using the technique used here:
http://tutorials.jenkov.com/java-concurrency/thread-signaling.html

from libsuperuser.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024

Why was this issue closed? Is my solution legit and OK ? I hope it won't break anything...

from libsuperuser.

Chainfire avatar Chainfire commented on July 2, 2024

This is not an issue with the library. This is you not grasping how it works or how it should be used - probably. Your original question is vague, and your clarification is even vaguer - pointing to a SO post that only appears to be vaguely related to the question asked here, and referencing some java article about concurrency.

I don't see anything specifically wrong with the class you put on SO, but I haven't actually tried and tested it, so that means very little.

from libsuperuser.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024

But you didn't explain what part of what I've written you didn't understand.... :(
Let me try again:
Some root operations are being ran on files, for example, so it's better to run them in a background thread, instead of the UI thread.
Now, since I intend to run multiple root operations, I wanted to hold the same session for all of the operations instead of causing the user to confirm each of them.
That's why I've tried using what's called "interactive mode" , which allows this exact thing.
What I've asked is how it should be achieved, as the API doesn't seem to offer it out-of-the box, and then I've found a way myself, which I'm not sure if it's ok to use, and if there's a better way.

from libsuperuser.

Chainfire avatar Chainfire commented on July 2, 2024

Everything you write is so very open to interpretation...

"the API doesn't seem to offer it out-of-the box"

Sure it does. Create an Shell.Interactive.Builder, set up it's properties, call open() on it (optionally with a listener that lets you know if root wasn't achieved). This returns a Shell.Interactive object you can call addCommand() on (with optional listeners for command completions and/or output).

"It seems the only way to start interactive mode is by using a listener."

I have no idea what you even want to say here.

"When I try to avoid this, only when root permission is given, I get the listener being called, but if the root permission isn't given, the listener isn't called."

Avoid what exactly? What type of listener are you using? There are multiple listeners that behave differently in different circumstances.

"Is there a way to start interactive mode on the background thread?"

Start, or run commands? Most Shell.Interactive functionality is asynchronous. Commands are not actually run on the thread open() is called on. But yes, you can most certainly (and is often advised) start an interactive shell from a different thread. Just call open() from the background thread instead of the main thread. I don't understand how this can be the question, as simply copying your code to a thread and trying to run it would have answered this.

"I could use rootSession.addCommand(String) , and then rootSession.waitForIdle() , but then I lose the output lines that were written..."

So use a callback with addCommand that gives you the output? waitForIdle is a blocking call that should rarely be used, and certainly not from the main thread. Sounds like you're trying to make event driven code behave like procedural code.

If you're running into issues where your callbacks aren't called while you're waiting (for example with waitForIdle) then you're probably having the callbacks be run on the same thread that is waiting (calls waitForIdle). In that case you need to read up on Handlers, and provide a different thread's Handler to the Shell.Interactive.Builder. A HandlerThread is often used for this.

from libsuperuser.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024

All I wanted is to have my own thread (maybe even on an AsyncTask) and start interactive mode inside it.
Then, according to the result of whether I got root or not, I will act accordingly (have a live session or not).
What I was talking about is that the API lacks this functionality and forces you to use a listener (using the "open" function).
I wanted to avoid using this listener (of getting root), as I will already know if root is given or not right away.
For example :

... doInBackground()
{
Shell.Interactive session= ... .open();
if(session.gotRoot())
...
}

Instead, I had to use a listener inside.

Anyway, it seems you've made yourself clear, as all operations of root are being run on a thread you've created, so you have to use a listener, and what I've done is probably fine.

So, sorry for taking your time, and thank you for making this cool library (and other projects you've created).

from libsuperuser.

Chainfire avatar Chainfire commented on July 2, 2024

Well, at least I understand what you mean now. You are correct, this is not currently available.

from libsuperuser.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024

@Chainfire again, sorry for taking a lot of your time.
I really like your work. Thank you.
You are welcomed to try my app if you wish. its root abilities are based on your library:
https://play.google.com/store/apps/details?id=com.lb.app_manager

from libsuperuser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.