自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
验证和调试
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需验证和调试蓝牙堆栈,请使用 AOSP 中提供的工具以及蓝牙技术联盟 (SIG) 的测试。
测试和验证
为了测试蓝牙堆栈,AOSP 提供了一系列单元测试、CTS 测试,以及旨在辅助 Bluetooth Profile Tuning Suite 的工具。
AOSP 中的单元测试
AOSP 包括针对默认蓝牙堆栈的功能测试和单元测试。这些测试位于
/packages/modules/Bluetooth/system/test/
中。如需运行 AOSP 测试,请执行以下操作:
- 停止 Android 运行时:
adb shell stop
- 从测试目录中运行 shell 可执行文件,如果要运行特定测试或测试套件,请包含相应选项:
./run_unit_tests.sh TEST_GROUP_NAME TEST_NAME OPTIONS
- 测试完成后,重新启用 Android 运行时:
adb shell start
您可以在
/packages/modules/Bluetooth/system/test/README.md
中找到测试名称列表。
Profile Tuning Suite
Bluetooth SIG 提供了 Bluetooth Profile Tuning Suite (PTS),这是一种用于测试协议和配置文件互操作性的工具。如需更多信息,请访问 Bluetooth Profile Tuning Suite 网站。
CTS 测试
兼容性测试套件 (CTS) 包括针对蓝牙堆栈的测试。这些测试位于以下位置:
cts/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth
。
调试选项
AOSP 提供了多种调试设备蓝牙堆栈的方法,其中包括日志和 bug 报告。这些方法可能不适用于无法再现的问题或可能受平台和设备的多个部分影响的音频问题。
使用错误报告进行调试
如需使用 dumpsys
检查蓝牙服务状态,请使用以下命令:
adb shell dumpsys bluetooth_manager
默认情况下,所有日志消息的跟踪级别均为 2。如需详细了解日志记录级别,并更改不同配置文件的日志记录级别,请查看
system/bt/conf/bt_stack.conf
。
如需从 bug 报告中提取信息收集日志,请使用 btsnooz
脚本。
- 获取
btsnooz.py
。
- 提取 bug 报告的文本版本。
- 对 bug 报告的文本版本运行
btsnooz.py
:
btsnooz.py BUG_REPORT.txt > BTSNOOP.log
使用日志进行调试
在 Android 4.4 及更高版本中,您可以手动收集 BTSnoop 日志(类似于 RFC 1761 中的信息收集格式)。这些日志可捕获主机控制器接口 (HCI) 数据包。对于大多数 Android 设备,这些日志都存储在 data/misc/bluetooth/logs
中。
出于保护隐私方面的考虑,始终处于开启状态且位于“内存中”的 BTSnoop 仅会记录非个人信息和事件。要记录所有数据,用户需要通过执行以下操作来启用蓝牙 HCI 信息收集:
- 启用设备上的开发者选项。
- 在开发者选项菜单中,打开启用蓝牙 HCI 信息收集日志开关。
- 重新启动蓝牙以使日志记录功能生效。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["To verify and debug the Bluetooth stack, use the tools provided in AOSP\nand the Bluetooth Special Interest Group's (SIG) tests.\n\nTest and verify\n\nTo test the Bluetooth stack, AOSP provides a mix of unit tests, CTS tests,\nand tools for the Bluetooth Profile Tuning Suite (PTS).\n\nUnit tests in AOSP\n\nAOSP includes functional and unit tests for the default Bluetooth stack.\nThese tests are located in [`/packages/modules/Bluetooth/system/test/`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Bluetooth/system/test/).\nTo run the AOSP tests, do the following:\n\n1. Stop the Android runtime:\n\n adb shell stop\n\n2. From the test directory, run the shell executable file and include\n options if you want to run a specific test or test suite:\n\n ./run_unit_tests.sh \u003cvar translate=\"no\"\u003eTEST_GROUP_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eTEST_NAME\u003c/var\u003e \u003cvar translate=\"no\"\u003eOPTIONS\u003c/var\u003e\n\n3. When the tests finish, re-enable the Android runtime:\n\n adb shell start\n\nThe list of test names can be found in\n[`/packages/modules/Bluetooth/system/test/README.md`](https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/system/test/README.md).\n\nProfile Tuning Suite\n\nThe Bluetooth SIG provides the Bluetooth PTS, a\ntesting tool for protocol and profile interoperability. For more\ninformation, see the [Bluetooth Profile Tuning Suite](https://www.bluetooth.com/develop-with-bluetooth/test-tools/profile-tuning-suite)\nsite.\n\nCTS tests\n\nThe [Compatibility Test Suite](/docs/compatibility/cts) (CTS) includes\ntests for the Bluetooth stack. These are located in\n[`cts/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth).\n\nDebugging options\n\nAOSP provides different methods of debugging a device's Bluetooth stack,\nincluding logs and bug reports. These methods may not work for issues that\ncannot be reproduced or for audio issues, which can be affected by multiple\nparts of the platform and device.\n\nDebugging with bug reports\n\nTo check the Bluetooth service status using `dumpsys`, use the following\ncommand: \n\n adb shell dumpsys bluetooth_manager\n\nBy default, all log messages are trace level 2. To find out more about\nthe logging levels and change the logging levels for different profiles,\nlook in [`system/bt/conf/bt_stack.conf`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Bluetooth/system/conf/bt_stack.conf).\n\nTo extract snoop logs from the bug report, use the `btsnooz` script.\n\n1. Get [`btsnooz.py`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Bluetooth/system/tools/scripts/btsnooz.py).\n\n2. Extract the text version of the bug report.\n\n3. Run `btsnooz.py` on the text version of the bug report:\n\n btsnooz.py BUG_REPORT.txt \u003e BTSNOOP.log\n\nDebugging with logs\n\nIn Android 4.4 and later, you can manually collect BTSnoop logs, which\nresemble the snoop format in [RFC 1761](https://www.rfc-editor.org/rfc/rfc1761). These logs capture the Host\nController Interface (HCI) packets. For most Android devices, the logs are\nstored in `data/misc/bluetooth/logs`.\n\nFor privacy reasons, always-on, \"in-memory\" BTSnoop only logs non-personal\ninformation and events. To log all data, the user needs to enable\nBluetooth HCI snoop by doing the following:\n\n1. Enable **Developer options** on the device.\n\n2. In the **Developer options** menu, activate the **Enable Bluetooth\n HCI snoop log** toggle.\n\n3. Restart Bluetooth for logging to take effect."]]