GithubHelp home page GithubHelp logo

morristech / rxshell Goto Github PK

View Code? Open in Web Editor NEW

This project forked from d4rken/rxshell

0.0 1.0 0.0 288 KB

Easy shell access for Android apps using RxJava.

License: Apache License 2.0

Java 100.00%

rxshell's Introduction

RxShell

Build Status Download Coverage Status

A library that helps your app interact with shells on Android.

Quickstart

Include the library in your modules build.gradle file:

implementation 'eu.darken.rxshell:core:<insert-latest-release>'
implementation 'eu.darken.rxshell:root:<insert-latest-release>' // For root related extensions

Now your project is ready to use the library, let's quickly talk about a few core concepts:

  1. You construct a shell using RxCmdShell.builder().
  2. The shell has to be opened before use (shell.open()), which will launch the process and give you a RxCmdShell.Session to work with.
  3. Build your commands with Cmd.builder("your command").
  4. Commands are run with session.submit(command), cmd.submit(session) or cmd.execute(session).
  5. Remember to close() the session to release resources.

Examples

Single-Shot execution

If you pass a shell builder to the command it will be used for a single shot execution.

A shell is created and opened, used and closed.

Cmd.execute(...) is shorthand for Cmd.submit(...).blockingGet(), so don't run it from a UI thread.

Cmd.Result result = Cmd.builder("echo hello").execute(RxCmdShell.builder());

Reusing a shell

If you want to issue multiple commands, you can reuse the shell which is faster and uses less resources.

RxCmdShell.Session session = RxCmdShell.builder().build().open().blockingGet();
// Blocking
Cmd.Result result1 = Cmd.builder("echo straw").execute(session);
// Async
Cmd.builder("echo berry").submit(session).subscribe(result -> Log.i("ExitCode: " + result.getExitCode()));
shell.close().blockingGet();

The default shell process is launched using sh, if you want to open a root shell (using su) tell the ShellBuilder!

Cmd.Result result = Cmd.builder("echo hello").execute(RxCmdShell.builder().root(true));

Checking root access

// General info
new RootContext.Builder(getContext()).build().subscribe(c -> {/* c.getRoot().getState() */});
// Just root state
Root root = new Root.Builder().build().blockingGet();
if(root.getState() == Root.State.ROOTED) /* yay */

Used by

  • SD Maid, which was also the motivation for this library.

Alternatives

While this is obviously :^) the best library, there are alternatives you could be interested in:

rxshell's People

Contributors

d4rken avatar joni-salminen avatar

Watchers

 avatar

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.