自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
攝影機偵錯
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面將說明相機服務中的偵錯工具,可用於查看傳送至相機 HAL 和從相機 HAL 傳送的擷取要求和結果值的變更。相機服務包含 watch
和 dumpsys
指令。watch
指令適用於搭載 Android 13 以上版本的裝置,可用於控管標記的監控和存取時機、從開放用戶端即時預覽標記監控傾印,以及查看從關閉用戶端快取的傾印。dumpsys
指令可讓您存取偵錯資訊,但不會提供來自已關閉用戶端的標記監控傾印。
watch 指令
本節將說明如何使用 watch
指令,並提供範例。
開始監控標記
如要開始監控代碼,請使用:
adb shell cmd media.camera watch start -m <tags> [-c <clients>]
例子:
adb shell cmd media.camera watch start \
-m android.control.effectMode,android.control.aeMode \
-c com.google.android.GoogleCamera,com.android.chrome
引數:
tags
:以逗號分隔的清單,當中列有要監控的標記。也接受簡寫 3a
,其中 3a
是指與 AF、AE 和 AWB 相關的所有 android.control.*
標記組合 (如需標記完整清單,請參閱 TagMonitor.cpp
)。
clients
:選用引數。以半形逗號分隔的用戶端套件名稱清單,用於監控代碼片段。如果未傳遞用戶端引數,或用戶端清單中含有 all
,則會監控所有用戶端。
這個指令會在已開啟的用戶端和之後開啟的任何用戶端中啟動標記監控 (直到呼叫 stop
為止)。呼叫 start
後,相機服務會在用戶端關閉時快取用戶端的標記監控傾印。
除非呼叫 start
,否則攝影機服務不會監控任何用戶端的標記,也不會快取標記監控傾印。如果 all
在 clients
參數中傳遞,攝影機服務會監控標記,並快取來自所有用戶端的監控傾印。
傾印標記監控資訊
如要傾印代碼監控資訊,請使用:
adb shell cmd media.camera watch dump
這個指令會將標記監控資訊轉儲至標準輸出內容,然後退出。它會列印自 start
(或上次 clear
) 以來已關閉的用戶端所快取的代碼監控傾印內容,以及已開啟的用戶端的最新代碼監控傾印內容。
輸出內容範例:
$ adb shell cmd media.camera watch dump
Client: com.android.chrome (active)
1:com.android.chrome f0:532642803202286ns: REQ:android.control.aeMode: [ON] output stream ids: 0
1:com.android.chrome f0:532642803202286ns: REQ:android.control.afMode: [CONTINUOUS_PICTURE] output stream ids: 0
..
Client: com.google.android.GoogleCamera (cached)
0:com.google.android.GoogleCamera f0:532601698728552ns: REQ:android.control.aeMode: [ON] output stream ids: 0 3 1 2
0:com.google.android.GoogleCamera f0:532601698728552ns: REQ:android.control.afMode: [CONTINUOUS_PICTURE] output stream ids: 2 1 3 0
0:com.google.android.GoogleCamera f0:532601698728552ns: REQ:android.control.awbMode: [AUTO] output stream ids: 0 3 1 2
...
即時預覽代碼監控資訊
如要即時預覽標記監控資訊,請使用:
adb shell cmd media.camera watch live [-n refresh_interval_ms]
例子:
adb shell cmd media.camera watch live -n 250
引數:
refresh_interval_ms
:選用引數。以毫秒為單位的間隔,用於重新整理資訊。如果未傳遞任何值,則預設為 1000。
這個指令會即時顯示代碼監控資訊。如要退出,請按下 return/enter 鍵。
輸出內容範例:
$ adb shell cmd media.camera watch live
Press return to exit...
0:com.google.android.GoogleCamera f0:533016991302201ns: REQ:android.control.aeMode: [ON] output stream ids: 1 3 0 2
0:com.google.android.GoogleCamera f0:533016991302201ns: REQ:android.control.afMode: [CONTINUOUS_PICTURE] output stream ids: 2 0 3 1
...
0:com.google.android.GoogleCamera f0:533017066793915ns: RES:android.control.aeState: [SEARCHING]
0:com.google.android.GoogleCamera f0:533017066793915ns: 3 RES:android.control.aeState: [SEARCHING]
0:com.google.android.GoogleCamera f0:533017066793915ns: 2 RES:android.control.aeState: [SEARCHING]
0:com.google.android.GoogleCamera f0:533017066793915ns: RES:android.control.afState: [PASSIVE_SCAN]
清除快取的快照
如要清除所有快取的標記監控傾印,請使用:
adb shell cmd media.camera watch clear
這個指令不會停止代碼監控。
如要停止監控所有用戶端中的標記,並清除用於快取標記監控傾印的所有緩衝區,請使用:
adb shell cmd media.camera watch stop
dumpsys 指令
dumpsys
指令會提供攝影機服務的大量偵錯資訊。下列指令會擷取相機服務的完整偵錯傾印:
adb shell dumpsys media.camera
dumpsys
指令也允許擷取來自開放用戶端的標記監控傾印。不過,dumpsys
不會提供來自已關閉用戶端的代碼監控傾印。以下是使用 dumpsys
監控代碼的範例:
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-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"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Camera debugging\n\nThis page describes the debugging tools in the camera service for viewing\nchanges in capture request and result values that are sent to and from the\ncamera HAL. The camera service includes the `watch` and the `dumpsys` commands.\nAvailable on devices running Android 13 or higher, the\n`watch` command allows control over when tags are monitored and accessed, live\npreviewing of tag monitoring dumps from open clients, and viewing of cached\ndumps from closed clients. The `dumpsys` command allows for accessing debugging\ninformation but doesn't provide tag monitoring dumps from closed clients.\n\nwatch command\n-------------\n\nThis section describes how to use the `watch` command and provides examples.\n\n### Start monitoring tags\n\nTo start monitoring tags, use: \n\n adb shell cmd media.camera watch start -m \u003ctags\u003e [-c \u003cclients\u003e]\n\nExample: \n\n adb shell cmd media.camera watch start \\\n -m android.control.effectMode,android.control.aeMode \\\n -c com.google.android.GoogleCamera,com.android.chrome\n\nArguments:\n\n- `tags`: Comma-separated list of tags to be monitored. Also accepts the shorthand `3a`, where `3a` refers to the set of all `android.control.*` tags related to AF, AE, and AWB (for the full list of tags, see [`TagMonitor.cpp`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/camera/libcameraservice/utils/TagMonitor.cpp?q=%22const%20char*%20TagMonitor::k3aTags%22)).\n- `clients`: Optional argument. Comma-separated list of client package names for which tags are monitored. Watches all clients if no client argument is passed, or if `all` is present in the list of clients.\n\nThis command starts tag monitoring in open clients and in any clients\nthat are subsequently opened (until `stop` is called). After `start` is called,\nThe camera service caches tag monitoring dumps from clients when the clients\nclose.\n\nUnless `start` is called, the camera service doesn't monitor tags for any\nclients, and doesn't cache tag monitoring dumps. If `all` is passed in the\n`clients` parameter, the camera service monitors tags and caches monitoring\ndumps from all clients.\n\n### Dump tag monitoring information\n\nTo dump tag monitoring information, use: \n\n adb shell cmd media.camera watch dump\n\nThis command dumps the tag monitoring information to standard output and then\nexits. It prints the cached tag monitoring dumps from clients that have closed\nsince `start` (or last `clear`) and the latest tag monitoring dump from open\nclients.\n\nSample output: \n\n $ adb shell cmd media.camera watch dump\n Client: com.android.chrome (active)\n 1:com.android.chrome f0:532642803202286ns: REQ:android.control.aeMode: [ON] output stream ids: 0\n 1:com.android.chrome f0:532642803202286ns: REQ:android.control.afMode: [CONTINUOUS_PICTURE] output stream ids: 0\n ..\n Client: com.google.android.GoogleCamera (cached)\n 0:com.google.android.GoogleCamera f0:532601698728552ns: REQ:android.control.aeMode: [ON] output stream ids: 0 3 1 2\n 0:com.google.android.GoogleCamera f0:532601698728552ns: REQ:android.control.afMode: [CONTINUOUS_PICTURE] output stream ids: 2 1 3 0\n 0:com.google.android.GoogleCamera f0:532601698728552ns: REQ:android.control.awbMode: [AUTO] output stream ids: 0 3 1 2\n ...\n\n### Preview tag monitoring information in real time\n\nTo preview tag monitoring information in real time, use: \n\n adb shell cmd media.camera watch live [-n refresh_interval_ms]\n\nExample: \n\n adb shell cmd media.camera watch live -n 250\n\nArguments:\n\n- `refresh_interval_ms`: Optional argument. Interval in milliseconds to refresh the information at. Defaults to 1000 if no value is passed.\n\nThis command prints tag monitoring information in real time. To exit, press\n*return* /*enter*.\n\nSample output: \n\n $ adb shell cmd media.camera watch live\n Press return to exit...\n\n 0:com.google.android.GoogleCamera f0:533016991302201ns: REQ:android.control.aeMode: [ON] output stream ids: 1 3 0 2\n 0:com.google.android.GoogleCamera f0:533016991302201ns: REQ:android.control.afMode: [CONTINUOUS_PICTURE] output stream ids: 2 0 3 1\n ...\n 0:com.google.android.GoogleCamera f0:533017066793915ns: RES:android.control.aeState: [SEARCHING]\n 0:com.google.android.GoogleCamera f0:533017066793915ns: 3 RES:android.control.aeState: [SEARCHING]\n 0:com.google.android.GoogleCamera f0:533017066793915ns: 2 RES:android.control.aeState: [SEARCHING]\n 0:com.google.android.GoogleCamera f0:533017066793915ns: RES:android.control.afState: [PASSIVE_SCAN]\n\n### Clear cached dumps\n\nTo clear all cached tag monitoring dumps, use: \n\n adb shell cmd media.camera watch clear\n\nThis command doesn't stop tag monitoring.\n\n### Stop monitoring tags\n\nTo stop monitoring tags in all clients and clear all buffers held for caching\ntag monitoring dumps, use: \n\n adb shell cmd media.camera watch stop\n\ndumpsys command\n---------------\n\nThe `dumpsys` command provides a host of debugging information from the camera\nservice. The following command captures the entire debugging dump from the\ncamera service: \n\n adb shell dumpsys media.camera\n\nThe `dumpsys` command also allows capturing tag monitoring dumps from open\nclients. However, `dumpsys` doesn't provide tag monitoring dumps from closed\nclients. The following are examples of using `dumpsys` for tag monitoring:\n\n- Capture tag monitoring dumps from all open clients:\n\n adb shell dumpsys media.camera -m 3a | grep -A50 Monitored\n\n- Get live preview of tag monitoring information using the Linux\n `watch` command:\n\n watch -n 1 -c 'adb shell dumpsys media.camera -m 3a | grep -A50 Monitored'"]]