mirror of
https://github.com/topjohnwu/libsu.git
synced 2024-11-23 03:59:43 +00:00
Do not readlink /proc/self/exe
Old platforms prevent `readlink /proc/self/exe` from being called from non-main threads on release builds https://stackoverflow.com/questions/28590831/android-permission-denied-when-reading-proc-self-exe-from-non-main-thread
This commit is contained in:
parent
9cb4862248
commit
9043cd5c46
@ -32,6 +32,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -180,4 +181,24 @@ public final class Utils {
|
||||
public static boolean isMainShellRoot() {
|
||||
return MainShell.get().isRoot();
|
||||
}
|
||||
|
||||
@SuppressLint("DiscouragedPrivateApi")
|
||||
public static boolean isProcess64Bit() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return Process.is64Bit();
|
||||
}
|
||||
try {
|
||||
Class<?> classVMRuntime = Class.forName("dalvik.system.VMRuntime");
|
||||
Method getRuntime = classVMRuntime.getDeclaredMethod("getRuntime");
|
||||
getRuntime.setAccessible(true);
|
||||
Object runtime = getRuntime.invoke(null);
|
||||
Method is64Bit = classVMRuntime.getDeclaredMethod("is64Bit");
|
||||
is64Bit.setAccessible(true);
|
||||
// noinspection ConstantConditions
|
||||
return (boolean) is64Bit.invoke(runtime);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
err(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,8 @@ public class RootServiceManager implements Handler.Callback {
|
||||
break;
|
||||
}
|
||||
|
||||
String app_process = new File("/proc/self/exe").getCanonicalPath();
|
||||
// We cannot readlink /proc/self/exe on old kernels
|
||||
String app_process = "/system/bin/app_process" + (Utils.isProcess64Bit() ? "64" : "32");
|
||||
String cmd = String.format(Locale.ROOT,
|
||||
"(%s CLASSPATH=%s %s %s /system/bin %s " +
|
||||
"com.topjohnwu.superuser.internal.RootServerMain '%s' %d %s >/dev/null 2>&1)&",
|
||||
|
Loading…
Reference in New Issue
Block a user