ตั้งค่า IDE สำหรับการพัฒนา SDV

Android Studio for Platform (ASfP) เป็นสภาพแวดล้อมในการพัฒนาซอฟต์แวร์แบบรวม (IDE) ที่แนะนำสำหรับการพัฒนาแพลตฟอร์ม Software-Defined Vehicle (SDV) ของ Android Automotive OS (AAOS) ASfP รองรับทุกภาษาที่แพลตฟอร์ม SDV ของ AAOS ใช้ รวมถึง Rust สำหรับแพ็กเกจบริการ SDV

หน้านี้ครอบคลุมเฉพาะการตั้งค่าที่เจาะจงสำหรับ SDV เท่านั้น ดูข้อมูลเพิ่มเติมเกี่ยวกับฟีเจอร์และเวิร์กโฟลว์ทั่วไปของ ASfP ได้ที่ Android Studio for Platform

ASfP ทำงานบน Linux 64 บิตที่มี CPU x86-64 เท่านั้น คุณสามารถใช้เครื่องมือนี้ในเวิร์กสเตชัน Linux ในเครื่องหรือในระบบคลาวด์ก็ได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับการตั้งค่าระบบคลาวด์ได้ที่การพัฒนาในระบบคลาวด์

ติดตั้ง ASfP

ASfP จะมีขนาดฮีปสูงสุด 30 GB โดยค่าเริ่มต้น การจัดทำดัชนีการชำระเงินของแพลตฟอร์มใช้หน่วยความจำจำนวนมาก โดยเฉพาะเมื่อคุณเรียกใช้อุปกรณ์ Cuttlefish แบบหลาย VM ในเครื่องเดียวกันด้วย จำกัดขอบเขตโปรเจ็กต์ไว้ที่ไดเรกทอรีที่คุณทำงานอยู่ และปรับขนาดฮีปสูงสุดในการตั้งค่าหน่วยความจำ ASfP หากจำเป็น

ASfP รองรับการอัปเดตใน IDE โดยอัตโนมัติ ดูข้อมูลเพิ่มเติมได้ที่อัปเดต Android Studio for Platform ดูข้อมูลเพิ่มเติมเกี่ยวกับการดาวน์โหลดและติดตั้ง ASfP รวมถึงการตรวจสอบข้อกำหนดของระบบได้ที่ติดตั้ง Android Studio for Platform

สร้างโปรเจ็กต์ SDV

เริ่มต้น ซิงค์ และสร้างการชำระเงิน SDV ของ AAOS ก่อนเริ่ม ดูข้อมูลเพิ่มเติมเกี่ยวกับการตั้งค่าการชำระเงินได้ที่ตำแหน่งโค้ดและดาวน์โหลด สร้าง และเรียกใช้

