原文地址:[FAQ202072305]android10.0 user版本下开启adb root权限方法


[QUESTION]

有些客户问题须要开启开发这模式,打开usb debug调试方式,并在user版本下打开adb root权限调查

[ANSWER]

开启adb root权限和打开adb调试方法如下:

1、开启adb root
  1. /// platform/system/core/init/selinux.cpp
  2. bool IsEnforcing() {
  3. return false;<<<-------直接返回false
  4. }
  1. /// platform/system/core/adb/daemon/main.cpp
  2. static bool should_drop_privileges() {
  3. #if defined(ALLOW_ADBD_ROOT)
  4. // The properties that affect `adb root` and `adb unroot` are ro.secure and
  5. // ro.debuggable. In this context the names don't make the expected behavior
  6. // particularly obvious.
  7. //
  8. // ro.debuggable:
  9. // Allowed to become root, but not necessarily the default. Set to 1 on
  10. // eng and userdebug builds.
  11. //
  12. // ro.secure:
  13. // Drop privileges by default. Set to 1 on userdebug and user builds.
  14. bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
  15. bool ro_debuggable = __android_log_is_debuggable();
  16. // Drop privileges if ro.secure is set...
  17. bool drop = ro_secure;
  18. // ... except "adb root" lets you keep privileges in a debuggable build.
  19. std::string prop = android::base::GetProperty("service.adb.root", "");
  20. bool adb_root = (prop == "1");
  21. bool adb_unroot = (prop == "0");
  22. if (ro_debuggable && adb_root) {
  23. drop = false;
  24. }
  25. // ... and "adb unroot" lets you explicitly drop privileges.
  26. if (adb_unroot) {
  27. drop = true;
  28. }
  29. return drop;
  30. #else
  31. return false; // "adb root" not allowed, always drop privileges.<<<<<<<---------改为false
  32. #endif // ALLOW_ADBD_ROOT
  33. }

2、打开 adb 调试

user版本开启adb调试,注意python代码的缩进变化问题

  1. ### build / tools/post_process_props.py
  2. if prop.get("ro.debuggable") == "1":
  3. val = prop.get("persist.sys.usb.config")
  4. if "adb" not in val:
  5. if val == "":
  6. val = "adb"
  7. else:
  8. val = val + ",adb"
  9. prop.put("persist.sys.usb.config", val)

修改为

  1. #if prop.get("ro.debuggable") == "1":
  2. val = prop.get("persist.sys.usb.config")
  3. if "adb" not in val:
  4. if val == "":
  5. val = "adb"
  6. else:
  7. val = val + ",adb"
  8. prop.put("persist.sys.usb.config", val)