当前位置: 首页 > news >正文

Android adb自身调试log开关

本文介绍下如何打开adb源码中的debug log

1.adb源码log是可以动态打开和关闭的,控制逻辑代码如下

static NoDestructor<std::mutex> log_mutex;
static NoDestructor<CachedProperty> log_property GUARDED_BY(log_mutex)("debug.adbd.logging");
static std::optional<LogStatus> cached_log_status GUARDED_BY(log_mutex);

static NoDestructor<CachedProperty> persist_log_property
        GUARDED_BY(log_mutex)("persist.debug.adbd.logging");
static std::optional<LogStatus> cached_persist_log_status GUARDED_BY(log_mutex);

static LogStatus ParseLogStatus(std::string_view str) {
    LogStatus result = {};
    for (const auto& part : android::base::Split(std::string(str), ",")) {
        if (part == "cnxn") {
            result[adb::LogType::Connection] = true;
        } else if (part == "service") {
            result[adb::LogType::Service] = true;
        } else if (part == "shell") {
            result[adb::LogType::Shell] = true;
        } else if (part == "all") {
            result[adb::LogType::Connection] = true;
            result[adb::LogType::Service] = true;
            result[adb::LogType::Shell] = true;
        }
    }
    return result;
}

static LogStatus GetLogStatus(android::base::CachedProperty* property,
                              std::optional<LogStatus>* cached_status) REQUIRES(log_mutex) {
    bool changed;
    const char* value = property->Get(&changed);
    if (changed || !*cached_status) {
        **cached_status = ParseLogStatus(value);
    }
    return **cached_status;
}

namespace adb {
bool is_logging_enabled(LogType type) {
    std::lock_guard<std::mutex> lock(*log_mutex);
    return GetLogStatus(log_property.get(), &cached_log_status)[type] ||
           GetLogStatus(persist_log_property.get(), &cached_persist_log_status)[type];
}
}  // namespace adb

2.配置方法

adb shell  setprop persist.debug.adbd.logging  service   //打开LogType为service的log

例如:

daemon/services.cpp:262:    ADB_LOG(Service) << "transport " << transport->serial_name() << " opening service " << name;

打开后执行adb remount,可以抓到如下log

I adbd    : transport UsbFfs opening service shell,v2,TERM=xterm-256color,raw:remount

 adb shell  setprop persist.debug.adbd.logging all    //打开所有logtype

3.打开adb trace log方法

adb shell setprop persist.adb.trace_mask 1
adb shell pkill adbd   //需要重启adbd 生效

trace log会保存在/data/adb/文件夹下

相关文章:

  • HashMap的位操作是什么?HashSet 的 contains 方法复杂度是多少?红黑树简单讲一下?
  • 基于Ebay拍卖网站成交价格的影响因素分析
  • 【TI MSPM0】PWM学习
  • Android 12.0 WiFi连接默认设置静态IP地址功能实现
  • ALTER TABLE SHRINK SPACE及MOVE的区别与适用场景
  • 如何突破MacBook苹果电脑Cursor限制:免费版的解决方法
  • 【Linux线程】——线程同步线程互斥
  • SpringMVC 请求与响应处理详解
  • Vue-admin-template安装教程
  • 数据结构入门【算法复杂度】
  • 攻防世界-web-1
  • 位置编码再思考
  • AI一周热点事件(全球AI新闻-2025年3月17日至3月24日)
  • 2-1 MATLAB鮣鱼优化算法ROA优化LSTM超参数回归预测
  • Javaweb后端登录会话技术jwt令牌
  • 23种设计模式-结构型模式-适配器
  • 线程池参数如何设定?如何动态调整线程池?
  • 字符串交替合并问题
  • Mysql内置函数篇
  • 【Golang】第八弹----面向对象编程
  • 绵阳的网站建设/百度seo优化技巧
  • 连接品硕网线做怎么弹网站/全网引流推广
  • 企业网站seo多少钱/网站建设设计
  • 中小企业网站开发/专业网络推广公司排名
  • 专业模板建站服务/全网营销推广平台
  • 比较好用的免费素材网/郑州seo外包服务