Android如何判断系统是否已经被Root
前言App检测Android系统是否已经Root的几种方法1 判断系统内是否包含 su2 判断系统内是否包含 busybox3. 检测系统内是否安装了Superuser.apk之类的App4. 检测系统是否为测试版5. 检测系统挂载目录权限前言
实体手机的Root本文不讨论,只讨论Android模拟器的Root问题。在Android模拟器上运行的APP有时会提示:“设备已Root,使用软件可能存在安全风险”本文分析在Android模拟器系统中如何解决这个问题。App检测Android系统是否已经Root的几种方法
1 判断系统内是否包含 su
/*** 是否存在su命令,并且有执行权限** @return 存在su命令,并且有执行权限返回true*/public static boolean isSuEnable() {File file = null;String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};try {for (String path : paths) {file = new File(path + "su");if (file.exists() && file.canExecute()) {Log.i(TAG, "find su in : " + path);return true;}}} catch (Exception x) {x.printStackTrace();}return false;}
2 判断系统内是否包含 busybox
/*** 是否存在busybox命令,并且有执行权限** @return 存在busybox命令,并且有执行权限返回true*/public static boolean isSuEnable() {File file = null;String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};try {for (String path : paths) {file = new File(path + "busybox");if (file.exists() && file.canExecute()) {Log.i(TAG, "find su in : " + path);return true;}}} catch (Exception x) {x.printStackTrace();}return false;}
3. 检测系统内是否安装了Superuser.apk之类的App
public static boolean checkSuperuserApk(){try {File file = new File("/system/app/Superuser.apk");if (file.exists()) {Log.i(LOG_TAG,"/system/app/Superuser.apk exist");return true;}} catch (Exception e) {}return false;}
4. 检测系统是否为测试版
在系统adb shell中执行:
# cat /system/build.prop | grep ro.build.tagsro.build.tags=release-keys
这个返回结果“release-keys”,代表此系统是正式发布版。
在代码中的检测方法如下:
public static boolean checkDeviceDebuggable(){String buildTags = android.os.Build.TAGS;if (buildTags != null && buildTags.contains("test-keys")) {Log.i(LOG_TAG,"buildTags="+buildTags);return true;}return false;}
若是非官方发布版,很可能是完全root的版本,存在使用风险。
5. 检测系统挂载目录权限
检测Android 沙盒目录文件或文件夹读取权限(在Android系统中,有些目录是普通用户不能访问的,例如 /data、/system、/etc 等;比如微信沙盒目录下的文件或文件夹权限是否正常)