開始使用多媒體廣告安全功能

本頁面提供總覽,說明如何在軟體定義車輛 (SDV) 平台存取、建構及執行 Display Safety 元件,包括高可用性轉譯器 (HAR)、DriverUI 和安全監控器。

程式碼存取權

本節說明如何取得 HAR 和 DriverUI 顯示安全元件的程式碼集。

高可用性轉譯器

高可用性轉譯器 (HAR) 的程式碼集,可在 packages/services/display_safety/ 的主要存放區簽出中取得。

HAR 的程式碼集結構如下:

  • Framework:包含平台、算繪、動畫和音訊的核心架構介面。
  • 參考資料:包含架構介面的平台專屬實作,以及 HAR 參考應用程式和安全工具鍊 (設計編譯器、安全監控器) 的程式碼。
  • 服務:Android 專用服務,用於在元件之間傳送及接收車輛資料,以及定義 APEX 資料套件。
  • 預建:為預建二進位檔 (例如 Impeller 圖形程式庫) 提供包裝函式。

Harry 參考應用程式程式碼位於 packages/services/display_safety/reference/harry_app。

如要瞭解 HAR 的詳細目錄結構,請參閱「Display Safety Code 結構」

安全監控

安全監控工具的程式碼集位於主要存放區,可在 packages/services/display_safety/reference/safety-monitor 簽出。

安全監控程式碼的結構如下:

  • main.rs:擷取指示燈構件、初始化車輛資料伺服器,以及指示燈監控迴圈。系統會將指示燈能見度資訊與指示燈檢查結果進行比較,並使用 SDV 記錄提供結果。
  • Vehicle_data_server.rs:訂閱車輛 資料的伺服器,會更新主迴圈的指示燈顯示設定。
  • Telltale_monitoring.rs:在迴圈中執行,使用 screencap crate 擷取螢幕緩衝區的副本,並檢查指定區域是否有跡象。接著,指示燈檢查結果會傳送至主迴圈。

DriverUI

DriverUI 是未綁定程式碼集的一部分,可從 ub-automotive-master 分支存取。

mkdir ub-automotive-master && cd ub-automotive-master
repo init -u https://android.googlesource.com/platform/manifest -b ub-automotive-master
repo sync -cq

如要進一步瞭解未隨附和 Google 來源,請參閱「整合未隨附應用程式」。

建構及執行

本節詳細說明如何編譯及執行 SDV Media 中的 HAR 目標,以及 SDV 車用資訊娛樂系統 (IVI) 中的 DriverUI 目標,以透過 SDV 實現完整的儀表板解決方案。

訪客 VM

圖 1. Display Safety 雙 VM 結構。

建立 HAR 和 SDV 媒體目標

  • 基本媒體目標: sdv_media_cf
    • 說明:SDV 媒體堆疊的專屬目標,可獨立測試各種媒體架構。
    • 目錄位置: device/google/sdv/
  • HAR 整合目標: sdv_media_har_cf
    • 說明:這個目標會將媒體堆疊與 HAR 整合,在 Cuttlefish 上執行 SDV 媒體。
    • 目錄位置: device/google/sdv_display_safety/
    • 建構作業執行:
# In the root of the Android source
source build/envsetup.sh
lunch sdv_media_har_cf-aosp_current-userdebug
m -j

建構 DriverUI

在 ub-automotive-master 分支版本中,您可以使用 CommandLine 或 AndroidStudio 建構未隨附的應用程式。

在 Android Studio 中匯入 Gradle 檔案: packages/apps/Car/libs/aaos-apps-gradle-project/build.gradle

這是主要的 Gradle 專案,包含所有未隨附的應用程式,包括 DriverUI。使用 Gradle 建構專案:

# To build only DriverUI module of aaos-apps-gradle-project use
./gradlew :driver-ui:assemble

建構成功後,DriverUI APK 會位於 out/aaos-apps-gradle-build/driver-ui/outputs/apk/default/debug/ driver-ui-default-debug.apk

DriverUI 程式碼位於 packages/apps/Car/DriverUI

注意:DriverUI 是主要 Gradle 專案的子模組,因此所有 Gradle 工作都會使用 aaos-apps-gradle-project 執行。

使用 DriverUI 建構 SDV IVI 目標

  • 基本目標: sdv_ivi_cf
    • 說明:這是 x86-64 架構上 IVI 的基礎 SDV 目標。
    • 目錄位置: device/google/sdv/
  • DriverUI 整合目標: sdv_ivi_cf_ds

    • 說明:這個目標會擴充基本 IVI 設定,納入 Display Safety 元件。這個目標對於驗證 Display Safety 服務和儀表板內的互動至關重要。
    • 目錄位置: device/google/sdv_display_safety/
    • 新增 DriverUI 二進位檔:將 DriverUI.apk 複製到 packages/apps/Car/DriverUIPrebuilt,並附上 Blueprint Android.bp 檔案。

      # Create a blueprint file, contents of this file are shown in the next step
      touch /path/to/aosp_repo_root/packages/apps/Car/DriverUIPrebuilt/Android.bp
      # Copy DriverUI.apk built
      cp /path/to/ub-automotive-master/out/aaos-apps-gradle-build/driver-ui/outputs/apk/default/debug/driver-ui-default-debug.apk /path/to/aosp_repo_root/packages/apps/Car/DriverUIPrebuilt/DriverUI.apk
      

