Sau khi tạo phần mềm trung gian và viết mã tuỳ chỉnh, bạn có thể triển khai các gói dịch vụ dưới dạng tệp APEX.
Tạo tệp cấu hình SDV:
Rust
Tạo tệp cấu hình SDV bằng cách chạy:
vsidlc -c /path/to/catalog -o /path/to/output --apexViệc chạy
vsidlcbằng cờ--apexsẽ tự động tạo tất cả các tệp cấu hình cần thiết, bao gồm:- Tệp kê khai APEX (
apex_manifest.json) - Tệp kê khai siêu dữ liệu SDV (
sdv_service_bundles_manifest.textproto) - Cấu hình trình liên kết (
linker.config.json) - Ngữ cảnh tệp SELinux (
file_contexts) - Khoá công khai và khoá riêng tư (
.avbpubkeyvà.pem) - Khai báo quyền và cấu hình điều phối
- Tệp
Android.bpxác định tất cả các mô-đun Soong cần thiết.
Bạn có thể tìm thấy các cấu hình đã tạo trong phần:
/path/to/output/apex/và,
/path/to/output/configs/- Tệp kê khai APEX (
C++
Tạo tệp kê khai siêu dữ liệu SDV,
service_bundle.manifest.textprotocó các trường siêu dữ liệu thực thi thiết yếu sau:- Tên của dịch vụ theo quy ước đặt tên
- Biểu thị số nguyên và chuỗi của phiên bản gói dịch vụ
- Đường dẫn đến thư viện đã tạo trước đó
Bạn bắt buộc phải chuẩn bị siêu dữ liệu gói dịch vụ thiết yếu để đóng gói và triển khai gói dịch vụ.
# 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" }Tạo một tệp cấu hình trình liên kết mới,
linker.config.json:{ "visible": true }Tạo một tệp
apex_manifest.jsonmới có các trường sau:- Tên gói SDV duy nhất
- Phiên bản của APEX
- Phụ thuộc vào các thư viện 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" ] }Tạo khoá công khai
apex_name.apex_key.avbpubkeyvà khoá riêng tưapex_name.apex_key.pem.Tạo ngữ cảnh tệp SELinux mới
apex_file_contexts.(/.*)? u:object_r:system_file:s0Để tìm hiểu thêm, hãy xem phần Bối cảnh và danh mục bảo mật.
Tạo các mục tiêu được tạo sẵn trong một tệp
Android.bpmới hoặc hiện có:// 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", }Tạo một mô-đun APEX mới trong tệp
Android.bpmới hoặc hiện có. Sử dụng tên gói SDV làm tên mô-đun 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, }
Để đưa makefile mới vào hình ảnh SDV, hãy thêm mô-đun APEX mới vào
PRODUCT_PACKAGEStrong makefile sản phẩm. Ví dụ: xemsdv_samples_core_services.mk.Nếu bạn đang sử dụng Cuttlefish, hãy chạy lệnh sau để khởi động một thiết bị:
sdv-cf create --instance_name=instance1Chạy gói dịch vụ khi hệ thống khởi động:
# 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
Quản lý phần phụ thuộc gói dịch vụ
Trong một số trường hợp, bạn có thể sử dụng tính năng liên kết tĩnh của các phần phụ thuộc gói dịch vụ để giảm kích thước APEX và mức sử dụng bộ nhớ của gói dịch vụ, đồng thời cải thiện thời gian khởi động của các gói dịch vụ. Các trường hợp này bao gồm APEX có:
- Gói dịch vụ đơn lẻ
- Một số gói dịch vụ không có nhiều phần phụ thuộc chung
Để bật tính năng liên kết tĩnh, hãy thêm các thuộc tính sau vào định nghĩa thư viện gói dịch vụ:
// 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"],
}
Trong mỗi trường hợp, bạn nên xác nhận rằng việc liên kết tĩnh với các phần phụ thuộc sẽ giúp cải thiện mức sử dụng bộ nhớ và thời gian khởi động của các gói dịch vụ.
Gỡ lỗi (dumpsys)
Trình quản lý vòng đời triển khai giao diện dumpsys. Giao diện này hiển thị cho người dùng danh sách các gói dịch vụ ở trạng thái created hoặc started. Giao diện này cũng hiển thị FQIN hoặc UID của quy trình gói dịch vụ.
Để xem trạng thái và giá trị nhận dạng hiện tại của các gói dịch vụ, hãy thực thi:
# Grant root access.
adb root
# Execute dumpsys to see service bundles state
adb shell dumpsys google.sdv.lifecycle.ILifecycleManager/default
Các bước tiếp theo
Để tự động thực thi vsidlc và cho phép trình bổ trợ IDE hoạt động với các phần phụ thuộc, hãy xem phần Tự động cập nhật danh mục và tích hợp LSP.