क्विक स्टार्ट: एसडीवी सेवा बंडल बनाना और उन्हें लागू करना

इस पेज पर, एसडीवी सर्विस बंडल बनाने, उसे APEX फ़ाइल फ़ॉर्मैट में पैक करने, और वर्चुअल Cuttlefish डिवाइस पर उसे चलाने का तरीका बताया गया है. एसडीवी सिस्टम पर कोड एक्ज़ीक्यूशन की मुख्य इकाइयां, सर्विस बंडल होती हैं. सर्विस बंडल, लाइफ़साइकल के ऐसे तरीके उपलब्ध कराते हैं जिन्हें सिस्टम की स्थिति बदलने पर सिस्टम लागू करता है.

  1. अपना बिल्ड एनवायरमेंट सेट अप करना

    अपनी वर्किंग डायरेक्ट्री में, envsetup.sh स्क्रिप्ट को सोर्स करें, ताकि बिल्ड एनवायरमेंट सेट अप किया जा सके. साथ ही, Cuttlefish को बिल्ड टारगेट के तौर पर सेट किया जा सके और vsidlc कोड जनरेटर को बिल्ड किया जा सके:

    source build/envsetup.sh
    lunch sdv_core_cf-aosp_current-userdebug
    m vsidlc
    
  2. इन फ़ाइलों के साथ my_catalog नाम का फ़ोल्डर बनाकर, अपना आर्किटेक्चर तय करें:

    • tire.proto: इससे उस डेटा स्ट्रक्चर के बारे में पता चलता है जिसे भेजा जा रहा है:

      syntax = "proto3";
      
      package com.android.sdv.sample.quickstart;
      
      import "google/protobuf/empty.proto";
      import "sdv/vsidl/v1/annotations.proto";
      
      message TirePressure {
        uint32 pressure = 1;
      }
      
      message TireInfoResponse {
        string serial_number = 1;
        uint32 max_pressure = 2;
      }
      
      service TireService {
        rpc GetTireInfo(google.protobuf.Empty) returns (TireInfoResponse);
      }
      
    • architecture.vsidl: यह सेवा बंडल और उनके कम्यूनिकेशन को तय करता है. Android Studio for Platform में सिंटैक्स हाइलाइट करने, पुष्टि करने, और ऑटोकंप्लीट की सुविधा के लिए, VSIDL फ़ाइलों में बदलाव करना लेख पढ़ें:

      package: "com.android.sdv.sample.quickstart"
      
      service_bundle {
        name: "Manager"
      
        publisher {
          message: "TirePressure"
          topic: "pressure"
          capacity: 8
        }
      
        server {
          service: "TireService"
          channel: "tire-service"
        }
      }
      
      service_bundle {
        name: "Monitor"
      
        subscriber {
          message: "TirePressure"
          topic: "pressure"
        }
      
        client {
          service: "TireService"
          channel: "tire-service"
        }
      }
      
    • Android.bp: इससे बिल्ड प्रोसेस के बारे में पता चलता है:

      rust_protobuf {
          name: "libquickstart_sample_tire_proto",
          crate_name: "quickstart_sample_tire_proto",
          protos: [
              "tire.proto",
          ],
          source_stem: "quickstart_sample_tire_proto_source",
          rustlibs: [
              "libvsidl_v1_stdlib_proto_rs",
          ],
          proto_flags: [
              "-I external/protobuf/src",
          ],
          vendor_available: true,
          product_available: true,
          apex_available: [
              "//apex_available:platform",
              "//apex_available:anyapex",
          ],
          min_sdk_version: "35",
      }
      
      filegroup {
          name: "vsidl_quickstart_catalog",
          srcs: ["**/*"],
      }
      
  3. स्केलेटन इंप्लिमेंटेशन और कॉन्फ़िगरेशन फ़ाइलें जनरेट करने के लिए, यह कमांड चलाएं:

    vsidlc -c /path/to/catalog -o /path/to/output --services --apex
    
  4. हर सर्विस बंडल के लिए, /path/to/output/services/ServiceBundleName/src/main.rs में Rust इंप्लिमेंटेशन ढूंढें.

  5. डिफ़ॉल्ट रूप से, जनरेट किया गया लागू करने का तरीका, डिफ़ॉल्ट वैल्यू वाले मैसेज बनाता है. साथ ही, उन्हें पब्लिशर और सदस्यों या आरपीसी क्लाइंट और सर्वर के बीच भेजता है. इस व्यवहार में बदलाव करने के लिए, main.rs में TODO टिप्पणियां देखें और उन्हें अपनी पसंद के मुताबिक अडजस्ट करें. उदाहरण के लिए:

    rust async fn handle_tire_pressure_pressure_publisher(publisher: sdv::mw::Publisher<TirePressure>) { loop { // TODO: Modify the frequency of publishing messages here. sleep(Duration::from_secs(1)).await; // TODO: Modify the message content here. let message = TirePressure::default(); info!("Publishing on TirePressure#PRESSURE"); publisher.publish(&message).unwrap(); } }

  6. सिस्टम इमेज में अपना बंडल शामिल करने के लिए, जनरेट किए गए APEX मॉड्यूल का नाम अपने प्रॉडक्ट की मेकफ़ाइल में जोड़ें.

    1. अपनी प्रॉडक्ट मेकफ़ाइल खोलें. उदाहरण के लिए, device/google/sdv/sdv_core_base/sdv_samples_core_services.mk.

    2. PRODUCT_PACKAGES में मॉड्यूल जोड़ने के लिए, यह जोड़ें:

      PRODUCT_PACKAGES += com.android.sdv.sample.quickstart
      PRODUCT_PACKAGES += com_android_sdv_sample_quickstart_orchestration_configurations
      
  7. शुरुआती सिस्टम इमेज बनाएं, ताकि डिवाइस में नया APEX और उसकी साइनिंग कुंजी शामिल हो:

    m
    

    जब सिस्टम इमेज में APEX शामिल होता है (या /product/etc/brand_new_apex/ में इसकी सार्वजनिक साइनिंग कुंजी पहले से इंस्टॉल होती है), तो आपको APEX में होने वाले बदलावों (सर्विस बंडल कोड और बंडल-स्कोप वाले कॉन्फ़िगरेशन; vm_quickstart_orch_config.textproto जैसी /system/etc/orch/ फ़ाइलों में बदलाव करने के लिए, अब भी m के साथ सिस्टम इमेज को फिर से बनाना ज़रूरी है) के लिए, पूरी सिस्टम इमेज को फिर से बनाने की ज़रूरत नहीं होती. Android Studio for Platform में apex/Android.bp गटर आइकॉन से, बार-बार होने वाले APEX अपडेट डिप्लॉय किए जा सकते हैं. इसके अलावा, apex_manifest.json में "version" को बढ़ाया जा सकता है, सिर्फ़ अपना APEX मॉड्यूल (m com.android.sdv.sample.quickstart) बनाया जा सकता है, और अपडेट किए गए APEX को adb पर स्टेज किया जा सकता है. ज़्यादा जानकारी के लिए, एसडीवी सर्विस बंडल डिप्लॉय करना और डेवलपमेंट के दौरान सर्विस बंडल को तेज़ी से अपडेट करना लेख पढ़ें.

  8. सर्विस बंडल को चलाएं और उसकी पुष्टि करें:

    1. वर्चुअल Cuttlefish डिवाइस चालू करें:

      sdv-cf create --instance_name=instance1
      
    2. सिस्टम के चालू होने पर, सर्विस बंडल को चलाएं:

      • मैन्युअल तरीके से:

        adb wait-for-device
        adb root
        adb shell sdv_service_bundle start local-vm:com.android.sdv.sample.quickstart.Manager/instance
        adb shell sdv_service_bundle start local-vm:com.android.sdv.sample.quickstart.Monitor/instance
        
      • ऑर्केस्ट्रेटर का इस्तेमाल करना:

        adb wait-for-device
        adb root
        # Apply global orchestration configuration by setting system property
        adb shell setprop persist.sdv.orchestrator_config_path "etc/orch/vm_quickstart_orch_config.textproto"
        adb reboot
        
    3. सेवा बंडल के लागू होने की पुष्टि करें:

      adb logcat *:F com_android_sdv_sample_quickstart_Manager_instance:* com_android_sdv_sample_quickstart_Monitor_instance:*
      

      यह कमांड, मैसेज एक्सचेंज करने वाले सर्विस बंडल के लॉग दिखाता है:

      03-30 13:41:31.505   967   976 I com_android_sdv_sample_quickstart_Manager_instance: sdv_lm_manager: Publishing on TirePressure#PRESSURE
      03-30 13:41:31.505   983   991 I com_android_sdv_sample_quickstart_Monitor_instance: sdv_lm_monitor: Received message on TirePressure#PRESSURE: [TirePressure { pressure: 0, special_fields: SpecialFields { unknown_fields: UnknownFields { fields: None }, cached_size: CachedSize { size: 0 } } }]
      03-30 13:41:31.626   983   991 I com_android_sdv_sample_quickstart_Monitor_instance: sdv_lm_monitor: Sending request on Monitor/TireService
      03-30 13:41:31.627   967   976 I com_android_sdv_sample_quickstart_Manager_instance: sdv_lm_manager: Received request on Manager/TireService: Empty { special_fields: SpecialFields { unknown_fields: UnknownFields { fields: None }, cached_size: CachedSize { size: 0 } } }
      03-30 13:41:31.627   983   991 I com_android_sdv_sample_quickstart_Monitor_instance: sdv_lm_monitor: Received response on Monitor/TireService: TireInfoResponse { serial_number: "", max_pressure: 0, special_fields: SpecialFields { unknown_fields: UnknownFields { fields: None }, cached_size: CachedSize { size: 0 } } }
      

अगला कदम क्या है

Vehicle Services Interface Definition Language (VSIDL) के बारे में ज़्यादा जानें. साथ ही, अपने सर्विस बंडल को नए सिरे से तय करने का तरीका जानें.