示例#1
0
 /**
  * This will tell you how the specified mount is mounted. rw, ro, etc...
  *
  * @param path The mount you want to check
  * @return <code>String</code> What the mount is mounted as.
  * @throws Exception if we cannot determine how the mount is mounted.
  */
 public String getMountedAs(String path) throws Exception {
   ArrayList<Mount> mounts = Remounter.getMounts();
   if (mounts != null) {
     for (Mount mount : mounts) {
       if (path.contains(mount.getMountPoint().getAbsolutePath())) {
         Log.d(RootCommands.TAG, (String) mount.getFlags().toArray()[0]);
         return (String) mount.getFlags().toArray()[0];
       }
     }
   }
   throw new Exception();
 }
  /**
   * 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
  /**
   * 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 : getMounts()) {
          Log.d(RootCommands.TAG, mount.getMountPoint().toString());

          if (file.equals(mount.getMountPoint().toString())) {
            foundMount = true;
            break;
          }
        }
      } catch (Exception e) {
        Log.e(RootCommands.TAG, "Exception", e);
        return false;
      }
      if (!foundMount) {
        try {
          file = (new File(file).getParent()).toString();
        } catch (Exception e) {
          Log.e(RootCommands.TAG, "Exception", e);
          return false;
        }
      }
    }
    Mount mountPoint = findMountPointRecursive(file);

    Log.d(
        RootCommands.TAG,
        "Remounting "
            + mountPoint.getMountPoint().getAbsolutePath()
            + " as "
            + mountType.toLowerCase(Locale.US));
    final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US));

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

        // execute on shell
        shell.add(command).waitForFinish();

      } catch (Exception e) {
      }

      mountPoint = findMountPointRecursive(file);
    }

    if (mountPoint != null) {
      Log.d(RootCommands.TAG, mountPoint.getFlags() + " AND " + mountType.toLowerCase(Locale.US));
      if (mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US))) {
        Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
        return true;
      } else {
        Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
      }
    } else {
      Log.d(RootCommands.TAG, "mountPoint is null");
    }
    return false;
  }