mirror of
https://github.com/status-im/status-react.git
synced 2025-02-06 16:14:52 +00:00
android: kotlinify root util (#21877)
This commit is contained in:
parent
4654c4a543
commit
2a95f7cfac
@ -1,40 +0,0 @@
|
||||
package im.status.ethereum;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/** @author Kevin Kowalewski */
|
||||
public class RootUtil {
|
||||
|
||||
public static boolean isDeviceRooted() {
|
||||
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
|
||||
}
|
||||
|
||||
private static boolean checkRootMethod1() {
|
||||
String buildTags = android.os.Build.TAGS;
|
||||
return buildTags != null && buildTags.contains("test-keys");
|
||||
}
|
||||
|
||||
private static boolean checkRootMethod2() {
|
||||
String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
|
||||
"/system/bin/failsafe/su", "/data/local/su" };
|
||||
for (String path : paths) {
|
||||
if (new File(path).exists()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean checkRootMethod3() {
|
||||
Process process = null;
|
||||
try {
|
||||
process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
return in.readLine() != null;
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
} finally {
|
||||
if (process != null) process.destroy();
|
||||
}
|
||||
}
|
||||
}
|
42
android/app/src/main/java/im/status/ethereum/RootUtil.kt
Normal file
42
android/app/src/main/java/im/status/ethereum/RootUtil.kt
Normal file
@ -0,0 +1,42 @@
|
||||
package im.status.ethereum
|
||||
|
||||
import android.os.Build
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.InputStreamReader
|
||||
|
||||
object RootUtil {
|
||||
|
||||
fun isDeviceRooted(): Boolean =
|
||||
checkRootMethod1() || checkRootMethod2() || checkRootMethod3()
|
||||
|
||||
private fun checkRootMethod1(): Boolean =
|
||||
Build.TAGS?.contains("test-keys") ?: false
|
||||
|
||||
private fun checkRootMethod2(): Boolean {
|
||||
val paths = arrayOf(
|
||||
"/system/app/Superuser.apk",
|
||||
"/sbin/su",
|
||||
"/system/bin/su",
|
||||
"/system/xbin/su",
|
||||
"/data/local/xbin/su",
|
||||
"/data/local/bin/su",
|
||||
"/system/sd/xbin/su",
|
||||
"/system/bin/failsafe/su",
|
||||
"/data/local/su"
|
||||
)
|
||||
return paths.any { File(it).exists() }
|
||||
}
|
||||
|
||||
private fun checkRootMethod3(): Boolean {
|
||||
var process: Process? = null
|
||||
return try {
|
||||
process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su"))
|
||||
BufferedReader(InputStreamReader(process.inputStream)).readLine() != null
|
||||
} catch (t: Throwable) {
|
||||
false
|
||||
} finally {
|
||||
process?.destroy()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user