Optimize root shell and startups

This commit is contained in:
topjohnwu
2017-02-05 22:02:14 +08:00
parent 0886dca385
commit b3b2149ebb
6 changed files with 85 additions and 97 deletions

View File

@@ -25,18 +25,9 @@ public class Utils {
public static boolean isDownloading = false;
public static boolean itemExist(String path) {
return itemExist(true, path);
}
public static boolean itemExist(boolean root, String path) {
String command = "if [ -e " + path + " ]; then echo true; else echo false; fi";
List<String> ret;
if (Shell.rootAccess() && root) {
ret = Shell.su(command);
return isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(0));
} else {
return new File(path).exists();
}
List<String> ret = Shell.su(command);
return isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(0));
}
public static boolean commandExists(String s) {
@@ -59,10 +50,8 @@ public class Utils {
}
public static List<String> getModList(String path) {
List<String> ret;
String command = "find " + path + " -type d -maxdepth 1 ! -name \"*.core\" ! -name \"*lost+found\" ! -name \"*magisk\"";
ret = Shell.su(command);
return ret;
return Shell.su(command);
}
public static List<String> readFile(String path) {
@@ -151,4 +140,13 @@ public class Utils {
return Integer.parseInt(prefs.getString(key, String.valueOf(def)));
}
public static void checkAndStartMagiskHide() {
String command = "ps | grep magiskhide >/dev/null; echo $?";
List<String> ret = Shell.su(command);
if (!isValidShellResponse(ret))
return;
if (Integer.parseInt(ret.get(0)) != 0)
new Async.MagiskHide().enable();
}
}