ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
Automotive Location Bypass API
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ฟีเจอร์นี้ช่วยให้คุณควบคุมการเข้าถึงตำแหน่งของแอปตัวช่วยของผู้ขับที่รวมอยู่ใน Android และอยู่ในรายการที่อนุญาตแยกต่างหากได้โดยใช้สวิตช์ "ใช้ตำแหน่งสำหรับตัวช่วยของผู้ขับ" ซึ่งจะช่วยให้แอปเหล่านี้เข้าถึงตำแหน่งได้แม้ว่าสวิตช์ "ใช้ตำแหน่ง" จะปิดอยู่ก็ตาม
- Android 12 ไม่มี API สาธารณะสําหรับฟีเจอร์นี้ แอปผู้ช่วยคนขับควรขอการอัปเดตตำแหน่งตามปกติ
- Android 13 ขึ้นไปต้องส่งคำขอตำแหน่งเพื่อใช้
LocationManager.requestLocationUpdates()
และส่งออบเจ็กต์ LocationRequest
ที่กําหนดค่าด้วย LocationRequest.setAdasGnssBypass(true)
ใช้ 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>
เพิ่มชื่อแพ็กเกจลงใน config_locationDriverAssistancePackageNames
เพื่อให้แพ็กเกจปรากฏใน UI การตั้งค่าตำแหน่ง
เพิ่ม URL ของการเปิดเผยนโยบายความเป็นส่วนตัวของแอปลงใน 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 และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-08 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],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)"]]