Skip to content

Commit

Permalink
Updated to version 1.0.4
Browse files Browse the repository at this point in the history
Reviewed implementation of root detection in Android.
  • Loading branch information
agmv committed May 25, 2018
1 parent 71eacc6 commit e979d7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-secure-device" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-secure-device" version="1.0.4" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>secureDevice</name>
<description>Stops app from running if device is not secure, i.e. it is jailbroken, rooted, or doesn't have a passcode set.</description>
<author>André Vieira</author>
Expand Down
38 changes: 23 additions & 15 deletions src/android/secureDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}



/**
Expand Down

0 comments on commit e979d7b

Please sign in to comment.