当前位置: 首页>>代码示例>>Java>>正文


Java Shell类代码示例

本文整理汇总了Java中com.stericson.RootTools.execution.Shell的典型用法代码示例。如果您正苦于以下问题:Java Shell类的具体用法?Java Shell怎么用?Java Shell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Shell类属于com.stericson.RootTools.execution包,在下文中一共展示了Shell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInode

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * This method will return the inode number of a file. This method is dependent on having a version of
 * ls that supports the -i parameter.
 *
 * @param file path to the file that you wish to return the inode number
 * @return String The inode number for this file or "" if the inode number could not be found.
 */
public String getInode(String file) {
    try {
        CommandCapture command = new CommandCapture(Constants.GI, false, "/data/local/ls -i " + file) {

            @Override
            public void output(int id, String line) {
                if (id == Constants.GI) {
                    if (!line.trim().equals("") && Character.isDigit((char) line.trim().substring(0, 1).toCharArray()[0])) {
                        InternalVariables.inode = line.trim().split(" ")[0];
                    }
                }
            }
        };
        Shell.startRootShell().add(command);
        commandWait(Shell.startRootShell(), command);

        return InternalVariables.inode;
    } catch (Exception ignore) {
        return "";
    }
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:29,代码来源:RootToolsInternalMethods.java

示例2: getShell

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * The shell is set by BrowserPagerActivity and is released when BrowserPagerActivity
 * is destroyed.
 * Returns current global shell. If current shell is non-root, but root shell is requested,
 * it will ask for root shell every #REASK_FOR_ROOT_SHELL_THRESHOLD calls.
 *
 * @return shell shared Shell instance
 */
@Nullable
private Shell getShell() {
    synchronized (mShellLock) {
        final boolean suEnabled = Settings.getInstance().isSuEnabled();
        if (suEnabled && mShell != null && !mIsRootShell) {
            if (mSkipReaskForRootShellCount >= REASK_FOR_ROOT_SHELL_THRESHOLD) {
                mSkipReaskForRootShellCount = 0;
                final Pair<Boolean, Shell> result = ShellFactory.getRootShell();
                applyResult(result);
            } else {
                mSkipReaskForRootShellCount++;
            }
        }
        if (!suEnabled && mShell != null && mIsRootShell) {
            openNewShell();
            mSkipReaskForRootShellCount = REASK_FOR_ROOT_SHELL_THRESHOLD;
        }
        if (mShell == null || !Shell.isAnyShellOpen()) {
            openNewShell();
            mSkipReaskForRootShellCount = REASK_FOR_ROOT_SHELL_THRESHOLD;
        }
        return mShell;
    }
}
 
开发者ID:Doctoror,项目名称:Pure-File-Manager,代码行数:33,代码来源:ShellHolder.java

示例3: runTest

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
@Override
protected void runTest() throws Throwable {
    super.runTest();

    // init what application inits
    final Context context = getInstrumentation().getContext();
    final Settings settings = Settings.getInstance(context);
    com.docd.purefm.Environment.init((Application) context.getApplicationContext());
    PFMTextUtils.init(context);
    final Shell shell = ShellHolder.getShell();
    assertNotNull(shell);

    // override settings to force our test busybox
    if (!com.docd.purefm.Environment.hasBusybox()) {
        throw new RuntimeException("install busybox on a device before running this test");
    }
    settings.setUseCommandLine(true, false);

    testAgainstJavaIoFile(shell, settings);
    testFileReading(shell, settings);
    testFileDeletion(shell, settings);
    testFileCreation(shell, settings);
    testMkdir(shell, settings);
    testMkdirs(shell, settings);
}
 
开发者ID:Doctoror,项目名称:Pure-File-Manager,代码行数:26,代码来源:CommandLineFileTest.java

示例4: getInode

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * This method will return the inode number of a file. This method is dependent on having a version of
 * ls that supports the -i parameter.
 *
 * @param file path to the file that you wish to return the inode number
 * @return String The inode number for this file or "" if the inode number could not be found.
 */
public String getInode(String file) {
    try {
        CommandCapture command = new CommandCapture(Constants.GI, false, "/data/local/ls -i " + file) {

            @Override
            public void output(int id, String line) {
                if (id == Constants.GI) {
                    if (!line.trim().equals("") && Character.isDigit((char) line.trim().substring(0, 1).toCharArray()[0])) {
                        InternalVariables.inode = line.trim().split(" ")[0];
                    }
                }
            }
        };
        Shell.startRootShell().add(command);
        commandWait(command);

        return InternalVariables.inode;
    } catch (Exception ignore) {
        return "";
    }
}
 
开发者ID:cernekee,项目名称:ics-openconnect,代码行数:29,代码来源:RootToolsInternalMethods.java

示例5: initBamboo

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
private void initBamboo() {
    try {
        Shell shell = RootTools.getShell(true);
        shell.useCWD(this);
        JavaCommandCapture cmd = new JavaCommandCapture(
                43,
                false,
                Garden.this,
                "com.voilaweb.mobile.bamboogarden.RootHelper"
                + " init") {
        };
        shell.add(cmd);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Fusion,项目名称:BambooGarden,代码行数:18,代码来源:Garden.java

示例6: createNewBamboo

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
private void createNewBamboo(final BambooInfo bamboo) {
    try {
        Shell shell = RootTools.getShell(true);
        JavaCommandCapture cmd = new JavaCommandCapture(
                43,
                false,
                Garden.this,
                "com.voilaweb.mobile.bamboogarden.RootHelper"
                + " create "
                + bamboo.getName()) {
        };
        shell.add(cmd);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Fusion,项目名称:BambooGarden,代码行数:18,代码来源:Garden.java

示例7: updateBambooColor

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
protected void updateBambooColor(BambooInfo bamboo, int color) {
    try {
        Shell shell = RootTools.getShell(true);
        JavaCommandCapture cmd = new JavaCommandCapture(
                43,
                false,
                Garden.this,
                "com.voilaweb.mobile.bamboogarden.RootHelper"
                        + " color "
                        + bamboo.getName()
                        + " " + color) {

            @Override
            public void commandCompleted(int id, int exitCode) {
                super.commandCompleted(id, exitCode);
                refreshBambooGarden();
            }

        };
        shell.add(cmd);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Fusion,项目名称:BambooGarden,代码行数:26,代码来源:Garden.java

示例8: deleteBamboo

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
private void deleteBamboo(final BambooInfo bamboo) {
    if(bamboo != null) {
        try {
            Shell shell = RootTools.getShell(true);
            JavaCommandCapture cmd = new JavaCommandCapture(
                    43,
                    false,
                    Garden.this,
                    "com.voilaweb.mobile.bamboogarden.RootHelper"
                            + " delete "
                            + bamboo.getName()) {

                @Override
                public void commandCompleted(int id, int exitCode) {
                    super.commandCompleted(id, exitCode);
                    refreshBambooGarden();
                }

            };
            shell.add(cmd);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:Fusion,项目名称:BambooGarden,代码行数:27,代码来源:Garden.java

示例9: BlockDeviceObserver

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * Creates a new block device observer.
 * Does not start observing until {@link #startWatching()} is called.
 * @param rootShell The shell to execute mount commands in.
 * @param listener A listener to receive block device events.
 *                 Calls are received on the main thread.
 */
public BlockDeviceObserver(Shell rootShell, PartitionListener listener) {
    super("/dev/block/", FileObserver.CREATE | FileObserver.DELETE);
    mVolumes = new HashMap<String, Volume>();
    mListener = listener;
    mHandler = new Handler(Looper.getMainLooper());
    mRootShell = rootShell;
    detectDevices();
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:16,代码来源:BlockDeviceObserver.java

示例10: unmount

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
public void unmount(Shell shell, final UnmountListener listener) throws IOException {
    Command mountCommand = new CommandCapture(0, "umount " + getTarget()) {
        @Override
        public void commandCompleted(int id, int exitcode) {
            super.commandCompleted(id, exitcode);
            if (exitcode == 0) {
                getDevice().removeMount(Mount.this);
                listener.onUnmountSuccess(Mount.this);
            } else {
                listener.onUnmountError(Mount.this, null);
            }
        }
    };
    shell.add(mountCommand);
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:16,代码来源:Mount.java

示例11: Automounter

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * Creates a new automounter.
 * Must be registered to a {@link com.morlunk.mountie.fs.BlockDeviceObserver} in order to automount.
 * @param rootShell A root shell to execute mount commands in.
 * @param dirName The name of the directory to mount in on external storage.
 * @param mountListener A listener for newly automounted devices.
 * @param unmountListener A listener for unmounted automounted devices.
 */
public Automounter(Shell rootShell, String dirName, MountListener mountListener, UnmountListener unmountListener) {
    mRootShell = rootShell;
    mEmulatedDirectory = new File(Environment.getExternalStorageDirectory(), dirName);
    mMountDirectory = new File(DATA_DIR, dirName);
    mMountListener = mountListener;
    mUnmountListener = unmountListener;
    mMounts = new HashSet<Mount>();
    cleanDirectory(); // Treat directory like a tmpfs and delete+unmount contents.
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:18,代码来源:Automounter.java

示例12: closeShell

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * This will close either the root shell or the standard shell depending on what you specify.
 *
 * @param root a <code>boolean</code> to specify whether to close the root shell or the standard shell.
 * @throws IOException
 */
public static void closeShell(boolean root) throws IOException {
    if (root)
        Shell.closeRootShell();
    else
        Shell.closeShell();
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:13,代码来源:RootTools.java

示例13: getBusyBoxApplets

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * This will return an List of Strings. Each string represents an applet available from BusyBox.
 * <p/>
 *
 * @param path Path to the busybox binary that you want the list of applets from.
 * @return <code>null</code> If we cannot return the list of applets.
 */
public List<String> getBusyBoxApplets(String path) throws Exception {

    if (path != null && !path.endsWith("/") && !path.equals("")) {
        path += "/";
    } else if (path == null) {
        //Don't know what the user wants to do...what am I pshycic?
        throw new Exception("Path is null, please specifiy a path");
    }

    final List<String> results = new ArrayList<String>();

    CommandCapture command = new CommandCapture(Constants.BBA, false, path + "busybox --list") {

        @Override
        public void output(int id, String line) {
            if (id == Constants.BBA) {
                if (!line.trim().equals("") && !line.trim().contains("not found")) {
                    results.add(line);
                }
            }
        }
    };

    //try without root first...
    Shell.startShell().add(command);
    commandWait(Shell.startShell(), command);

    if(results.size() <= 0) {
        //try with root...
        Shell.startRootShell().add(command);
        commandWait(Shell.startRootShell(), command);
    }
    
    return results;
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:43,代码来源:RootToolsInternalMethods.java

示例14: isAccessGiven

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
/**
 * @return <code>true</code> if your app has been given root access.
 * @throws TimeoutException if this operation times out. (cannot determine if access is given)
 */
public boolean isAccessGiven() {
    try {
        RootTools.log("Checking for Root access");
        InternalVariables.accessGiven = false;

        CommandCapture command = new CommandCapture(Constants.IAG, false, "id") {
            @Override
            public void output(int id, String line) {
                if (id == Constants.IAG) {
                    Set<String> ID = new HashSet<String>(Arrays.asList(line.split(" ")));
                    for (String userid : ID) {
                        RootTools.log(userid);

                        if (userid.toLowerCase().contains("uid=0")) {
                            InternalVariables.accessGiven = true;
                            RootTools.log("Access Given");
                            break;
                        }
                    }
                    if (!InternalVariables.accessGiven) {
                        RootTools.log("Access Denied?");
                    }
                }
            }
        };
        Shell.startRootShell().add(command);
        commandWait(Shell.startRootShell(), command);

        return InternalVariables.accessGiven;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:acomminos,项目名称:Mountie,代码行数:40,代码来源:RootToolsInternalMethods.java

示例15: runCommand

import com.stericson.RootTools.execution.Shell; //导入依赖的package包/类
private static CommandResult runCommand(String command) throws IOException, CommandException
{
    final WaitCommand cmd = new WaitCommand(command);
    final Shell shell = Shell.getOpenShell();
    if (shell == null) throw new NullPointerException("Must start a shell before adding a command.");
    shell.add(cmd);
    final CommandResult result = cmd.waitForFinish();

    CommandNotFoundException.throwIfNotFound(result);
    if (result.terminated) throw new CommandException(result);

    return result;
}
 
开发者ID:Takhion,项目名称:android-tetheringfixer,代码行数:14,代码来源:Fixer.java


注:本文中的com.stericson.RootTools.execution.Shell类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。