Giter Club home page Giter Club logo

Comments (5)

Chainfire avatar Chainfire commented on July 20, 2024

There is no reliable way to know if access was denied or the command returned no output, without echo-ing something yourself first.

from libsuperuser.

nioncode avatar nioncode commented on July 20, 2024

The docs at http://su.chainfire.eu/ say otherwise.

The SH variants are used for a non-root shell, where the SU variants are used for a root shell. These calls return a List containing the output of the shell commands. If there was no output, the list is empty, but not null. The result is only null in case an error occured - including the user not granting your app su access. These are blocking calls.

Please update them, if the call really does never return 'null'.

What is the best practice to check for a permission error, then?
Something like Shell.SU.run("echo foo > bar && echo 0")?

from libsuperuser.

Chainfire avatar Chainfire commented on July 20, 2024

If read the few lines of code, you'll see it does indeed sometimes return null. Specifically, when an error has occurred.

On some su binaries it does generate null, on others it does not.

Using Shell.SU.available() to check root is generally considered a good idea. Or indeed, you can echo something first. But you still need to check for null either way.

from libsuperuser.

nioncode avatar nioncode commented on July 20, 2024

The issue with Shell.SU.available() is that this is effectively the same as executing a custom command and checking its output. Thus, there are 2 calls with possibly 2 requests to the user (if he does not use 'always allow') and even if there are not 2 popups, it will be twice as slow, resulting in a ~700ms response instead of a ~350ms response during my tests on my Nexus 5x.

Thus, I now just run my custom command and check if it has worked afterwards without making an additional SU call.

It should definitely be added to the docs that it is not guaranteed to return null on errors that are caused by denied su access.

from libsuperuser.

Chainfire avatar Chainfire commented on July 20, 2024

If you want to use a single shell for all of this, use Shell.Builder / Shell.Interactive, that's what it's for.

I'll adjust that doc, though, it is incomplete.

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.