public String sendCommand(String commandString) {
    String result = "";

    if (checkRoot()) {
      CommandCapture command = new CommandCapture(0, commandString);
      try {
        RootTools.getShell(true).add(command).waitForFinish();
        result = command.toString();
        LAST_COMMAND_OUTPUT = result;
        LAST_EXIT_CODE = command.exitCode();
      } catch (InterruptedException e) {
        // TODO: Do something useful with the exceptions
        // e.printStackTrace();
      } catch (IOException e) {
        // e.printStackTrace();
      } catch (TimeoutException e) {
        // e.printStackTrace();
      } catch (RootDeniedException e) {
        // e.printStackTrace();
      }
    }
    return result;
  }
示例#2
0
  @Override
  protected ShellCommandResult doInBackground(Void... params) {

    String umountCommand = String.format("umount %s", mMountPoint);
    CommandCapture unmountCommand = new CommandCapture(0, umountCommand);
    ShellCommandResult result = null;

    try {
      RootTools.getShell(true).add(unmountCommand);
      unmountCommand.waitForFinish();
      Log.d(
          CLASS,
          String.format("umount [%d] %s", unmountCommand.exitCode(), unmountCommand.toString()));
      result = new ShellCommandResult(unmountCommand.exitCode(), unmountCommand.toString());
    } catch (Exception exception) {
      mError = exception;
      cancel(false);
    }

    return result;
  }