init commit

This commit is contained in:
trykov
2015-06-10 23:55:45 +04:00
committed by Trykov Yura
parent 8125c775b7
commit 894e50d635
3 changed files with 85 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-root-detection" version="0.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>Root Detection</name>
<author>Yury Trykov (http://trykov.ru/)</author>
<description>Cordova Plugin for detecting if the device running the app is rooted.</description>
<keywords>cordova, detection, detector, root, rooted</keywords>
<license>MIT</license>
<repo>https://github.com/trykovyura/cordova-plugin-root-detection</repo>
<issue>https://github.com/trykovyura/cordova-plugin-root-detection/issues</issue>
<engines>
<engine name="cordova" version="&gt;=3.0.0"/>
</engines>
<js-module name="RootDetection" src="www/rootdetection.js">
<clobbers target="rootdetection"/>
</js-module>
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="RootDetection">
<param name="android-package" value="ru.trykov.root.RootDetection"/>
</feature>
</config-file>
<config-file parent="/*" target="AndroidManifest.xml"></config-file>
<source-file src="src/android/RootDetection.java" target-dir="src/ru/trykov/root"/>
</platform>
</plugin>
+54
View File
@@ -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;
}
}
+5
View File
@@ -0,0 +1,5 @@
var exec = require('cordova/exec');
exports.isDeviceRooted = function(arg0, success, error) {
exec(success, error, "RootDetection", "isDeviceRooted", [arg0]);
};