サービス バンドルをビルドしてデプロイする

ミドルウェアを作成してカスタムコードを記述したら、サービス バンドルを APEX ファイルとしてデプロイできます。

  1. SDV 構成ファイルを作成します。

    Rust

    1. 次のコマンドを実行して SDV 構成ファイルを生成します。

      vsidlc -c /path/to/catalog -o /path/to/output --apex
      

      --apex フラグを指定して vsidlc を実行すると、次のような必要な構成ファイルがすべて自動的に生成されます。

      • APEX マニフェスト(apex_manifest.json
      • SDV メタデータ マニフェスト(sdv_service_bundles_manifest.textproto
      • リンカー構成(linker.config.json
      • SELinux ファイル コンテキスト(file_contexts
      • 公開鍵と秘密鍵(.avbpubkey.pem
      • 権限の申告とオーケストレーションの構成
      • 必要なすべての Soong モジュールを定義する Android.bp ファイル。

      生成された構成は次の場所にあります。

      /path/to/output/apex/
      

      /path/to/output/configs/
      

    C++

    1. 次の重要な実行メタデータ フィールドを含む SDV メタデータ マニフェスト ファイル service_bundle.manifest.textproto を作成します。

      • 命名規則に従ったサービスの名前
      • サービス バンドル バージョンの整数と文字列の表現
      • 以前に作成したライブラリのパス

      サービス バンドルのパッケージ化とデプロイには、必須のサービス バンドル メタデータの準備が必須です。

      # proto-file: //system/software_defined_vehicle/core_services/service_bundles_registry/proto/sdv_service_bundles_manifest.proto
      # proto-message: SdvServiceBundleManifestEntry
      
      # SDV service bundle metadata definition with mandatory fields.
      sdv_service_bundle_metadata {
        # Service bundle name.
        name: "ServiceBundleName"
        # Service bundle integer version.
        version_number: 42
        # Service bundle version as a string.
        version_name: "42.alpha"
        # Service bundle library path.
        native_library_path: "lib64/libservice_bundle.so"
      }
      
    2. 新しいリンカー構成ファイル linker.config.json を作成します。

      { "visible": true }
      
    3. 次のフィールドを含む新しい apex_manifest.json ファイルを作成します。

      • 一意の SDV パッケージ名
      • APEX のバージョン
      • SDV Comms ライブラリへの依存関係
      {
        "name": "com.sdv.oem.apex_and_module_name",
        "version": 1,
        "requireNativeLibs": [
            "libsdv_comms_ctx_ffi.so",
            "libsdv_comms_dt_ffi.so",
            "libsdv_comms_id_ffi.so",
            "libsdv_comms_sd_ffi.so"
        ]
      }
      
    4. 公開鍵 apex_name.apex_key.avbpubkey と秘密鍵 apex_name.apex_key.pem を作成します。

    5. 新しい SELinux ファイル コンテキスト apex_file_contexts を作成します。

      (/.*)?    u:object_r:system_file:s0
      

      詳細については、セキュリティ コンテキストとカテゴリをご覧ください。

    6. 新しい Android.bp ファイルまたは既存の Android.bp ファイルに事前構築済みターゲットを作成します。

      // SDV manifest file prebuilt.
      prebuilt_etc {
          name: "com.sdv.oem.apex_and_module_name.service_bundles_manifest",
          // The source filename of the manifest file.
          src: "service_bundle.manifest.textproto",
          // The name of the installed file needs be `sdv_service_bundles_manifest.textproto`.
          filename: "sdv_service_bundles_manifest.textproto",
          // Disable direct installation of the prebuilt to one of the partitions.
          // The manifest is used only inside of an apex.
          installable: false,
      }
      // The linker config to allow libraries for the apex to be linkable.
      linker_config {
          name: "com.sdv.oem.apex_and_module_name. linker_config",
          src: "linker.config.json",
          // Disable direct installation of the prebuilt to one of the partitions.
          // The linker configuration is used only inside of an apex.
          installable: false,
      }
      // Key to be used for signing the apex.
      apex_key {
          name: "apex_name.apex_key",
          public_key: "apex_name.apex_key.avbpubkey",
          private_key: "apex_name.apex_key.pem",
      }
      
    7. 新しい Android.bp ファイルまたは既存の Android.bp ファイルに新しい APEX モジュールを作成します。SDV パッケージ名を APEX モジュール名として使用します。

      apex {
          name: "com.sdv.oem.apex_and_module_name",
          // The service bundle(s) to be included in the apex.
          native_shared_libs: [
              "libservice_bundle",
          ],
          prebuilts: [
              // SDV service bundles manifest file.
              "com.sdv.oem.apex_and_module_name.service_bundles_manifest",
              // Linker configuration to enable loading library from apex.
              "com.sdv.oem.apex_and_module_name.linker_config",
          ],
          // Json manifest file describes metadata of the APEX package.
          // The 'name' field from the JSON is used as a mounting point.
          manifest: "apex_manifest.json",
          // Setting the security contexts to files in this APEX bundle.
          file_contexts: "apex_file_contexts",
          // Name of the apex_key module that provides the private key to sign the APEX bundle.
          key: "apex_name.apex_key",
          // Mark apex as non-updatable for now, this might be revisited going forward.
          updatable: false,
          // Service bundle package is installed into /product partition.
          product_specific: true,
      }
      
  2. 新しい makefile を SDV イメージに含めるには、プロダクト makefilePRODUCT_PACKAGES に新しい APEX モジュールを追加します。例については、sdv_samples_core_services.mk をご覧ください。

  3. Cuttlefish を使用している場合は、次のコマンドを実行してデバイスを起動します。

    sdv-cf create --instance_name=instance1
    
  4. システムの起動時にサービス バンドルを実行します。

    # Grant root access.
    adb root
    # Launch the new service bundle.
    adb shell sdv_service_bundle start \
      local-vm:com.sdv.oem.apex_and_module_name.ServiceBundleName/instance-1
    

サービス バンドルの依存関係の管理

シナリオによっては、サービス バンドル依存関係の静的リンクを使用して、APEX のサイズとサービス バンドルのメモリ使用量を削減し、サービス バンドルの起動時間を短縮できます。これらのシナリオには、次のような APEX が含まれます。

  • 単一サービス バンドル
  • 共通の依存関係をあまり共有しない複数のサービス バンドル

静的リンクを有効にするには、サービス バンドル ライブラリの定義に次のプロパティを追加します。

// Service bundle library.
rust_ffi_shared {
  // See rust_ffi_shared basic template.
  ...
  // uses static linking for the dependencies
  prefer_rlib: true,
  // needed to correctly resolve commstack deps
  ld_flags: ["-Wl,--no-as-needed"],
}

各状況で、依存関係への静的リンクによってサービス バンドルのメモリ使用量と起動時間が改善されることを確認することをおすすめします。

デバッグ(dumpsys)

ライフサイクル マネージャーは dumpsys インターフェースを実装します。このインターフェースには、created 状態または started 状態のサービス バンドルのリストがユーザーに表示されます。インターフェースには、サービス バンドル プロセスの FQIN または UID も表示されます。

サービス バンドルの現在の状態と識別子を表示するには、次のコマンドを実行します。

# Grant root access.
adb root

# Execute dumpsys to see service bundles state
adb shell dumpsys google.sdv.lifecycle.ILifecycleManager/default

次のステップ

vsidlc を自動的に実行し、IDE プラグインが依存関係を処理できるようにするには、カタログの自動更新と LSP 統合をご覧ください。