自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
使用 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
的应用才能以用户 0 的身份访问摄像头。
对于以用户 0 身份访问摄像头的应用,摄像头数据必须在本地使用,不得传输到设备之外,包括从摄像头数据派生出的任何数据。这些应用需要预先授予 android.permission.CAMERA
权限,并且必须遵守 Design for Driving 中针对 GAS 要求列出的预授权政策。
配置相机隐私许可名单
原始设备制造商 (OEM) 现在可以将特定相机应用配置为包含在许可名单中,无论相机隐私切换开关的状态如何,该名单都会授予相机访问权限。借助此功能,用户可以为社交媒体和视频会议等娱乐应用停用相机访问权限,同时允许某些列入许可名单的应用使用相机。
只有被授予 android.permission.CAMERA_PRIVACY_ALLOWLIST
权限的系统应用和特权应用才能使用此功能。Google 汽车服务 (GAS) 合作伙伴必须提交其已列入许可名单的应用以供审核,并遵守隐私许可名单政策。如需了解详情,请参阅 Android for Cars。
将应用添加到许可名单
在 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
来替换此行为。这样,OEM 就可以根据自己的偏好,自定义必需应用的相机隐私切换开关的显示设置。
<!-- 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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],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."]]