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
@@ -15,16 +15,15 @@ public class Shell {
// -1 = problematic/unknown issue; 0 = not rooted; 1 = properly rooted
public static int rootStatus;
private static boolean isInit = false;
private static Process rootShell;
private static DataOutputStream rootSTDIN;
private static StreamGobbler rootSTDOUT;
private static List<String> rootOutList = new ArrayList<>();
private static List<String> rootOutList = Collections.synchronizedList(new ArrayList<String>());
static {
init();
}
public static void init() {
private static void init() {
isInit = true;
try {
rootShell = Runtime.getRuntime().exec("su");
@@ -64,7 +63,7 @@ public class Shell {
}
public static boolean rootAccess() {
return rootStatus > 0;
return isInit && rootStatus > 0;
}
public static List<String> sh(String... commands) {
@@ -120,9 +119,12 @@ public class Shell {
DataOutputStream STDIN;
StreamGobbler STDOUT;
if (!rootAccess()) {
// Create the default shell if not init
if (!newShell && !isInit)
init();
if (!newShell && !rootAccess())
return null;
}
if (newShell) {
res = Collections.synchronizedList(new ArrayList<String>());