当前位置:   article > 正文

android 检测手机是否被Root_如何检查手机是否root

如何检查手机是否root
  1. import android.text.TextUtils;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.InputStreamReader;
  5. /**
  6. * 使用 boolean isRoot = PACheckSysUtils.isRoot();
  7. * 检测手机是否被Root
  8. */
  9. public class CheckSysUtils {
  10. private static final String TAG = "PACheckSysUtils";
  11. /**
  12. * 检测是否root
  13. * modify by hiyi 20180928,移除雁联SDK的root检测,重新开发
  14. *
  15. * @param
  16. * @return
  17. */
  18. public static boolean isRoot() {
  19. String[] paths = {
  20. "/system/xbin/su",
  21. "/system/bin/su",
  22. "/system/sbin/su",
  23. "/sbin/su",
  24. "/vendor/bin/su",
  25. "/su/bin/su"
  26. };
  27. try {
  28. for (String path : paths) {
  29. if (new File(path).exists()) {
  30. String execResult = exec(new String[]{"ls", "-l", path});
  31. Log.d(TAG, "isRooted = " + execResult);
  32. //形如(rooted):-rwxr-xr-x root root 75348 1970-01-01 08:32 su
  33. if (TextUtils.isEmpty(execResult)
  34. || execResult.indexOf("root") == execResult.lastIndexOf("root")) {
  35. return false;
  36. }
  37. return true;
  38. }
  39. }
  40. } catch (Exception e) {
  41. e.printStackTrace();
  42. }
  43. return false;
  44. }
  45. private static String exec(String[] exec) {
  46. if (exec == null || exec.length <= 0) {
  47. return null;
  48. }
  49. StringBuilder ret = new StringBuilder();
  50. ProcessBuilder processBuilder = new ProcessBuilder(exec);
  51. try {
  52. Process process = processBuilder.start();
  53. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
  54. String line;
  55. while ((line = bufferedReader.readLine()) != null) {
  56. ret.append(line);
  57. }
  58. process.getInputStream().close();
  59. process.destroy();
  60. } catch (Exception e) {
  61. e.printStackTrace();
  62. }
  63. return ret.toString();
  64. }
  65. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/904170
推荐阅读
相关标签
  

闽ICP备14008679号