Пример #1
0
  public static boolean remount(String file, String mountType) {

    if (file.endsWith("/") && !file.equals("/")) {
      file = file.substring(0, file.lastIndexOf("/"));
    }

    boolean foundMount = false;

    List<Mount> mounts = getMounts();
    if (mounts == null || mounts.isEmpty()) {
      return false;
    }

    while (!foundMount) {
      for (Mount mount : mounts) {
        if (file.equals(mount.getMountPoint().toString())) {
          foundMount = true;
          break;
        }
      }
      if (!foundMount) {
        file = (new File(file).getParent()).toString();
      }
    }

    Mount mountPoint = getMountPoint(file);

    final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase());

    if (!isMountMode) {

      Command command =
          new Command(
              "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()) {

            @Override
            public void onUpdate(int id, String message) {}

            @Override
            public void onFinished(int id) {}
          };

      try {
        Shell.startRootShell().add(command).waitForFinish();
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } catch (TimeoutException e) {
        e.printStackTrace();
      } catch (PermissionException e) {
        e.printStackTrace();
      }
    }

    mountPoint = getMountPoint(file);

    if (mountPoint.getFlags().contains(mountType.toLowerCase())) {
      return true;
    } else {
      return false;
    }
  }