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) 指令

在開發和測試階段,您可以快速查看或變更駕駛輔助切換鈕的狀態,不必使用位置資訊設定。

  1. 如要使用 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 版本,請參閱下列內容:

  1. 在 Android 12 中,駕駛輔助應用程式必須具備 WRITE_SECURE_SETTINGS 權限。
  2. 在 Android 13 以上版本中,必須具備 LOCATION_BYPASS 權限。

將應用程式加入裝置的許可清單

在 etc/sysconfig 目錄中:

  1. 在系統設定 XML 檔案中新增應用程式的套件名稱:
  2. <!-- 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/>

移除「開啟定位功能以便使用駕駛輔助功能」切換鈕

如果沒有需要位置資訊的駕駛輔助應用程式,可以註解排除程式碼區塊,移除位置資訊設定的切換鈕。

  1. 開啟 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/>
  2. 移除切換鈕後,請將 config_defaultAdasGnssLocationEnabled 設為 false。

執行車輛測試套件

Google 提供車輛測試套件 (ATS) 測試,確保裝置上的所有駕駛輔助套件都已加入 Google 的許可清單。測試是透過遠端設定。您不必等到下一個 ATS 版本發布,就能新增套件。詳情請參閱「完整的 Automotive Tests in a Box」。