自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
驗證及偵錯
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要驗證及偵錯藍牙堆疊,請使用 AOSP 和藍牙技術聯盟 (SIG) 測試提供的工具。
測試及驗證
為了測試藍牙堆疊,Android 開放原始碼計畫提供單元測試、CTS 測試和藍牙設定檔調整套件的工具。
AOSP 中的單元測試
AOSP 包含預設藍牙堆疊的功能和單元測試。這些測試位於
/packages/modules/Bluetooth/system/test/
中。如要執行 AOSP 測試,請執行下列操作:
- 停止 Android 執行階段:
adb shell stop
- 如要執行特定測試或測試套件,請從測試目錄執行殼層可執行檔案,並加入選項:
./run_unit_tests.sh TEST_GROUP_NAME TEST_NAME OPTIONS
- 測試完成後,請重新啟用 Android 執行階段:
adb shell start
您可以在
/packages/modules/Bluetooth/system/test/README.md
中找到測試名稱清單。
設定檔調整套件
Bluetooth SIG 提供 Bluetooth Profile Tuning Suite (PTS),這是一項測試工具,可測試通訊協定和設定檔的互通性。詳情請參閱
Bluetooth Profile Tuning Suite 網站。
CTS 測試
Compatibility Test Suite (CTS) 包含藍牙堆疊的測試。這些檔案位於
cts/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth
中。
偵錯選項
AOSP 提供多種方法,可用於偵錯裝置的藍牙堆疊,包括記錄和錯誤報告。這些方法可能無法解決無法重現的問題,或音訊問題 (可能受到平台和裝置的多個部分影響)。
使用錯誤報告進行偵錯
如要使用 dumpsys
檢查藍牙服務狀態,請使用下列指令:
adb shell dumpsys bluetooth_manager
根據預設,所有記錄訊息的追蹤層級為 2。如要進一步瞭解記錄層級,並變更不同設定檔的記錄層級,請參閱
system/bt/conf/bt_stack.conf
。
如要從錯誤報告中擷取窺探記錄,請使用 btsnooz
指令碼。
- 取得
btsnooz.py
。
- 擷取錯誤報告的文字版本。
- 針對錯誤回報的文字版本執行
btsnooz.py
:btsnooz.py BUG_REPORT.txt > BTSNOOP.log
使用記錄檔進行偵錯
在 Android 4.4 以上版本中,您可以手動收集 BTSnoop 記錄,這些記錄類似於 RFC 1761 中的 snoop 格式。這些記錄會擷取主機控制器介面 (HCI) 封包。對於大多數 Android 裝置,記錄會儲存在 data/misc/bluetooth/logs
中。
基於隱私權考量,一律開啟的「記憶體內」BTSnoop 只會記錄非個人資訊和事件。如要記錄所有資料,使用者必須按照下列步驟啟用藍牙 HCI 窺探功能:
- 在裝置上啟用開發人員選項。
- 在「開發人員選項」選單中,啟用「啟用藍牙 HCI 窺探記錄」切換鈕。
- 重新啟動藍牙,讓記錄功能生效。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-06-26 (世界標準時間)。
[null,null,["上次更新時間:2025-06-26 (世界標準時間)。"],[],[],null,["# Verify and debug\n\nTo verify and debug the Bluetooth stack, use the tools provided in\nAOSP and the Bluetooth Special Interest Group's (SIG) tests.\n\nTest and verify\n---------------\n\nTo test the Bluetooth stack, AOSP provides a mix of unit tests,\nCTS tests, and tools for the Bluetooth Profile Tuning Suite.\n\n### Unit tests in AOSP\n\nAOSP includes functional and unit tests for the default\nBluetooth stack. These 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 ```\n adb shell stop\n ```\n2. From the test directory, run the shell executable file and include options if you want to run a specific test or test suite: \n\n ```\n ./run_unit_tests.sh TEST_GROUP_NAME TEST_NAME OPTIONS\n ```\n3. When the tests finish, re-enable the Android runtime: \n\n ```\n adb shell start\n ```\n\nThe list of test names can be found in [/packages/modules/Bluetooth/system/test/README.md](https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/system/test/README.md).\n\n### Profile Tuning Suite\n\nThe Bluetooth SIG provides the Bluetooth Profile Tuning Suite (PTS),\na testing tool for protocol and profile interoperability.\nFor more information, see the [Bluetooth Profile Tuning Suite](https://www.bluetooth.com/develop-with-bluetooth/test-tools/profile-tuning-suite) site.\n\n### CTS tests\n\n\nThe [Compatibility Test Suite](/docs/compatibility/cts) (CTS)\nincludes tests for the Bluetooth stack. These are located in [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-----------------\n\nAOSP provides different methods of debugging a device's\nBluetooth stack, including logs and bug reports. These methods may\nnot work for issues that cannot be reproduced or for audio issues,\nwhich can be affected by multiple parts of the platform and device.\n\n### Debugging with bug reports\n\nTo check the Bluetooth service status using `dumpsys`,\nuse the following command: \n\n```\nadb shell dumpsys bluetooth_manager\n```\n\nBy default, all log messages are trace level 2.\nTo find out more about the logging levels and change the logging levels\nfor different profiles, look 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\n`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).\n2. Extract the text version of the bug report.\n3. Run `btsnooz.py` on the text version of the bug report: \n\n ```\n btsnooz.py BUG_REPORT.txt \u003e BTSNOOP.log\n ```\n\n### Debugging with logs\n\nIn Android 4.4 and later, you can manually collect BTSnoop logs,\nwhich resemble the snoop format in RFC 1761. These logs capture the\nHost Controller Interface (HCI) packets.\nFor most Android devices, the logs are stored in\n`data/misc/bluetooth/logs`.\n\nFor privacy reasons, always-on, \"in-memory\" BTSnoop only logs\nnon-personal information and events. To log all data, the user needs\nto enable Bluetooth HCI snoop by doing the following:\n\n1. Enable **Developer options** on the device.\n2. In the **Developer options** menu, activate the **Enable Bluetooth HCI snoop log** toggle.\n3. Restart Bluetooth for logging to take effect."]]