Android.bp 應設定為使用模組名稱 DriverUIPrebuilt 並覆寫 DriverUIStubApp:

android_app_import {
    name: "DriverUIPrebuilt",
    overrides: ["DriverUIStubApp"],
    apk: "DriverUI.apk",
    privileged: true,
    product_specific: true,
    certificate: "platform",
    required: ["allowed_privapp_com.android.car.driverui"],

    optional_uses_libs: [
        "androidx.window.extensions",
        "androidx.window.sidecar",
    ],
    enforce_uses_libs: false,
    dex_preopt: {
        enabled: false,
    },
}
  • 建構作業執行:

    # In the root of the Android source
    source build/envsetup.sh
    lunch sdv_ivi_cf_ds-aosp_current-userdebug
    m -j
    

目標部署作業

兩個目標的建構程序成功完成後,Cuttlefish 公用程式會協助啟動目標,如本節所述。

SDV 媒體和 HAR 部署

HAR 目標是使用預先定義的 sdv-media-config.json 設定建立,該設定是在 device/google/sdv_media_cf.mk 中指定。

注意:SDV Media 和 SDV IVI 都是在 Display Safety 叢集的 Unlocked 啟動模式下啟動。詳情請參閱「SDV 啟動模式」。

# In the root of the Android source
source build/envsetup.sh
lunch sdv_media_har_cf-aosp_current-userdebug
cvd create --extra_bootconfig_args="androidboot.sdv.boot_mode=unlocked androidboot.sdv.instance_name=instance1 androidboot.virt.address=3"

建立完成後,終端機會顯示記錄,說明如何透過 localhost 通訊埠在瀏覽器中存取目標:Point your browser to https://localhost:8443 to interact with the device.

SDV Media VM 中的 HAR

圖 2. 顯示 Safety SDV Media VM 與 HAR。

SDV IVI 和 DriverUI 部署

SDV IVI DriverUI 目標會使用 device/google/sdv_ivi_cf.mk 中定義的現有 sdv-ivi-config.json 啟動。您也可以指定其他啟動設定參數,以及儀表板螢幕的適當顯示尺寸。

# In the root of the Android source
source build/envsetup.sh
lunch sdv_ivi_cf_ds-aosp_current-userdebug
cvd create --extra_bootconfig_args="androidboot.sdv.boot_mode=unlocked androidboot.sdv.instance_name=instance2 androidboot.virt.address=4" --display1=width=1920,height=720

目標啟動後,終端機會顯示記錄,以便在瀏覽器中透過 localhost 通訊埠存取目標:Point your browser to https://localhost:8443 to interact with the device.

部署 SDV-IVI 和 DriverUI 目標時,會初始化兩個螢幕:一個用於 SDV-IVI 系統,另一個用於 DriverUI。DriverUI 是具備特殊權限的叢集應用程式,會運用 ClusterHomeManager 類別 (也稱為 Cluster2)。

SDV-IVI VM 中的 DriverUI

圖 3. 顯示 Safety SDV IVI VM 和 DriverUI。

部署雙 VM 叢集

Cuttlefish 可使用雙 VM 設定啟動兩個虛擬機器 (VM),以實現顯示疊加。

顯示組合結構

圖 4. Display Safety 顯示組合總覽。

您可以使用 packages/services/display_safety/service/ 提供的 ds_toolkit 啟動雙 VM 設定。

m ds_toolkit
ds_toolkit launch

設定啟動後,終端機會顯示記錄,以便在瀏覽器中透過 localhost 通訊埠存取目標:Point your browser to https://localhost:8443 to interact with the device.

這會在完全運作的叢集中啟動兩個 Cuttlefish 目標,並疊加兩個虛擬機器螢幕。

顯示安全完整叢集

圖 5. 顯示 Safety 完整叢集,內含 SDV Media 和 SDV IVI VM。

建築物安全監控

根據預設,系統會為 SDV 媒體目標建構安全監控器:

# In the root of the Android source
source build/envsetup.sh
lunch sdv_media_har_cf-aosp_current-userdebug
m -j

在執行階段,安全監控器會使用一組預設的編譯器構件,這些構件會產生並封裝至 APEX,用於參考叢集顯示。

執行 har-design-compiler 可能會產生新的構件。這項工具會在目標上執行,根據設計生成構件。建議您執行工具,從目標提取新的構件,然後重新建構映像檔。根據預設,這項工具會在目標上建構及安裝。

# Run the compiler on the target
adb shell har_design_compiler -c </path/to/artifacts> -o /data/local/tmp/
# Pull the artifacts to the local filesystem
adb pull data/local/tmp/artifacts services/harry-prebuilt/data/assets/
# Rebuild the image
m -j

安全監控器會在目標啟動時初始化。安全監控器會持續循環執行,分析螢幕緩衝區和傳入的車輛資料信號,驗證螢幕上的安全關鍵元素是否符合預期。

你隨時可以查看安全監控記錄:

adb logcat | grep har-safety-monitor