├── LICENSE ├── README.md ├── package.json ├── plugin.xml ├── src └── android │ └── RootDetection.java └── www └── rootdetection.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 trykovyura 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Root Detection Plugin for Apache Cordova 2 | 3 | Use this plugin to check if the android device running the app is rooted. 4 | 5 | 6 | ## Install 7 | 8 | ### Locally 9 | 10 | ``` 11 | cordova plugin add cordova-plugin-root-detection 12 | ``` 13 | 14 | or 15 | 16 | ``` 17 | cordova plugin add https://github.com/trykovyura/cordova-plugin-root-detection.git 18 | ``` 19 | 20 | ## Usage 21 | 22 | ### isDeviceRooted 23 | 24 | ```js 25 | rootdetection.isDeviceRooted(successCallback, errorCallback); 26 | ``` 27 | 28 | - => `successCallback` is called with true if the device is rooted, otherwise false 29 | - => `errorCallback` is called if there was an error determining if the device is rooted 30 | - returns '1' if device is rooted else '0' 31 | 32 | ### Example 33 | ```js 34 | var successCallback = function (result) { 35 | var isDevicesRooted = result == 1; 36 | }; 37 | var errorCallback = function (error) { 38 | console.error(error); 39 | }; 40 | rootdetection.isDeviceRooted(successCallback, errorCallback); 41 | ``` 42 | 43 | ## Platform Support 44 | 45 | Android only. 46 | 47 | ## License 48 | 49 | MIT License 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-root-detection", 3 | "version": "0.1.1", 4 | "description": "Cordova Plugin for detecting if the device running the app is rooted.", 5 | "cordova": { 6 | "id": "cordova-plugin-root-detection", 7 | "platforms": [ 8 | "android" 9 | ] 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/trykovyura/cordova-plugin-root-detection.git" 14 | }, 15 | "keywords": [ 16 | "cordova", 17 | "detection", 18 | "detector", 19 | "root", 20 | "rooted", 21 | "ecosystem:cordova", 22 | "cordova-android" 23 | ], 24 | "engines": [ 25 | { 26 | "name": "cordova", 27 | "version": ">=3.0.0" 28 | } 29 | ], 30 | "author": "Yury Trykov (http://trykov.ru/)", 31 | "license": "MIT", 32 | "bugs": { 33 | "url": "https://github.com/trykovyura/cordova-plugin-root-detection/issues" 34 | }, 35 | "homepage": "https://github.com/trykovyura/cordova-plugin-root-detection#readme" 36 | } 37 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | Root Detection 5 | Yury Trykov (http://trykov.ru/) 6 | Cordova Plugin for detecting if the device running the app is rooted. 7 | cordova, detection, detector, root, rooted 8 | MIT 9 | https://github.com/trykovyura/cordova-plugin-root-detection 10 | https://github.com/trykovyura/cordova-plugin-root-detection/issues 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/android/RootDetection.java: -------------------------------------------------------------------------------- 1 | package ru.trykov.root; 2 | 3 | import org.apache.cordova.CordovaPlugin; 4 | import org.apache.cordova.CallbackContext; 5 | 6 | import org.json.JSONArray; 7 | import org.json.JSONException; 8 | import org.json.JSONObject; 9 | 10 | import java.lang.Exception; 11 | import java.io.File; 12 | 13 | /** 14 | * Detect weather device is rooted or not 15 | * @author trykov 16 | */ 17 | public class RootDetection extends CordovaPlugin { 18 | 19 | @Override 20 | public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { 21 | if (action.equals("isDeviceRooted")) { 22 | try { 23 | callbackContext.success(isDeviceRooted() ? 1 : 0); 24 | return true; 25 | } catch (Exception e) { 26 | callbackContext.error("N/A"); 27 | return false; 28 | } 29 | } 30 | return false; 31 | } 32 | 33 | private boolean isDeviceRooted() { 34 | return checkBuildTags() || checkSuperUserApk() || checkFilePath(); 35 | } 36 | private boolean checkBuildTags() { 37 | String buildTags = android.os.Build.TAGS; 38 | return buildTags != null && buildTags.contains("test-keys"); 39 | } 40 | 41 | private boolean checkSuperUserApk() { 42 | return new File("/system/app/Superuser.apk").exists(); 43 | } 44 | 45 | private boolean checkFilePath() { 46 | String[] paths = { "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", 47 | "/system/bin/failsafe/su", "/data/local/su" }; 48 | for (String path : paths) { 49 | if (new File(path).exists()) return true; 50 | } 51 | return false; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /www/rootdetection.js: -------------------------------------------------------------------------------- 1 | var exec = require('cordova/exec'); 2 | 3 | exports.isDeviceRooted = function(success, error) { 4 | exec(success, error, "RootDetection", "isDeviceRooted", []); 5 | }; 6 | --------------------------------------------------------------------------------