自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Automotive Location Bypass API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
這項功能可讓您透過「使用位置資訊提供駕駛輔助功能」切換鈕,分別控管許可清單中 Android 隨附的駕駛輔助應用程式的位置存取權。這樣一來,即使關閉「使用位置資訊」切換鈕,這些應用程式也能存取位置資訊。
- Android 12 不會為這項功能提供公開 API。駕駛輔助應用程式應照常要求位置更新通知。
- Android 13 以上版本必須提出位置要求才能使用
LocationManager.requestLocationUpdates()
,並傳入以 LocationRequest.setAdasGnssBypass(true)
設定的 LocationRequest
物件。
使用駕駛輔助位置略過 API
以下各節說明如何使用駕駛輔助位置繞過 API。如要進一步瞭解使用政策,請參閱「地點略過功能許可清單政策」。
檢查駕駛輔助系統開關狀態
在 Android 13 以上版本中,您可以在要求位置更新之前,先檢查駕駛輔助切換鈕狀態。
// Returns the current status of "Use location for driver assistance".
locationManager.isAdasGnssLocationEnabled();
執行 Android Debug Bridge (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>
為確保套件會顯示在位置設定 UI 中,請將套件名稱加入 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
。
執行 Automotive 測試套件
Google 提供汽車測試套件 (ATS) 測試,可確保裝置上的所有駕駛輔助套件都已列入 Google 許可清單。測試已從遠端設定。您不必等到下次 ATS 版本發布,即可新增套件。如需進一步瞭解,請參閱「Complete Automotive Tests in a Box」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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)"]]