Skip to content

Commit

Permalink
Fix IO scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkumar66 committed Jun 27, 2020
1 parent db5a567 commit d143caf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
22 changes: 9 additions & 13 deletions app/src/main/java/com/performancetweaker/app/utils/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,18 @@ public static String getReadAhead() {
public static boolean setDiskScheduler(String ioScheduler) {
ArrayList<String> 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());
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/performancetweaker/app/utils/SysUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,7 +42,7 @@ public static String readOutputFromFile(String pathToFile) {
}
/*
* try reading the file as root
*/
*/
else {
InputStream inputStream;
DataOutputStream dos;
Expand Down Expand Up @@ -74,7 +76,9 @@ public static boolean executeRootCommand(List<String> 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");
Expand Down Expand Up @@ -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();
Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/com/performancetweaker/app/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


}

0 comments on commit d143caf

Please sign in to comment.