diff --git a/app/src/main/java/com/performancetweaker/app/utils/IOUtils.java b/app/src/main/java/com/performancetweaker/app/utils/IOUtils.java index 63590c8..03070a7 100755 --- a/app/src/main/java/com/performancetweaker/app/utils/IOUtils.java +++ b/app/src/main/java/com/performancetweaker/app/utils/IOUtils.java @@ -60,22 +60,18 @@ public static String getReadAhead() { public static boolean setDiskScheduler(String ioScheduler) { ArrayList mCommands = new ArrayList<>(); if (ioScheduler != null) { - File[] devices = new File(AVAILABLE_BLOCKDEVICES).listFiles(); + File[] devices = Utils.listFiles(AVAILABLE_BLOCKDEVICES); + for (int i = 0; i < devices.length; i++) { + String devicePath = devices[i].getAbsolutePath(); - if (devices != null) { - for (int i = 0; i < devices.length; i++) { + if (!(devicePath.contains("ram") || devicePath.contains("loop") || devicePath.contains( + "dm"))) { - String devicePath = devices[i].getAbsolutePath(); + File blockDevice = new File(devices[i].getAbsolutePath() + "/queue/scheduler"); - if (!(devicePath.contains("ram") || devicePath.contains("loop") || devicePath.contains( - "dm"))) { - - File blockDevice = new File(devices[i].getAbsolutePath() + "/queue/scheduler"); - - if (blockDevice.exists()) { - mCommands.add("chmod 0644 " + blockDevice.getAbsolutePath()); - mCommands.add("echo " + ioScheduler + " > " + blockDevice.getAbsolutePath()); - } + if (blockDevice.exists()) { + mCommands.add("chmod 0644 " + blockDevice.getAbsolutePath()); + mCommands.add("echo " + ioScheduler + " > " + blockDevice.getAbsolutePath()); } } } diff --git a/app/src/main/java/com/performancetweaker/app/utils/SysUtils.java b/app/src/main/java/com/performancetweaker/app/utils/SysUtils.java index 50432a3..6c99743 100755 --- a/app/src/main/java/com/performancetweaker/app/utils/SysUtils.java +++ b/app/src/main/java/com/performancetweaker/app/utils/SysUtils.java @@ -2,6 +2,8 @@ import android.util.Log; +import com.stericson.RootTools.RootTools; + import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; @@ -40,7 +42,7 @@ public static String readOutputFromFile(String pathToFile) { } /* * try reading the file as root - */ + */ else { InputStream inputStream; DataOutputStream dos; @@ -74,7 +76,9 @@ public static boolean executeRootCommand(List commands) { try { Process mProcess = Runtime.getRuntime().exec("su"); - if (mProcess == null){ return false;} + if (mProcess == null) { + return false; + } dos = new DataOutputStream(mProcess.getOutputStream()); for (String cmd : commands) { dos.writeBytes(cmd + "\n"); @@ -120,7 +124,7 @@ public static String executeCommandWithOutput(boolean root, String command) { StringBuilder builder = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; - while ((line = br.readLine()) != null) builder.append(line); + while ((line = br.readLine()) != null) builder.append(line + "\n"); return builder.toString(); } else { is = process.getErrorStream(); diff --git a/app/src/main/java/com/performancetweaker/app/utils/Utils.java b/app/src/main/java/com/performancetweaker/app/utils/Utils.java index aec08c1..1878807 100644 --- a/app/src/main/java/com/performancetweaker/app/utils/Utils.java +++ b/app/src/main/java/com/performancetweaker/app/utils/Utils.java @@ -16,7 +16,28 @@ public static void startService(Context context, Intent intent) { } } - public static boolean fileExists(String file) { - return new File(file).exists(); + public static boolean fileExists(String filePath) { + if (new File(filePath).exists()) { + return true; + } else { + String output = SysUtils.executeCommandWithOutput(true, "[ -e " + filePath + " ] && echo true"); + return output != null && output.equals("true"); + } } + + public static File[] listFiles(String directory) { + File[] filesList = new File(directory).listFiles(); + if (filesList == null || filesList.length == 0) { + //try as root + String output = SysUtils.executeCommandWithOutput(true, "ls " + directory); + String filesPath[] = output.split("\n"); + filesList = new File[filesPath.length]; + for (int i = 0; i < filesPath.length; i++) { + filesList[i] = new File(directory + filesPath[i]); + } + } + return filesList; + } + + }