Android系统默认开启adb root模式

需求描述

将adb root模式默认开启

解决方案

system/core/adb/daemon/main.cpp

复制代码
static bool should_drop_privileges() {
#if defined(ALLOW_ADBD_ROOT)
    char value[PROPERTY_VALUE_MAX];

    // 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.
    property_get("ro.secure", value, "1");
    bool ro_secure = (strcmp(value, "1") == 0);

    property_get("ro.debuggable", value, "");
    bool ro_debuggable = (strcmp(value, "1") == 0);

    // Drop privileges if ro.secure is set...
    bool drop = ro_secure;

    property_get("service.adb.root", value, "");
    bool adb_root = (strcmp(value, "1") == 0);
    bool adb_unroot = (strcmp(value, "0") == 0);

    // ... except "adb root" lets you keep privileges in a debuggable build.
    if (ro_debuggable && adb_root) {
        drop = false;
    }

    // ... and "adb unroot" lets you explicitly drop privileges.
    if (adb_unroot) {
        drop = true;
    }

    return drop;
#else
    return true; // "adb root" not allowed, always drop privileges.
#endif // ALLOW_ADBD_ROOT
}

修改system/core/adb/daemon/main.cpp的should_drop_privileges()方法返回为false

修改build/core/main.mk,使ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0

添加属性device/qcom/msm8953_64/system.prop,该属性会编译到root/default.prop

复制代码
ro.secure=0
ro.adb.secure=0
ro.duebuggbale=1
相关推荐
私人珍藏库1 小时前
【Android】BotHub-多模型AI机器人聚合库-内置免费模型
android·人工智能·智能手机·app·工具·多功能
普马萨特1 小时前
Wi-Fi 扫描频率限制与 Android 演进全解析
android
张拭心2 小时前
Android 17 新特性:后台音频交互限制加强
android·前端
张拭心2 小时前
Android 17 新特性:ProfilingManager 新触发器
android·前端
张拭心2 小时前
Android 17 新特性:MessageQueue 无锁实现
android·前端
brycegao2 小时前
如何搭建标准化 Git 工具流,保障 Android 团队代码质量
android·ci/cd
AI科技星2 小时前
数术江湖·全卷合集 - 硬核江湖・数理史诗
android·人工智能·架构·概率论·学习方法
五月君_2 小时前
安卓也支持了!微信链接 Claude Code 保姆级教程
android·微信
柚鸥ASO优化2 小时前
一篇讲透安卓ASO!开发者千万别只盯着iOS了
android·ios·aso优化
木易 士心2 小时前
compileSdkVersion、minSdkVersion 和 targetSdkVersion —— Android 三个核心的 SDK 版本配置
android