หากต้องการสร้างโปรเจ็กต์ SDV ให้ทำตามขั้นตอนต่อไปนี้

  1. สร้างโปรเจ็กต์ใหม่ใน ASfP และเลือกรูทของ Checkout AAOS SDV เป็น Checkout ของที่เก็บ ดูข้อมูลเพิ่มเติมเกี่ยวกับขั้นตอนของวิซาร์ดได้ที่หัวข้อสร้างหรือนำเข้าโปรเจ็กต์
  2. หลังจาก ASfP สร้างโปรเจ็กต์แล้ว ให้เลือก ASfP > Project > Open Config เพื่อเปิดไฟล์ .asfp-project
  3. แทนที่เนื้อหาของไฟล์ด้วยตัวอย่างต่อไปนี้ แล้วตั้งค่า repo เป็นเส้นทางของการชำระเงิน

    repo: /path/to/sdv_source
    lunch: sdv_core_cf-aosp_current-userdebug
    directories:
      include:
        -   system/software_defined_vehicle/samples
    other_languages:
      -   rust
    
  4. อัปเดตlunchและdirectoriesสำหรับพื้นที่ที่คุณทำงาน หากต้องการให้การจัดทำดัชนีและการซิงค์ทำงานได้อย่างรวดเร็ว ให้รวมเฉพาะไดเรกทอรีที่คุณแก้ไขอยู่เป็นประจำเท่านั้น ตารางต่อไปนี้แสดงเป้าหมายและไดเรกทอรี SDV ทั่วไป

    จุดมุ่งเน้นในการพัฒนา SDV เป้าหมาย lunch รายการ directories แนะนำ
    แพ็กเกจบริการ SDV sdv_core_cf-aosp_current-userdebug แคตตาล็อกบริการและไดเรกทอรีแพ็กเกจ เช่น system/software_defined_vehicle/samples
    การผสานรวมแพลตฟอร์มหลักของ SDV sdv_core_cf-aosp_current-userdebug system/software_defined_vehicle/middleware, system/software_defined_vehicle/automotive_services, device/google/sdv
    เกตเวย์ SDV ใน SDV IVI sdv_ivi_cf-aosp_current-userdebug system/software_defined_vehicle/sdv_gateway, system/software_defined_vehicle/samples/sdv_gateway, packages/services/Car
    ความปลอดภัยของจอแสดงผลในสื่อ SDV sdv_media_har_cf-aosp_current-userdebug packages/services/display_safety, device/google/sdv_display_safety
    ความปลอดภัยของจอแสดงผลใน IVI ของ SDV sdv_ivi_cf_ds-aosp_current-userdebug packages/apps/Car/DriverUI, packages/services/display_safety/service

    หากการชำระเงินใช้ไฟล์ Manifest trunk_staging ให้แทนที่ -aosp_current-userdebug ด้วย -trunk_staging-userdebug หากต้องการเรียกดูโค้ดแพลตฟอร์มเนทีฟด้วย ให้เพิ่ม cpp ลงใน other_languages ดูข้อมูลเพิ่มเติมเกี่ยวกับตัวเลือกการกำหนดค่าทั้งหมดได้ที่พารามิเตอร์การกำหนดค่า

  5. หากต้องการใช้การเปลี่ยนแปลง ให้เลือก ASfP > ซิงค์ > ซิงค์โปรเจ็กต์ ดูข้อมูลเพิ่มเติมเกี่ยวกับโหมดการซิงค์ (การซิงค์แบบเต็ม การซิงค์บางส่วน และการซิงค์แบบไม่บิลด์) และการส่งออกหรือนำเข้าเทมเพลต .asfp-project ที่แชร์ได้สำหรับทีมได้ที่หัวข้อโหมดการซิงค์และหน้าต่างเครื่องมือ Soong และเทมเพลตโปรเจ็กต์ที่แชร์ได้ (การส่งออกและนำเข้า)

ติดตั้งใช้งานแพ็กเกจบริการ SDV

ASfP มีปลั๊กอิน SDV ที่ติดตั้งใช้งาน APEX ซึ่งมีแพ็กเกจบริการของคุณไปยังอุปกรณ์ SDV ที่ทำงานอยู่โดยตรง ปลั๊กอินจะปิดใช้อยู่โดยค่าเริ่มต้น หากต้องการใช้ ให้เปิดใช้ปลั๊กอิน SDV ในการตั้งค่า > ปลั๊กอิน ดูข้อมูลเพิ่มเติมเกี่ยวกับแพ็กเกจ APEX ได้ที่สร้างและติดตั้งใช้งานแพ็กเกจบริการ

วิธีติดตั้งใช้งานจะขึ้นอยู่กับว่า APEX อยู่ในอุปกรณ์แล้วหรือไม่ ดังนี้

  • หากติดตั้ง APEX ไว้แล้ว คุณจะติดตั้งใช้งานการเปลี่ยนแปลงได้โดยตรงจาก ASfP
  • หาก APEX เป็นเวอร์ชันใหม่ คุณต้องสร้างและเปิดอิมเมจระบบอีกครั้งก่อน หรือใช้อิมเมจระบบที่มีคีย์ที่ใช้รับรอง APEX หลังจากนั้น คุณจะติดตั้งใช้งานจาก ASfP ได้

