原文地址:[FAQ202072305]android10.0 user版本下开启adb root权限方法
[QUESTION]
有些客户问题须要开启开发这模式,打开usb debug调试方式,并在user版本下打开adb root权限调查
[ANSWER]
1、开启adb root
/// platform/system/core/init/selinux.cpp
bool IsEnforcing() {
return false;<<<-------直接返回false
}
/// platform/system/core/adb/daemon/main.cpp
static bool should_drop_privileges() {
#if defined(ALLOW_ADBD_ROOT)
// The properties that affect `adb root` and `adb unroot` are ro.secure and
// ro.debuggable. In this context the names don't make the expected behavior
// particularly obvious.
//
// ro.debuggable:
// Allowed to become root, but not necessarily the default. Set to 1 on
// eng and userdebug builds.
//
// ro.secure:
// Drop privileges by default. Set to 1 on userdebug and user builds.
bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
bool ro_debuggable = __android_log_is_debuggable();
// Drop privileges if ro.secure is set...
bool drop = ro_secure;
// ... except "adb root" lets you keep privileges in a debuggable build.
std::string prop = android::base::GetProperty("service.adb.root", "");
bool adb_root = (prop == "1");
bool adb_unroot = (prop == "0");
if (ro_debuggable && adb_root) {
drop = false;
}
// ... and "adb unroot" lets you explicitly drop privileges.
if (adb_unroot) {
drop = true;
}
return drop;
#else
return false; // "adb root" not allowed, always drop privileges.<<<<<<<---------改为false
#endif // ALLOW_ADBD_ROOT
}
2、打开 adb 调试
user版本开启adb调试,注意python代码的缩进变化问题。
### build / tools/post_process_props.py
if prop.get("ro.debuggable") == "1":
val = prop.get("persist.sys.usb.config")
if "adb" not in val:
if val == "":
val = "adb"
else:
val = val + ",adb"
prop.put("persist.sys.usb.config", val)
修改为
#if prop.get("ro.debuggable") == "1":
val = prop.get("persist.sys.usb.config")
if "adb" not in val:
if val == "":
val = "adb"
else:
val = val + ",adb"
prop.put("persist.sys.usb.config", val)