コード例 #1
0
ファイル: Remounter.java プロジェクト: Soaa-/turbo-editor
  /**
   * This will return an ArrayList of the class Mount. The class mount contains the following
   * property's: device mountPoint type flags
   *
   * <p>These will provide you with any information you need to work with the mount points.
   *
   * @return <code>ArrayList<Mount></code> an ArrayList of the class Mount.
   * @throws Exception if we cannot return the mount points.
   */
  protected static ArrayList<Mount> getMounts() throws Exception {

    final String tempFile = "/data/local/RootToolsMounts";

    // copy /proc/mounts to tempfile. Directly reading it does not work on 4.3
    Shell shell = Shell.startRootShell();
    Toolbox tb = new Toolbox(shell);
    tb.copyFile("/proc/mounts", tempFile, false, false);
    tb.setFilePermissions(tempFile, "777");
    shell.close();

    LineNumberReader lnr = null;
    lnr = new LineNumberReader(new FileReader(tempFile));
    String line;
    ArrayList<Mount> mounts = new ArrayList<Mount>();
    while ((line = lnr.readLine()) != null) {

      Log.d(RootCommands.TAG, line);

      String[] fields = line.split(" ");
      mounts.add(
          new Mount(
              new File(fields[0]), // device
              new File(fields[1]), // mountPoint
              fields[2], // fstype
              fields[3] // flags
              ));
    }
    lnr.close();

    return mounts;
  }
コード例 #2
0
  /**
   * This will take a path, which can contain the file name as well, and attempt to remount the
   * underlying partition.
   *
   * <p>For example, passing in the following string:
   * "/system/bin/some/directory/that/really/would/never/exist" will result in /system ultimately
   * being remounted. However, keep in mind that the longer the path you supply, the more work this
   * has to do, and the slower it will run.
   *
   * @param file file path
   * @param mountType mount type: pass in RO (Read only) or RW (Read Write)
   * @return a <code>boolean</code> which indicates whether or not the partition has been remounted
   *     as specified.
   */
  protected boolean remount(String file, String mountType) {

    // if the path has a trailing slash get rid of it.
    if (file.endsWith("/") && !file.equals("/")) {
      file = file.substring(0, file.lastIndexOf("/"));
    }
    // Make sure that what we are trying to remount is in the mount list.
    boolean foundMount = false;
    while (!foundMount) {
      try {
        for (Mount mount : RootTools.getMounts()) {
          RootTools.log(mount.getMountPoint().toString());

          if (file.equals(mount.getMountPoint().toString())) {
            foundMount = true;
            break;
          }
        }
      } catch (Exception e) {
        if (RootTools.debugMode) {
          e.printStackTrace();
        }
        return false;
      }
      if (!foundMount) {
        try {
          file = (new File(file).getParent()).toString();
        } catch (Exception e) {
          e.printStackTrace();
          return false;
        }
      }
    }
    Mount mountPoint = findMountPointRecursive(file);

    RootTools.log(
        InternalVariables.TAG,
        "Remounting "
            + mountPoint.getMountPoint().getAbsolutePath()
            + " as "
            + mountType.toLowerCase());
    final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase());

    if (!isMountMode) {
      // grab an instance of the internal class
      try {
        CommandCapture command =
            new CommandCapture(
                0,
                "busybox mount -o remount,"
                    + mountType.toLowerCase()
                    + " "
                    + mountPoint.getDevice().getAbsolutePath()
                    + " "
                    + mountPoint.getMountPoint().getAbsolutePath(),
                "toolbox mount -o remount,"
                    + mountType.toLowerCase()
                    + " "
                    + mountPoint.getDevice().getAbsolutePath()
                    + " "
                    + mountPoint.getMountPoint().getAbsolutePath(),
                "mount -o remount,"
                    + mountType.toLowerCase()
                    + " "
                    + mountPoint.getDevice().getAbsolutePath()
                    + " "
                    + mountPoint.getMountPoint().getAbsolutePath(),
                "/system/bin/toolbox mount -o remount,"
                    + mountType.toLowerCase()
                    + " "
                    + mountPoint.getDevice().getAbsolutePath()
                    + " "
                    + mountPoint.getMountPoint().getAbsolutePath());

        Shell.startRootShell().add(command);
        command.waitForFinish();

      } catch (Exception e) {
      }

      mountPoint = findMountPointRecursive(file);
    }

    Log.i(InternalVariables.TAG, mountPoint.getFlags() + " AND " + mountType.toLowerCase());
    if (mountPoint.getFlags().contains(mountType.toLowerCase())) {
      RootTools.log(mountPoint.getFlags().toString());
      return true;
    } else {
      RootTools.log(mountPoint.getFlags().toString());
      return false;
    }
  }
コード例 #3
0
ファイル: Installer.java プロジェクト: huhu/OpenExplorer
  /**
   * This method can be used to unpack a binary from the raw resources folder and store it in
   * /data/data/app.package/files/ This is typically useful if you provide your own C- or C++-based
   * binary. This binary can then be executed using sendShell() and its full path.
   *
   * @param sourceId resource id; typically <code>R.raw.id</code>
   * @param destName destination file name; appended to /data/data/app.package/files/
   * @param mode chmod value for this file
   * @return a <code>boolean</code> which indicates whether or not we were able to create the new
   *     file.
   */
  protected boolean installBinary(int sourceId, String destName, String mode) {
    File mf = new File(filesPath + File.separator + destName);
    if (!mf.exists()) {
      // First, does our files/ directory even exist?
      // We cannot wait for android to lazily create it as we will soon
      // need it.
      try {
        FileInputStream fis = context.openFileInput(BOGUS_FILE_NAME);
        fis.close();
      } catch (FileNotFoundException e) {
        FileOutputStream fos = null;
        try {
          fos = context.openFileOutput("bogus", Context.MODE_PRIVATE);
          fos.write("justcreatedfilesdirectory".getBytes());
        } catch (Exception ex) {
          if (RootTools.debugMode) {
            Log.e(LOG_TAG, ex.toString());
          }
          return false;
        } finally {
          if (null != fos) {
            try {
              fos.close();
              context.deleteFile(BOGUS_FILE_NAME);
            } catch (IOException e1) {
            }
          }
        }
      } catch (IOException ex) {
        if (RootTools.debugMode) {
          Log.e(LOG_TAG, ex.toString());
        }
        return false;
      }

      // Only now can we start creating our actual file
      InputStream iss = context.getResources().openRawResource(sourceId);
      FileOutputStream oss = null;
      try {
        oss = new FileOutputStream(mf);
        byte[] buffer = new byte[4096];
        int len;
        try {
          while (-1 != (len = iss.read(buffer))) {
            oss.write(buffer, 0, len);
          }
        } catch (IOException ex) {
          if (RootTools.debugMode) {
            Log.e(LOG_TAG, ex.toString());
          }
          return false;
        }
      } catch (FileNotFoundException ex) {
        if (RootTools.debugMode) {
          Log.e(LOG_TAG, ex.toString());
        }
        return false;
      } finally {
        if (oss != null) {
          try {
            oss.close();
          } catch (IOException e) {
          }
        }
      }
      try {
        iss.close();
      } catch (IOException ex) {
        if (RootTools.debugMode) {
          Log.e(LOG_TAG, ex.toString());
        }
        return false;
      }

      try {
        CommandCapture command =
            new CommandCapture(0, "chmod " + mode + " " + filesPath + File.separator + destName);
        Shell.startRootShell().add(command);
        command.waitForFinish();
      } catch (Exception e) {
      }
    }
    return true;
  }