mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 10:35:26 +00:00
Root shell workaround
This commit is contained in:
parent
727294fbbe
commit
4c230d9e61
@ -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];
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user