सेवा बंडल बनाना और उन्हें डिप्लॉय करना

मिडलवेयर बनाने और कस्टम कोड लिखने के बाद, अपनी सर्विस बंडल को APEX फ़ाइलों के तौर पर डिप्लॉय किया जा सकता है.

  1. एसडीवी कॉन्फ़िगरेशन फ़ाइलें बनाना:

    रस्ट

    1. एसडीवी कॉन्फ़िगरेशन फ़ाइलें जनरेट करने के लिए, यह कमांड चलाएं:

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

      vsidlc को --apex फ़्लैग के साथ चलाने पर, सभी ज़रूरी कॉन्फ़िगरेशन फ़ाइलें अपने-आप जनरेट हो जाती हैं. इनमें ये फ़ाइलें शामिल हैं:

      • APEX मेनिफ़ेस्ट (apex_manifest.json)
      • एसडीवी मेटाडेटा मेनिफ़ेस्ट (sdv_service_bundles_manifest.textproto)
      • लिंकर कॉन्फ़िगरेशन (linker.config.json)
      • SELinux की फ़ाइल के कॉन्टेक्स्ट (file_contexts)
      • सार्वजनिक और निजी कुंजियां (.avbpubkey और .pem)
      • अनुमतियों का एलान और ऑर्केस्ट्रेशन कॉन्फ़िगरेशन
      • Android.bp फ़ाइल, जिसमें सभी ज़रूरी Soong मॉड्यूल तय किए गए हैं.

      जनरेट किए गए कॉन्फ़िगरेशन यहां देखे जा सकते हैं:

      /path/to/output/apex/
      

      और,

      /path/to/output/configs/
      

    C++

    1. एसडीवी मेटाडेटा मेनिफ़ेस्ट फ़ाइल, 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 फ़ाइल बनाएं:

      • एसडीवी पैकेज का यूनीक नाम
      • APEX का वर्शन
      • एसडीवी 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. एक नया 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 मॉड्यूल बनाएं. एसडीवी पैकेज के नाम को, 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. एसडीवी इमेज में नया मेकफ़ाइल शामिल करने के लिए, प्रॉडक्ट मेकफ़ाइल में 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
    

सेवा बंडल की डिपेंडेंसी मैनेज करना

कुछ मामलों में, सेवा बंडल की डिपेंडेंसी को स्टैटिक तौर पर लिंक किया जा सकता है. इससे, 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 इंटिग्रेशन देखें.