diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..1d9df07 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,26 @@ + + + Root Detection + Yury Trykov (http://trykov.ru/) + Cordova Plugin for detecting if the device running the app is rooted. + cordova, detection, detector, root, rooted + MIT + https://github.com/trykovyura/cordova-plugin-root-detection + https://github.com/trykovyura/cordova-plugin-root-detection/issues + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/android/RootDetection.java b/src/android/RootDetection.java new file mode 100644 index 0000000..34f7011 --- /dev/null +++ b/src/android/RootDetection.java @@ -0,0 +1,54 @@ +package ru.trykov.root; + +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CallbackContext; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.lang.Exception; +import java.io.File; + +/** + * Detect weather device is rooted or not + * @author trykov + */ +public class RootDetection extends CordovaPlugin { + + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + if (action.equals("isDeviceRooted")) { + try { + callbackContext.success(isDeviceRooted() ? 1 : 0); + return true; + } catch (Exception e) { + callbackContext.error("N/A"); + return false; + } + } + return false; + } + + private boolean isDeviceRooted() { + return checkBuildTags() || checkSuperUserApk() || checkFilePath(); + } + private boolean checkBuildTags() { + 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" }; + for (String path : paths) { + if (new File(path).exists()) return true; + } + return false; + } + +} diff --git a/www/rootdetection.js b/www/rootdetection.js new file mode 100644 index 0000000..af07f6b --- /dev/null +++ b/www/rootdetection.js @@ -0,0 +1,5 @@ +var exec = require('cordova/exec'); + +exports.isDeviceRooted = function(arg0, success, error) { + exec(success, error, "RootDetection", "isDeviceRooted", [arg0]); +};