서비스 번들 빌드 및 배포

미들웨어를 만들고 맞춤 코드를 작성한 후에는 서비스 번들을 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 파일 또는 기존 파일에 사전 빌드된 타겟을 만듭니다.

      // 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 파일에 새 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. SDV 이미지에 새 makefile을 포함하려면 제품 makefile의 PRODUCT_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
    

개발 중 빠른 서비스 번들 업데이트

Android 스튜디오 for Platform (ASfP)을 사용하는 경우 시스템 이미지를 다시 빌드하지 않고도 IDE에서 직접 이미 설치된 서비스 번들 APEX에 변경사항을 배포할 수 있습니다. 자세한 내용은 SDV 서비스 번들 배포를 참고하세요.

서비스 번들 종속 항목 관리

일부 시나리오에서는 서비스 번들 종속 항목의 정적 연결을 사용하여 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 통합을 참고하세요.