diff --git a/plugin.xml b/plugin.xml index 59d05b0..f598f81 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + secureDevice Stops app from running if device is not secure, i.e. it is jailbroken, rooted, or doesn't have a passcode set. André Vieira diff --git a/src/android/secureDevice.java b/src/android/secureDevice.java index 034c2fa..a9fd6cd 100644 --- a/src/android/secureDevice.java +++ b/src/android/secureDevice.java @@ -28,6 +28,8 @@ import java.lang.Exception; import java.io.File; +import java.io.BufferedReader; +import java.io.InputStreamReader; import android.annotation.SuppressLint; import android.app.Activity; @@ -87,32 +89,38 @@ private void checkDevice() { } } - /** - * Detect weather device is rooted or not - * @author trykov - * @source https://github.com/trykovyura/cordova-plugin-root-detection - */ - private boolean isDeviceRooted() { - return checkBuildTags() || checkSuperUserApk() || checkFilePath(); + public static boolean isDeviceRooted() { + return checkRootMethod1() || checkRootMethod2() || checkRootMethod3(); } - private boolean checkBuildTags() { + + private static boolean checkRootMethod1() { String buildTags = android.os.Build.TAGS; return buildTags != null && buildTags.contains("test-keys"); } - private boolean checkSuperUserApk() { - return new File("/system/app/Superuser.apk").exists(); - } - - private boolean checkFilePath() { - String[] paths = { "/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" }; + private static boolean checkRootMethod2() { + String[] paths = { "/system/app/Superuser.apk", "/system/app/SuperSU.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", "/su/bin/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())); + if (in.readLine() != null) return true; + return false; + } catch (Throwable t) { + return false; + } finally { + if (process != null) process.destroy(); + } + } + /**