Root shell workaround

This commit is contained in:
topjohnwu 2017-09-05 04:07:33 +08:00
parent 727294fbbe
commit 4c230d9e61
2 changed files with 37 additions and 11 deletions

View File

@ -154,8 +154,16 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
mList.add("- Use boot image: " + boot);
Shell shell;
if (mode == PATCH_MODE && Shell.rootAccess()) {
// Force non-root shell
shell = Shell.getShell("sh");
} else {
shell = getShell();
}
// Patch boot image
getShell().sh(mList,
shell.sh(mList,
"cd " + install,
"KEEPFORCEENCRYPT=" + mKeepEnc + " KEEPVERITY=" + mKeepVerity + " sh " +
"update-binary indep boot_patch.sh " + boot + " 2>&1" +
@ -176,16 +184,6 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
getShell().sh_raw("cp -f " + patched_boot + " " + dest);
break;
case ".img.tar":
// Workaround root shell issues so we can access the file through Java
if (Shell.rootAccess()) {
// Get non-root UID
int uid = mm.getApplicationInfo().uid;
// Get app selabel
String selabel = getShell().su("/system/bin/ls -dZ " + install + " | cut -d' ' -f1").get(0);
getShell().su(
"chcon " + selabel + " " + patched_boot,
"chown " + uid + "." + uid + " " + patched_boot);
}
TarOutputStream tar = new TarOutputStream(new BufferedOutputStream(new FileOutputStream(dest)));
tar.putNextEntry(new TarEntry(patched_boot, "boot.img"));
byte buffer[] = new byte[4096];

View File

@ -87,10 +87,38 @@ public class Shell {
sh_raw("umask 022");
}
private Shell(String command) {
Process process;
DataOutputStream in;
DataInputStream out;
try {
process = Runtime.getRuntime().exec(command);
in = new DataOutputStream(process.getOutputStream());
out = new DataInputStream(process.getInputStream());
} catch (IOException e) {
// Nothing works....
shellProcess = null;
STDIN = null;
STDOUT = null;
isValid = false;
return;
}
isValid = true;
shellProcess = process;
STDIN = in;
STDOUT = out;
}
public static Shell getShell() {
return new Shell();
}
public static Shell getShell(String command) {
return new Shell(command);
}
public static Shell getShell(Context context) {
MagiskManager magiskManager = Utils.getMagiskManager(context);
if (magiskManager.shell == null || !magiskManager.shell.isValid) {