بسته های خدماتی را بسازید و اجرا کنید

پس از اینکه میان‌افزار را ایجاد کردید و کد سفارشی خود را نوشتید، می‌توانید بسته‌های سرویس خود را به عنوان فایل‌های APEX مستقر کنید.

  1. ایجاد فایل‌های پیکربندی SDV:

    زنگ زدگی

    1. Generate SDV configuration files by running:

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

      Running vsidlc with the --apex flag automatically generates all necessary configuration files, including:

      • APEX manifest ( apex_manifest.json )
      • مانیفست فراداده SDV ( sdv_service_bundles_manifest.textproto )
      • Linker configuration ( linker.config.json )
      • چارچوب‌های فایل SELinux ( file_contexts )
      • Public and private keys ( .avbpubkey and .pem )
      • اعلان‌های مجوز و پیکربندی‌های هماهنگی
      • یک فایل Android.bp که تمام ماژول‌های Soong لازم را تعریف می‌کند.

      می‌توانید پیکربندی‌های تولید شده را در زیر بیابید:

      /path/to/output/apex/
      

      و،

      /path/to/output/configs/
      

    سی++

    1. Create an SDV metadata manifest file, service_bundle.manifest.textproto with these essential execution metadata fields:

      • Name of the service according to the naming conventions
      • نمایش عدد صحیح و رشته‌ای نسخه بسته سرویس
      • مسیر کتابخانه‌ای که قبلاً ایجاد شده است

      آماده‌سازی فراداده‌های ضروری بسته خدمات برای بسته‌بندی و استقرار بسته خدمات الزامی است.

      # 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. Create a new linker configuration file, linker.config.json :

      { "visible": true }
      
    3. Create a new apex_manifest.json file with these fields:

      • نام بسته SDV منحصر به فرد
      • نسخه ایپکس
      • Dependency on SDV Comms libs
      {
        "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. Create a new SELinux file context apex_file_contexts .

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

      To learn more, see Security context and categories .

    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. Create a new APEX module in a new or existing Android.bp file. Use the SDV package name as the APEX module name.

      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. To include the new makefile in an SDV image, add the new APEX module to the PRODUCT_PACKAGES in the product makefile . For example, see 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هایی با موارد زیر هستند:

  • Single service bundles
  • چندین بسته خدماتی که وابستگی‌های مشترک زیادی ندارند

برای فعال کردن پیوند استاتیک، ویژگی‌های زیر را به تعریف کتابخانه بسته سرویس اضافه کنید:

// 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"],
}

برای هر موقعیت، توصیه می‌کنیم تأیید کنید که پیوند استاتیک به وابستگی‌ها منجر به بهبود در فضای حافظه و زمان شروع بسته‌های سرویس می‌شود.

Debug (dumpsys)

The lifecycle manager implements the dumpsys interface. This interface displays the list of service bundles to the user that are in either the created or started state. The interface also displays the FQIN or UID of the service bundle process.

برای مشاهده وضعیت فعلی و شناسه‌های بسته‌های سرویس خود، دستور زیر را اجرا کنید:

# Grant root access.
adb root

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

قدم بعدی چیست؟

To automatically execute vsidlc and enable the IDE plugin to work with dependencies, see Automatic catalog updates and LSP integration .