Finalize 2.0 version

This commit is contained in:
topjohnwu
2016-08-25 18:08:07 +08:00
parent 3e97d29bcf
commit dc06a132bc
11 changed files with 232 additions and 248 deletions
@@ -1,5 +1,7 @@
package com.topjohnwu.magisk.utils;
import android.os.AsyncTask;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -23,21 +25,18 @@ public class Shell {
private static List<String> rootOutList = new ArrayList<>();
static {
init();
}
private static void init() {
List<String> ret = sh("getprop magisk.supath");
if(!ret.isEmpty()) {
suPath = ret.get(0) + "/su";
rootStatus = 1;
} else {
suPath = "su";
rootStatus = 2;
}
}
public static boolean rootAccess() {
return rootStatus > 0;
}
public static void startRoot() {
rootStatus = rootStatus == 0 ? 1 : 2;
try {
rootShell = Runtime.getRuntime().exec(suPath);
@@ -45,15 +44,14 @@ public class Shell {
rootSTDOUT = new StreamGobbler(rootShell.getInputStream(), rootOutList);
rootSTDOUT.start();
} catch (IOException e) {
// runtime error! No binary found!
// runtime error! No binary found! Means no root
rootStatus = 0;
return;
}
List<String> ret = su("echo -BOC-", "id");
ret = su("echo -BOC-", "id");
if (ret == null) {
// Something wrong with root install, not enabled?
// Something wrong with root, not allowed?
rootStatus = -1;
return;
}
@@ -84,6 +82,10 @@ public class Shell {
}
}
public static boolean rootAccess() {
return rootStatus > 0;
}
public static List<String> sh(String... commands) {
List<String> res = Collections.synchronizedList(new ArrayList<String>());
@@ -36,7 +36,8 @@ public class StreamGobbler extends Thread {
try {
String line;
while ((line = reader.readLine()) != null) {
writer.add(line);
if (!line.replaceAll("\\s", "").isEmpty())
writer.add(line);
}
} catch (IOException e) {
// reader probably closed, expected exit condition
@@ -1,45 +1,9 @@
package com.topjohnwu.magisk.utils;
import android.os.AsyncTask;
import com.topjohnwu.magisk.module.Module;
import java.util.ArrayList;
import java.util.List;
public class Utils {
public static Init initialize;
public static List<Module> listModules = new ArrayList<>();
public static List<Module> listModulesCache = new ArrayList<>();
public static List<String> listLog;
public static class Init extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
Shell.startRoot();
listModules.clear();
listModulesCache.clear();
List<String> magisk = getModList("/magisk");
List<String> magiskCache = getModList("/cache/magisk");
if (!magisk.isEmpty()) {
for (String mod : magisk) {
listModules.add(new Module(mod));
}
}
if (!magiskCache.isEmpty()) {
for (String mod : magiskCache) {
listModulesCache.add(new Module(mod));
}
}
listLog = readFile("/cache/magisk.log");
return null;
}
}
public static boolean fileExist(String path) {
List<String> ret;
ret = Shell.sh("if [ -f " + path + " ]; then echo true; else echo false; fi");