หากต้องการติดตั้งใช้งาน APEX ของแพ็กเกจบริการ ให้ทำตามขั้นตอนต่อไปนี้

  1. เริ่มใช้อุปกรณ์ SDV ด้วยปลั๊กอิน Cuttlefish ดูข้อมูลเพิ่มเติมได้ที่เรียกใช้อุปกรณ์ SDV ใน Cuttlefish
  2. เปิดไฟล์ apex/Android.bp ของแพ็กเกจบริการ แล้วคลิกไอคอนเรียกใช้ในแถบด้านข้างถัดจากบล็อก apex {
  3. ในเมนูที่เปิดขึ้น ให้เลือกเรียกใช้ "ติดตั้งใช้งาน APEX_NAME" นอกจากนี้ คุณยังสร้าง APEX โดยไม่ต้องติดตั้งใช้งานหรือเปลี่ยนการกำหนดค่าการเรียกใช้จากเมนูเดียวกันได้ด้วย

เรียกใช้อุปกรณ์ SDV บน Cuttlefish

ASfP มีปลั๊กอิน Cuttlefish ที่สร้างและเรียกใช้อุปกรณ์ Cuttlefish ในเครื่อง ปลั๊กอินต้องใช้ Cuttlefish Host Orchestrator หากไม่มี Orchestrator ของโฮสต์ ASfP จะแสดงวิธีการตั้งค่า

หากต้องการสร้างอุปกรณ์ SDV ให้ทำตามขั้นตอนต่อไปนี้

  1. เลือกเครื่องมือ > โปรแกรมจัดการอุปกรณ์ คลิก + แล้วเลือกสร้างอุปกรณ์ Cuttlefish
  2. หากต้องการสร้างการตั้งค่า VM หลายรายการ ให้เลือกจากการกำหนดค่า Canonical แล้วสร้างหรือนำเข้าการกำหนดค่าสำหรับการตั้งค่า เช่น SDV Core ที่มี SDV IVI หรือ SDV Media ที่มี SDV IVI สำหรับความปลอดภัยในการแสดงผล หากต้องการสร้าง VM รายการเดียว ให้เลือกจากการชำระเงินในโครงสร้างแหล่งที่มาของ Android ในเครื่องแทน

หากต้องการดูจอแสดงผล VM ทั้งหมดในหน้าจอเดียวและเข้าถึงตัวเลือกอุปกรณ์เพิ่มเติม ให้ใช้หน้าต่างเครื่องมือ Cuttlefish หากต้องการเปิด ให้เลือกไอคอน ... ในแผงด้านข้าง แล้วเลือก Cuttlefish หรือค้นหา Cuttlefish ในความช่วยเหลือ > ค้นหาการดำเนินการ นอกจากนี้ คุณยังดูจอแสดงผลแต่ละจอใน Running Devices ได้ด้วย เนื่องจาก SDV Core ทำงานโดยไม่มีจอแสดงผล ให้ใช้ Logcat และเทอร์มินัลเพื่อตรวจสอบ

แก้ไขข้อบกพร่องและทดสอบ

ASfP มีโปรแกรมแก้ไขข้อบกพร่อง LLDB ในตัวสำหรับโค้ด C++ และ Rust ดูข้อมูลเพิ่มเติมเกี่ยวกับการแก้ไขข้อบกพร่องและการทดสอบใน ASfP ได้ที่แก้ไขข้อบกพร่องของโค้ดแพลตฟอร์ม, แก้ไขข้อบกพร่องของโค้ด Rust, ทดสอบโค้ดแพลตฟอร์มด้วย atest และแก้ไขข้อบกพร่องของเป้าหมาย cc_test และ rust_test ภายใต้ LLDB

เมื่อแนบโปรแกรมแก้ไขข้อบกพร่องกับแพ็กเกจบริการ ให้แนบกับกระบวนการที่โฮสต์แพ็กเกจนั้น ชื่อกระบวนการใช้รูปแบบ <bundle_name>:<instance_name> เช่น OrchestratorSampleRustServiceBundle:sample-main-no-conditions คำสั่งต่อไปนี้จะแสดงรายการกระบวนการที่ตรงกันและรหัสกระบวนการ

adb shell ps -A | grep <bundle_name>

ดูข้อมูลเพิ่มเติมเกี่ยวกับเวิร์กโฟลว์การแก้ไขข้อบกพร่องของ SDV เช่น การเชื่อมต่อกับอุปกรณ์หลายเครื่องและการดูบันทึกได้ที่แก้ไขข้อบกพร่องของ SDV

แก้ไขไฟล์ VSIDL

ASfP มี VSIDL Language Server (vsidl-lsp) ดูข้อมูลเพิ่มเติมเกี่ยวกับวิธีตั้งค่าแคตตาล็อกสำหรับ Language Server ได้ที่การอัปเดตแคตตาล็อกอัตโนมัติและการผสานรวม LSP เมื่อแคตตาล็อกมีไฟล์ CATALOG_UPDATE เครื่องมือแก้ไขจะมีฟีเจอร์ต่อไปนี้สำหรับไฟล์ .vsidl

  • การตรวจสอบแบบเรียลไทม์: เครื่องมือแก้ไขจะไฮไลต์คีย์เวิร์ด VSIDL และแสดงข้อผิดพลาดทางไวยากรณ์ ประเภทที่ยังไม่ได้รับการแก้ไข และข้อผิดพลาดในการตรวจสอบ VSIDLC ในหน้าต่างปัญหา ดูข้อมูลเพิ่มเติมเกี่ยวกับกฎการตรวจสอบและรหัสข้อผิดพลาดได้ที่ข้อกำหนดภาษา VSIDL
  • การเติมข้อความอัตโนมัติและเอกสารประกอบ: คุณสามารถกด Ctrl+Space เพื่อดูคำแนะนำเกี่ยวกับคีย์เวิร์ด ข้อความ บริการ หัวข้อ และช่อง และกด Ctrl+Q เพื่อดูความคิดเห็นเกี่ยวกับเอกสารประกอบ
  • การไปยังส่วนต่างๆ และการจัดรูปแบบ: คุณสามารถกด Ctrl+B เพื่อไปยังคำจำกัดความของ .vsidl หรือ .proto, กด Alt+Shift+F7 เพื่อค้นหาข้อมูลอ้างอิง, กด Ctrl+F12 เพื่อดูโครงสร้างไฟล์ และกด Ctrl+Alt+L เพื่อจัดรูปแบบไฟล์

เพิ่มบริบท SDV สำหรับผู้ช่วย AI

ASfP มี AI ใน Android Studio และ Agent ในตัวพร้อมเครื่องมือบิลด์และatestของ Soong เนื่องจากไฟล์ AGENTS.md อยู่ร่วมกับซอร์สโค้ดในการควบคุมเวอร์ชัน คุณจึงแชร์กฎ SDV เดียวกันในเอเจนต์ในตัวของ ASfP และเอเจนต์การเขียนโค้ดที่อิงตามคอนเทนเนอร์หรือบรรทัดคำสั่งที่อ่าน AGENTS.md ได้ เมื่อคุณส่งพรอมต์โดยเปิดไฟล์ไว้ใน ASfP เอเจนต์จะโหลดไฟล์ AGENTS.md จากไดเรกทอรีของไฟล์นั้นและไดเรกทอรีระดับบน (เว้นแต่ไฟล์ GEMINI.md ในไดเรกทอรีเดียวกันจะมีความสำคัญเหนือกว่า) และคุณสามารถยืนยันไฟล์ที่ใช้งานอยู่ได้ในลิ้นชักบริบทของแผงแชทในส่วนไฟล์ AGENTS.md ดูข้อมูลเพิ่มเติมได้ที่ทำความรู้จัก Android Studio for Platform และปรับแต่ง Agent โดยใช้ไฟล์ AGENTS.md

เทมเพลตต่อไปนี้เป็นจุดเริ่มต้นสำหรับเวิร์กโฟลว์ในสร้างโปรเจ็กต์ SDV

แพ็กเกจบริการ SDV

วางไฟล์ AGENTS.md นี้ในไดเรกทอรีแพ็กเกจที่รวมอยู่ใน .asfp-project ซึ่งล้อมรอบโฟลเดอร์ catalog/, services/ และ apex/ ดูข้อมูลเพิ่มเติมได้ที่สร้างมิดเดิลแวร์, สร้างและติดตั้งใช้งานแพ็กเกจบริการ, เขียนไฟล์การแมป SOME/IP และภาพรวมการให้สิทธิ์การสื่อสาร SDV

# AAOS SDV service bundle and VSIDL rules

## Build and test
- Initialize the build environment (`source build/envsetup.sh` and
  `lunch sdv_core_cf-aosp_current-userdebug`) when running outside ASfP, build
  modules with Soong (`m <module_name>`), and run tests with
  `atest <TestModuleName>` (`rust_test`, `rust_test_host`, `cc_test`, or
  `python_test_host`), without creating `Cargo.toml` files or running `cargo`
- In catalog `Android.bp` files, avoid `defaults` on `rust_protobuf` modules
  (`vsidlc` uses a regex parser), include each `.proto` file in at most one
  `rust_protobuf` target, and cover all catalog files in the first `filegroup`
  (`srcs: ["**/*"]`)

## Protobuf, VSIDL, and AUTOSAR SOME/IP mapping conventions
- Keep `.proto` files limited to `message`, `enum`, and RPC `service` schemas
  (using `sdv/vsidl/v1/annotations.proto` only for field size bounds), without
  topic names, channel names, or queue capacities
- Write `.vsidl` files in TextProto `VsidlEntry` syntax (`package: "..."`,
  `service_bundle { name: "..." }`, `publisher` or `subscriber` with `message`
  and `topic`, and `server` or `client` with `service` and `channel`, without
  `import` statements; RPCs support unary, client-streaming, and
  server-streaming methods, not bidirectional streaming), and isolate
  `some_ip_mapping` (`sdv_type_mapping` and `someip_service_mapping` for
  AUTOSAR electronic control unit (ECU) `ARXML` or `vsomeip` IDs) or
  `vhal_mapping` rules in dedicated `.vsidl` mapping files so core bundles stay
  transport-independent
- Use `PascalCase` for `service_bundle` names (avoiding Rust, C++, and Java
  keywords), `snake_case` for `build_cfg.target_name`, a globally unique
  lowercase `package` with at least four segments (`com.<org>.sdv.<domain>`;
  never reuse platform-reserved `com.android.sdv.*` or sample `com.sdv.*`
  names), and lowercase dash-case starting with a letter (no consecutive or
  trailing hyphens, underscores, or slashes) for `topic`, `channel`, and
  instance names
- Set `capacity` on every `publisher` to an even integer greater than or equal
  to 2, and pair every `subscriber` and RPC `client` with a matching
  `publisher` or `server` in the catalog or its `-d` dependency catalogs

## Code generation, authorization, and APEX packaging
- Export `ANDROID_BUILD_TOP`, check `CATALOG_UPDATE` for catalog-relative
  `output_path` (such as `".."`), `dependency_catalog_paths` (`-d`), and
  `vsidlc_gen_args`, and run `vsidlc -c <catalog_dir> -o <output_dir>`; omit
  `--services` from `vsidlc_gen_args` and avoid `-p` (`--purge`) or
  `regenerator` when `output_path` holds handwritten `services/` code
- Leave generated files in `generated_rs/`, `apex/`, and `configs/` unmodified,
  and implement Rust logic in `services/<ServiceBundleName>/src/main.rs` (even
  though the initial `vsidlc --services` skeleton header says not to edit; C++
  bundles do not use `vsidlc` C++ codegen and instead use
  `libsdv_lifecycle_client_cpp`, `libsdv_comms_cpp`, and
  `sdv_service_bundle_metadata` with `native_library_path: "lib64/lib<so>.so"`
  in `sdv_service_bundles_manifest.textproto`)
- Keep communications authorization `.textproto` policies in `configs/` aligned
  with every `publisher`, `subscriber`, `server`, and `client` unit (omitting
  `capacity` inside manual authorization `.textproto` `publisher` entries) so
  Service Discovery does not reject endpoints at runtime
- In Rust bundles, wait for publisher or RPC server availability before
  creating subscribers or clients, stop active tasks in `on_stop`, and run
  blocking work in `tokio::spawn_blocking`
- Generate Rust service bundle APEXes with `vsidlc --apex` (`updatable: true`,
  `min_sdk_version: "35"`, and `product_specific: true` in `apex/Android.bp`,
  never `vendor: true` or `soc_specific: true`, with matching unique `name` and
  `version` >= 1 in `apex_manifest.json`), and do not set
  `supportsRebootlessUpdate: true` or run `adb install --force-non-staged`
  because SDV APEX updates require a reboot

เกตเวย์ SDV ใน SDV IVI

วางไฟล์ AGENTS.md นี้ในไดเรกทอรีโมดูลไคลเอ็นต์ IVI หรือ system/software_defined_vehicle/sdv_gateway/ ดูข้อมูลเพิ่มเติมได้ที่ใช้เกตเวย์ SDV ใน IVI

# AAOS SDV Gateway on SDV IVI rules

- Initialize the build environment (`source build/envsetup.sh` and
  `lunch sdv_ivi_cf-aosp_current-userdebug`) when running outside ASfP, build
  IVI modules with Soong (`m <module_name>`), and run verification with
  `atest <TestModuleName>`
- For native C or C++ IVI clients (including vehicle hardware abstraction layer
  (VHAL) integrations), link `libsdvgatewayclient`
  (`#include "libsdvgatewayclient.h"`) or `ISdvGateway`; for in-tree system Java
  or Kotlin clients, use `libsdvgatewayclient-java`,
  `libsdvgatewayclient-java-sdk.stubs`, `libsdvgatewayclient-java-sdk`, and
  `com.android.sdv.gateway.client`
- Start the Binder thread pool before calling `ASDVGateway_Client_new`, and
  call `ASDVGateway_Client_initComms` (or `SdvGatewayClient.initComms`) before
  any service discovery, data tunnel, or RPC calls
- Check `ASDVGateway_Client_isRpcAvailable` or
  `ASDVGateway_Client_isProcessBoundToSdvRpcNetworkInterface` before opening
  RPC sockets on early boot, treat `ASDVGateway_StatusCode_OK` with null
  `ASDVGateway_RpcCredentials_t` as insecure `UNLOCKED` boot mode, and free
  non-null credentials with `ASDVGateway_Client_deleteRpcCredentials`
- Grant `sdv_gateway_client_domain(<domain>)` in SELinux (do not add
  `binder_use` on `/vendor` daemons, which violates Treble `neverallow`; add
  `group inet` on native init services, and `INTERNET` plus
  `CONNECTIVITY_USE_RESTRICTED_NETWORKS` privapp permissions for system Java
  RPC clients)

ความปลอดภัยของจอแสดงผล

วางไฟล์ AGENTS.md นี้ใน packages/services/display_safety/ หรือไดเรกทอรีแอปแผงหน้าปัด ดูข้อมูลเพิ่มเติมได้ที่เริ่มต้นใช้งาน Display Safety, เลเยอร์นามธรรมของแพลตฟอร์ม HAR, ชุดเครื่องมือการออกแบบความปลอดภัย และ DriverUI

# AAOS Display Safety partner integration rules

- Display Safety spans two guest VMs with separate `lunch` targets: keep
  safety-critical telltales, gauges, camera views, chimes, and early-boot or
  fallback placeholders in the Rust high availability renderer (HAR) and safety
  monitor on SDV Media (`sdv_media_har_cf`), and build non-safety cluster UI on
  SDV IVI (`sdv_ivi_cf_ds`) using `ClusterHomeManager` (`Cluster2` rather than
  legacy `Cluster1`)
- Implement target OS and hardware subsystems (display, graphics, exterior view
  system (EVS) cameras, audio, user input, and vehicle signals) in a dedicated
  `har-platform-<target>` platform abstraction layer (PAL) crate implementing
  `har-platform-api` traits rather than modifying core `harry` framework crates,
  and verify PAL crates against the HAR platform test suite with `atest`
- Generate safety monitor configurations and telltale inspection artifacts from
  the serialized Automotive Design for Compose document and safety JSON mapping
  (`{"documents": [{"rootnode": "#...", "display_id": 1, "document_id": "...",`
  `"states": {"<signal>": "#<node_id>"}}]}`) using the safety design compiler
  rather than hardcoding telltale pixel coordinates
- Because the HAR display plane composites above Android IVI, ensure HAR clears
  the cluster viewport region to `alpha = 0.0` while valid `HeartbeatRequest`
  gRPC messages arrive from IVI, and set opaque pixels in custom HAR OpenGL ES
  surfaces to `alpha = 1.0` (`0xFF`)
- Initialize the build environment (`source build/envsetup.sh` and `lunch`) when
  running outside ASfP, integrate prebuilt cluster APKs into `sdv_ivi_cf_ds`
  through `DriverUIPrebuilt` (`overrides: ["DriverUIStubApp"]`), launch dual-VM
  Cuttlefish setups from ASfP or with `ds_toolkit launch`, pass `--user 0` to
  `adb shell am` cluster commands, and note that
  `adb shell dumpsys SurfaceFlinger` on SDV IVI inspects only Android layers
  rather than the overlying HAR plane