Core code samples

The SDV Core services code samples in /system/software_defined_vehicle/samples enable you to start building your services. Each sample contains a README file describing the use case.

Sample directory overview

The following table lists the reference sample directories in system/software_defined_vehicle/samples and their corresponding documentation guides:

Sample directory Description Documentation guide
system/software_defined_vehicle/samples/quickstart End-to-end Rust service bundle sample demonstrating VSIDL publication, subscription, and RPC between Manager and Monitor bundles. Quick start: Create and execute SDV service bundles
system/software_defined_vehicle/samples/vsidl Reference VSIDL catalog, protobuf definitions, and service bundle implementation patterns. Implement business logic
system/software_defined_vehicle/samples/concal Client sample for reading and updating vehicle configuration and calibration parameters. Configuration and calibration
system/software_defined_vehicle/samples/health Health-monitored service bundle and quality-of-service (QoS) monitoring samples. Health monitoring
system/software_defined_vehicle/samples/oem_partition_update_client Sample service using the sdv_oem_updater crate to trigger and roll back /oem_ab partition updates. OEM AB partition updates
system/software_defined_vehicle/samples/sdv_gateway Native and Java IVI sample apps (NativeSdvGatewayTestApp and SdvCarMonitorTestApp) that communicate with SDV Core services through the SDV Gateway. Use the SDV Gateway on IVI
system/software_defined_vehicle/samples/telemetry On-device telemetry data source and simulator samples. Data sources
system/software_defined_vehicle/samples/apex APEX packaging, versioned service bundle updates, and key-verification samples. Build and deploy service bundles
system/software_defined_vehicle/samples/diagnostics OEM diagnostics provider and updatable diagnostics bundle samples. Diagnostics
system/software_defined_vehicle/samples/logging C++ and Rust structured logging, runtime log filtering, and service bundle logging samples. Use the logging API
system/software_defined_vehicle/samples/orchestration Orchestrated service bundle and custom mode state-transition samples. Orchestrator
system/software_defined_vehicle/samples/qos_scheduling Parallel CPU contention benchmark comparing normal and elevated scheduling presets. Scheduling
system/software_defined_vehicle/samples/service_bundles_registry Single-bundle, multi-bundle, C++, Rust, and manifest-validation APEX registration samples. Service bundle metadata
system/software_defined_vehicle/samples/some_ip External vsomeip virtual ECU and RPC middleware samples bridged to SDV Data Tunnel topics and RPC services through SomeIpBroker. Deployment
system/software_defined_vehicle/samples/tracing Rust tracing crate and C++ Perfetto SDK instrumentation samples and capture configs. Use tracing to gain insights into system performance
system/software_defined_vehicle/samples/update_manager Command-line client and reference guides for preparing, activating, and committing APEX updates. SDV Update Manager
system/software_defined_vehicle/samples/user_preferences Multi-user HVAC and HMI settings persistence and factory-reset sample bundles. User preferences
system/software_defined_vehicle/samples/vpm Vehicle Power Manager state machine and notification client samples. Power management
system/software_defined_vehicle/samples/vsidl_provider Per-bundle and shared runtime schema reflection samples for sdv_vsidl_provider_agent. VSIDL Provider for reflection

Use the logging API

To learn more about the instructions provided, see:

Basic log sample

logging.cpp demonstrates writing to the main log buffer and runtime assertion checks (CHECK_LE). For a short description of the available Android log buffers, see View alternative log buffers.

  • To run the sample with standard log output:

    /apex/com.android.sdv.sample.logging/bin/logging_sdv_sample
    
  • To pass a command-line argument and trigger the CHECK_LE(argc, 1) fatal assertion log:

    /apex/com.android.sdv.sample.logging/bin/logging_sdv_sample test
    

Structured logging sample

Sample file: structured_logging.cpp

  • To run the sample, which writes logs to the events log buffer:

    /apex/com.android.sdv.sample.logging/bin/structured_logging_sdv_sample
    

The event, security, and stats log buffers hold structured data rather than free text.

Structured data is logged using the event list API, which is always logged with INFO priority and the numeric tag ID.

A .logtags file can be defined with a logtags attribute in Android.bp. When provided, logcat uses this to derive the tag name from the numeric tag ID. The tag name can then be used for filtering structured logs. For details and a description of the file format, see the comment in the logcat event.logtags file.

During the build process, all logtags files are merged and placed into the /system/etc/event-log-tags file in the Android system image.

Compile a time log filtering sample

Sample file: compile_time_log_filtering.cpp

This sample contains macros you can adjust to remove some logs from the executable. See the source code for details.

Log filtering sample: log_filtering.cpp

  • To run the sample, setting the minimum log priority to WARNING:

    LOGLEVEL=WARNING /apex/com.android.sdv.sample.logging/bin/log_filtering_sdv_sample
    

Log filtering is affected by system properties. For all logs with :

  • log.tag.<tag>
  • persist.log.tag.<tag>

For all logs in the system:

  • log.tag
  • persist.log.tag

To select the chosen log level, which are checked in order, each value can be set to V, D, I, W, or E.

The effective log level is the level set on the first system property that has a value, which may be lower or higher than the log level set by app with a __android_log_set_minimum_priority call. When none of the properties are set, the level configured with __android_log_set_minimum_priority applies.

For details, see the Logging system overview.

  • Run the sample, setting the default log tag to example_tag:

    LOGTAG=example_tag /apex/com.android.sdv.sample.logging/bin/log_filtering_sdv_sample
    

The sample also contains a commented out LOG_TAG macro definition you can use to set the log tag for all log messages. The tag set in this way overrides the tag set at runtime with __android_log_set_default_tag.

If the LOG_TAG macro is not defined and the app does not call __android_log_set_default_tag, the default tag is the result of getprogname(). For example, the executable name.