Search in sources :

Example 1 with Shell

use of eu.chainfire.libsuperuser.Shell in project AmazeFileManager by TeamAmaze.

the class MainActivity method initializeInteractiveShell.

/**
 * Initializes an interactive shell, which will stay throughout the app lifecycle
 * The shell is associated with a handler thread which maintain the message queue from the
 * callbacks of shell as we certainly cannot allow the callbacks to run on same thread because
 * of possible deadlock situation and the asynchronous behaviour of LibSuperSU
 */
private void initializeInteractiveShell() {
    // handler threads every time the code relaunch.
    if (isRootExplorer()) {
        handlerThread = new HandlerThread("handler");
        handlerThread.start();
        handler = new Handler(handlerThread.getLooper());
        shellInteractive = (new Shell.Builder()).useSU().setHandler(handler).open();
    // TODO: check for busybox
    /*try {
                if (!RootUtils.isBusyboxAvailable()) {
                    Toast.makeText(this, getString(R.string.error_busybox), Toast.LENGTH_LONG).show();
                    closeInteractiveShell();
                    sharedPref.edit().putBoolean(PreferenceUtils.KEY_ROOT, false).apply();
                }
            } catch (ShellNotRunningException e) {
                e.printStackTrace();
                sharedPref.edit().putBoolean(PreferenceUtils.KEY_ROOT, false).apply();
            }*/
    }
}
Also used : Shell(eu.chainfire.libsuperuser.Shell) HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) CryptHandler(com.amaze.filemanager.database.CryptHandler) CloudHandler(com.amaze.filemanager.database.CloudHandler) UtilsHandler(com.amaze.filemanager.database.UtilsHandler) TabHandler(com.amaze.filemanager.database.TabHandler)

Example 2 with Shell

use of eu.chainfire.libsuperuser.Shell in project XposedInstaller by rovo89.

the class RootUtil method startShell.

/**
     * Starts an interactive shell with root permissions. Does nothing if
     * already running.
     *
     * @return true if root access is available, false otherwise
     */
public synchronized boolean startShell() {
    if (mShell != null) {
        if (mShell.isRunning()) {
            return true;
        } else {
            dispose();
        }
    }
    mCallbackThread = new HandlerThread("su callback listener");
    mCallbackThread.start();
    mCommandRunning = true;
    mShell = new Shell.Builder().useSU().setHandler(new Handler(mCallbackThread.getLooper())).setOnSTDERRLineListener(mStderrListener).open(mOpenListener);
    waitForCommandFinished();
    if (mLastExitCode != OnCommandResultListener.SHELL_RUNNING) {
        dispose();
        return false;
    }
    return true;
}
Also used : Shell(eu.chainfire.libsuperuser.Shell) HandlerThread(android.os.HandlerThread) Handler(android.os.Handler)

Example 3 with Shell

use of eu.chainfire.libsuperuser.Shell in project afwall by ukanth.

the class Api method cleanupUid.

// Cleanup unused shell opened by logservice
public static void cleanupUid() {
    try {
        Set<String> uids = G.storedPid();
        if (uids != null && uids.size() > 0) {
            Shell.Interactive tempSession = new Shell.Builder().useSU().open();
            for (String uid : uids) {
                Log.i(Api.TAG, "Cleaning up previous uid: " + uid);
                tempSession.addCommand("kill -9 " + uid);
            }
            G.storedPid(new HashSet());
            if (tempSession != null) {
                tempSession.kill();
                tempSession.close();
            }
        }
    } catch (ClassCastException e) {
        Log.e(TAG, "ClassCastException in cleanupUid: " + e.getMessage());
    } catch (Exception e) {
        Log.e(TAG, "Exception in cleanupUid: " + e.getMessage());
    }
}
Also used : Shell(eu.chainfire.libsuperuser.Shell) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Aggregations

Shell (eu.chainfire.libsuperuser.Shell)3 Handler (android.os.Handler)2 HandlerThread (android.os.HandlerThread)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)1 CloudHandler (com.amaze.filemanager.database.CloudHandler)1 CryptHandler (com.amaze.filemanager.database.CryptHandler)1 TabHandler (com.amaze.filemanager.database.TabHandler)1 UtilsHandler (com.amaze.filemanager.database.UtilsHandler)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 JSONException (org.json.JSONException)1