自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Automotive Location Bypass API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助此功能,您可以通过“使用位置信息提供驾驶辅助功能”开关,单独控制已列入许可名单且与 Android 绑定的驾驶辅助应用的位置信息访问权限。这样一来,即使“使用位置信息”开关处于关闭状态,这些应用也能获取位置信息。
- Android 12 不为此功能提供公共 API。驾驶辅助应用应像往常一样请求位置信息更新。
- Android 13 及更高版本必须发出位置信息请求,才能使用
LocationManager.requestLocationUpdates()
并传入已配置 LocationRequest.setAdasGnssBypass(true)
的 LocationRequest
对象。
使用 Driver Assistance Location Bypass API
以下部分介绍了如何使用 Driver Assistance Location Bypass API。如需详细了解使用政策,请参阅位置信息绕过许可名单政策。
查看驾驶辅助开关状态
在 Android 13 及更高版本中,您可以在请求位置信息更新之前检查驾驶辅助开关状态。
// Returns the current status of "Use location for driver assistance".
locationManager.isAdasGnssLocationEnabled();
运行 Android 调试桥 (ADB) 命令
对于开发和测试,您无需使用位置信息设置即可快速检查或更改驾驶辅助功能的状态。
- 如需使用 ADB 命令来检查或更改状态,请执行以下操作:
// Gets the status of ADAS location.
adb shell cmd location is-adas-gnss-location-enabled
// Enables ADAS location.
adb shell cmd location set-adas-gnss-location-enabled true
// Disables ADAS location.
adb shell cmd location set-adas-gnss-location-enabled false
设置权限
如需了解针对特定 Android 版本的权限,请参阅以下内容:
- 在 Android 12 中,驾驶辅助应用必须具有 WRITE_SECURE_SETTINGS 权限。
- 在 Android 13 及更高版本中,需要
LOCATION_BYPASS
权限。
将应用添加到设备的许可名单中
在 etc/sysconfig
目录中执行以下操作:
- 将应用的软件包名称添加到系统配置 XML 文件中:
<!-- In a xml file under etc/sysconfig–>
<config>
…
<allow-adas-location-settings package="PACKAGE-NAME" />
…
</config>
如需确保您的软件包显示在位置信息设置界面中,请将软件包名称添加到 config_locationDriverAssistancePackageNames
。
将应用的隐私权政策披露网址添加到 AndroidManifest.xml
。元数据的名称应为 privacy_policy
。
<meta-data android:name="privacy_policy" android:value= privacy policy URL/>
移除“使用位置信息提供驾驶辅助功能”开关
如果您没有位置信息驱动的驾驶辅助应用从 Android 请求位置信息,您可以注释掉代码块以移除“位置信息设置”开关。
- 打开
packages/apps/Car/Settings/res/xml/location_settings_fragment.xml
,然后注释掉以下代码。
<com.android.car.ui.preference.CarUiTwoActionSwitchPreference
android:fragment="com.android.car.settings.location.AdasLocationFragment"
android:key="@string/pk_location_driver_assistance_state_switch"
android:title="@string/location_driver_assistance_toggle_title"
android:summary="@string/location_driver_assistance_toggle_summary"
settings:controller="com.android.car.settings.location.AdasLocationSwitchPreferenceController"
settings:searchable="true"/>
<com.android.car.settings.common.DividerPreference/>
- 移除该开关后,将
config_defaultAdasGnssLocationEnabled
设为 false
。
运行汽车测试套件
Google 提供了汽车测试套件 (ATS) 测试,以确保设备上的所有驾驶辅助软件包均已列入 Google 的许可名单。测试已远程配置。您无需等待下一个 ATS 版本就能添加新软件包。如需了解详情,请参阅 Complete Automotive Tests in a Box。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-08。
[[["易于理解","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-08-08。"],[],[],null,["# Automotive Location Bypass API\n\nThis feature allows location access of allowlisted, Android-bundled, driver\nassistance apps to be controlled separately by the \"Use location for driver\nassistance\" switch. This enables these apps to access location even when the \"Use location\"\nswitch is off.\n\n- Android 12 doesn't provide a public API for this feature. Driver assistance apps should request location updates as usual.\n- Android 13 and higher must make a location request to use `LocationManager.requestLocationUpdates()` and pass in a `LocationRequest` object configured with `LocationRequest.setAdasGnssBypass(true)`.\n\nUse the driver assistance location bypass API\n---------------------------------------------\n\nThe following sections describe how to use the driver assistance location bypass API. To learn\nmore about the usage policy, see\n[Location Bypass Allowlist Policy](/docs/automotive/location_bypass/location_bypass_policy).\n\n### Check the driver assistance switch status\n\nIn Android 13 and higher, you can check driver assistance switch status\nbefore requesting location updates.\n\n```scilab\n// Returns the current status of \"Use location for driver assistance\".\nlocationManager.isAdasGnssLocationEnabled();\n```\n\n### Run Android Debug Bridge (ADB) commands\n\nFor development and testing, you can quickly check or change the status of the driver assistance\ntoggle without using Location Settings.\n\n1. To use ADB commands to check or change status: \n\n ```scilab\n // Gets the status of ADAS location.\n adb shell cmd location is-adas-gnss-location-enabled\n\n // Enables ADAS location.\n adb shell cmd location set-adas-gnss-location-enabled true\n\n // Disables ADAS location.\n adb shell cmd location set-adas-gnss-location-enabled false\n ```\n\n### Set permission\n\nSee the following for version-specific Android releases:\n\n1. In Android 12, driver assistance apps must have the [WRITE_SECURE_SETTINGS](https://developer.android.com/reference/android/Manifest.permission#WRITE_SECURE_SETTINGS) permission.\n2. In Android 13 and higher, the `LOCATION_BYPASS` permission is required.\n\n### Add an app to the allowlist on your device\n\nIn the `etc/sysconfig` directory:\n\n1. Add the app's package name in a system configuration XML file: \n\n```carbon\n\u003c!-- In a xml file under etc/sysconfig--\u003e\n\u003cconfig\u003e\n...\n\u003callow-adas-location-settings package=\"PACKAGE-NAME\" /\u003e\n...\n\u003c/config\u003e\n```\n\nTo ensure your package appears in the Location Settings UI, add your package name to\n`config_locationDriverAssistancePackageNames`.\n\nAdd the app's URL of privacy policy disclosure to `AndroidManifest.xml`. The name\nof the meta-data should be `privacy_policy`. \n\n```scdoc\n\u003cmeta-data android:name=\"privacy_policy\" android:value= privacy policy URL/\u003e\n```\n\n### Remove the \"Use location for driver assistance switch\"\n\nIf you don't have a location-powered driver assistance app that requests location from Android,\nyou can comment out the code block to remove the switch for Location Settings.\n\n1. Open `packages/apps/Car/Settings/res/xml/location_settings_fragment.xml` and then comment out the following code. \n\n ```transact-sql\n \u003ccom.android.car.ui.preference.CarUiTwoActionSwitchPreference\n\n android:fragment=\"com.android.car.settings.location.AdasLocationFragment\"\n\n android:key=\"@string/pk_location_driver_assistance_state_switch\"\n\n android:title=\"@string/location_driver_assistance_toggle_title\"\n\n android:summary=\"@string/location_driver_assistance_toggle_summary\"\n\n\n settings:controller=\"com.android.car.settings.location.AdasLocationSwitchPreferenceController\"\n\n settings:searchable=\"true\"/\u003e\n\n \u003ccom.android.car.settings.common.DividerPreference/\u003e\n ```\n2. After removing the switch, set `config_defaultAdasGnssLocationEnabled` to `false`.\n\nRun the Automotive test suite\n-----------------------------\n\nGoogle provides an Automotive test suite (ATS) test, which ensures that all driver assistance\npackages on a device have been allowlisted with Google. The test is remotely configured. You\nneedn't wait until the next ATS release to add a new package. You can learn more at\n[Complete Automotive Tests in a Box.](/docs/automotive/tools/catbox)\n[](/docs/automotive/tools/catbox)"]]