自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
使用 Android 相機服務
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 相機服務包含在汽車裝置和其他板型規格 (例如手機、平板電腦和電視) 中使用的相機堆疊。如要查看整體相機架構,請參閱「相機」。本頁重點介紹汽車裝置專屬主題,以及如何使用 Android Camera API。
啟用 Android 相機服務
如要在汽車平台上啟用 Android 相機服務,產品的 makefile 必須將 ENABLE_CAMERA_SERVICE
指定為 true
。
汽車專用相機特性
在車用裝置的情況下,相機 HAL 必須包含兩個特定於車用板型規格的特徵:
如果相機未精確對準特定位置或鏡頭方向 (可透過 android.automotive.location
或 android.automotive.lens.facing
特性中的 *_OTHER
判斷),或是有多台相機共用相同的位置和方向,相機 HAL 應提供其他特性,讓應用程式能夠準確判斷相機的位置。這些特徵包括:
授予無頭系統使用者存取權
某些系統和第一方 (1P) 應用程式可以無使用者介面系統使用者 (又稱為使用者 0) 權限存取相機。這項功能可確保安全性至關重要的應用程式 (例如後視相機) 能夠繼續不間斷地串流相機畫面,不受前景使用者切換的影響。只有經過平台簽署且擁有新權限 android.permission.CAMERA_HEADLESS_SYSTEM_USER
的應用程式,才能以 User 0 的身分存取相機。
如果應用程式以 User 0 身分存取攝影機,則攝影機資料必須在本機使用,且不得傳輸至裝置外部,包括任何從攝影機資料衍生的資料。這類應用程式必須預先授予 android.permission.CAMERA
權限,並遵守「設計駕駛模式」一文中列出的 GAS 要求,遵循預先授予權限的政策。
設定相機隱私權許可清單
原始設備製造商 (OEM) 現可將特定相機應用程式納入許可清單,無論相機隱私權切換鈕的狀態為何,都能授予相機存取權。這項功能可讓使用者同時為特定許可清單應用程式允許攝影機存取權,並停用娛樂應用程式 (例如社群媒體和視訊會議) 的攝影機存取權。
只有獲得 android.permission.CAMERA_PRIVACY_ALLOWLIST
權限的系統和特權應用程式才能使用這項功能。Google Automotive Services (GAS) 合作夥伴必須提交許可清單應用程式以供審查,並遵守隱私權許可清單政策。詳情請參閱「車輛專用 Android」。
將應用程式加入許可清單
在 etc/sysconfig
目錄中:
在系統設定 XML 檔案中新增應用程式的套件名稱:
<!-- In an xml file under etc/sysconfig —>
<!--
Allowlisted packages for the camera privacy toggle. Users will not be able to turn the privacy on for these packages as OEM requires camera access for these packages to preserve user safety.
-->
<config>
<camera-privacy-allowlisted-app package="package_name" />
</config>
將應用程式的隱私權政策揭露網址新增至 AndroidManifest.xml
。meta-data
的名稱應為 privacy_policy
。
<meta-data android:name="privacy_policy" android:value= privacy policy URL/>
根據預設,允許清單應用程式或必要應用程式的相機隱私權切換鈕會隱藏在「隱私權設定」使用者介面中。不過,原始設備製造商 (OEM) 可以將下列標記設為 TRUE
,藉此覆寫這項行為。這可讓原始設備製造商根據偏好設定,自訂必要應用程式的相機隱私權切換按鈕顯示方式。
<!-- Whether to show the toggle to turn on the camera privacy for required apps -->
<bool name="config_show_camera_required_apps_toggle">false</bool>
搶先使用攝影機
特定的時間敏感型和安全性導向應用程式可以在 Android 啟動程序完成前存取相機。不過,這項存取權僅授予具備 UID AID_AUTOMOTIVE_EVS
的特殊客戶。如要進一步瞭解如何將特定 UID 指派給原生應用程式,請參閱「選用存取權控管 (DAC)」一文。這項攝影機搶先體驗功能僅適用於位於車輛車身外部的系統攝影機。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-06-12 (世界標準時間)。
[[["容易理解","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-06-12 (世界標準時間)。"],[],[],null,["# Use the Android Camera Service\n\nThe Android Camera Service comprises the camera stack used in automotive\ndevices, as well as in other form factors such as mobile phones, tablets,\nand TVs. To view the overall camera architecture, see\n[Camera](/docs/core/camera). This page focuses on topics specific to automotive\ndevices, and working with the [Android Camera API](https://developer.android.com/reference/android/hardware/camera2/package-summary).\n\nEnable Android Camera Service\n-----------------------------\n\nTo enable the Android Camera Service on the automotive platform, the product's\nmakefile must specify `ENABLE_CAMERA_SERVICE` as `true`.\n\nAutomotive-specific camera characteristics\n------------------------------------------\n\nIn the context of automotive devices, the camera HAL must include two\ndistinctive characteristics specific to the automotive form factor:\n\n| Name | Description |\n|-------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|\n| [android.automotive.location](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#AUTOMOTIVE_LOCATION) | Specifies the positioning of cameras in relation to the vehicle's body frame. |\n| [android.automotive.lens.facing](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#AUTOMOTIVE_LENS_FACING) | Indicates which direction a camera lens is facing relative to the vehicle body frame and passenger seats. |\n\nIn situations when cameras don't precisely align with specific location or lens\norientation (indicated by the presence of `*_OTHER` in the\n[`android.automotive.location`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#AUTOMOTIVE_LOCATION) or [`android.automotive.lens.facing`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#AUTOMOTIVE_LENS_FACING)\ncharacteristics), or when multiple cameras share the same location and\ndirection, the camera HAL should provide additional characteristics to enable\napps to accurately determine the camera's location. These characteristics\ninclude:\n\n- [`android.lens.poseReference`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#LENS_POSE_REFERENCE)\n- [`android.lens.poseRotation`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#LENS_POSE_ROTATION)\n- [`android.lens.poseTranslation`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#LENS_POSE_TRANSLATION)\n\nGrant access to the Headless System User\n----------------------------------------\n\nCertain system and first-party (1P) apps can access the camera as the Headless\nSystem User, also known as User 0. This feature ensures that safety-critical\napps, such as the rear-view camera, can continue camera streaming without\ninterruption, regardless of foreground user switching. Only apps that are\nplatform-signed and hold the new permission\n`android.permission.CAMERA_HEADLESS_SYSTEM_USER` can access the camera as\nUser 0.\n\nFor apps accessing cameras as User 0, the camera data MUST be consumed locally\nand MUST not be transmitted off the device, including any data derived from the\ncamera data. These apps require that the `android.permission.CAMERA` permission\nbe pre-granted and must adhere to the pre-grant permission policy outlined in\n[Design for Driving](https://developers.google.com/cars) for GAS requirements.\n\nConfigure a camera privacy allowlist\n------------------------------------\n\nOriginal equipment manufacturers (OEMs) can now configure specific camera apps\nto be included on an allowlist that grants camera access regardless of the\ncamera privacy toggle's status. This feature enables users to disable camera\naccess for entertainment apps, such as social media and video conferencing,\nwhile simultaneously permitting camera access for certain allowlisted apps.\n\nOnly system and privileged apps granted the\n`android.permission.CAMERA_PRIVACY_ALLOWLIST` permission can use this feature.\nGoogle Automotive Services (GAS) partners must submit their allowlisted apps\nfor review and comply with the privacy allowlist policy. To learn more, see\n[Android for Cars](https://developers.google.com/cars).\n\n### Add an app to the allowlist\n\nIn the `etc/sysconfig` directory:\n\n1. Add the app's package name in a system configuration XML file:\n\n \u003c!-- In an xml file under etc/sysconfig ---\u003e\n\n \u003c!--\n Allowlisted packages for the camera privacy toggle. Users will not be able to turn the privacy on for these packages as OEM requires camera access for these packages to preserve user safety.\n --\u003e\n\n \u003cconfig\u003e\n \u003ccamera-privacy-allowlisted-app package=\"package_name\" /\u003e\n \u003c/config\u003e\n\n2. Add the app's URL of privacy policy disclosure to `AndroidManifest.xml`.\n The name of the `meta-data` should be `privacy_policy`.\n\n \u003cmeta-data android:name=\"privacy_policy\" android:value= privacy policy URL/\u003e\n\nBy default, the camera privacy toggle for allowlisted apps or required apps is\nhidden in the **Privacy Settings** UI. However, OEMs can override this behavior\nby setting the following flag to `TRUE`. This allows OEMs to customize the\nvisibility of the camera privacy toggle for the required apps based on their\npreferences. \n\n \u003c!-- Whether to show the toggle to turn on the camera privacy for required apps --\u003e\n\n \u003cbool name=\"config_show_camera_required_apps_toggle\"\u003efalse\u003c/bool\u003e\n\nGet early camera access\n-----------------------\n\nSpecific time-sensitive and safety-oriented apps can access the camera before\nthe Android boot process is finished. However, this access is exclusively\ngranted to privileged clients with the `UID AID_AUTOMOTIVE_EVS`. To learn more\nabout assigning a specific UID to a native app,\nsee [Discretionary access control (DAC)](/docs/core/permissions/filesystem).\nThis early access to the camera is limited to system cameras positioned on the\nexterior of the vehicle's body."]]