# nkh-lab/aosp-ncar-vehicle-hal architecture

> Architecture diagram of the GitHub repository nkh-lab/aosp-ncar-vehicle-hal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nkh-lab/aosp-ncar-vehicle-hal
- Repository: https://github.com/nkh-lab/aosp-ncar-vehicle-hal

## Overview

##### Project type and purpose
- This is an Android-based Vehicle Hardware Abstraction Layer (VHAL) example project for AOSP.
- It provides a dummy implementation of Google’s SYSTEM vehicle properties (HIDL v2.0) plus an extension with custom VENDOR properties (HIDL v1.0).
- The service simulates certain property values via timers or by reading Android system properties, exposing them to Car API clients over Android’s Binder IPC.

##### File structure
- Top level:
– 1.0/Types and build files for the VENDOR‐defined HAL interface (types.hal, Android.bp).
– README.md, vehicle-hal.mk for legacy Make-based builds.
– doc/screenshots for UI examples.
- impl/:
– Android.bp defines the HIDL service module (vendor.nlab.vehicle@1.0-service).
– sepolicy/ for SELinux rules (file_contexts + .te).
– src/:
- VehicleHalImpl.{cpp,h}: the core HIDL service implementation.
- VehicleHalClient.{cpp,h}: client‐side stub for internal calls (if any).
- VehicleService.cpp: the entry point that registers the HIDL service with init.
- hw-clients/Simulator.cpp: simulation backend that generates or updates property values.
- utils/Runnable.h: helper for threading/timers.
– vendor.nlab.vehicle@1.0-service.{rc,xml}: init and manifest entries to start the HAL service at boot.
- vehicle-hal.mk: legacy Android build integration.

##### README for additional insights
- Confirms separation of SYSTEM vs. VENDOR properties and simulation approach.
- Points to how consumers (e.g., CAR API Hello World app) invoke the HAL.
- Mentions related projects (AOSP manifest, device, and sample apps) but those are external.

##### Elements
– Client → Binder → HAL Service → Simulator/SystemProp → HAL Service → Binder → Client.
– Init → HAL Service (startup path).
– Android framework components (e.g., binder driver, init).
– HAL interface definitions vs. implementation.
– Internal simulation modules.
– External configuration source (Android system properties).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Android Framework Layer
    subgraph "Android Framework" 
        direction TB
        CarApiClient["Car API Client"]:::framework
        BinderDriver["Binder Driver"]:::framework
        SystemProps["Android System Properties"]:::config
        Init["Android init (RC)"]:::framework
    end

    %% HAL Interface Definitions
    subgraph "HAL Interface Definitions"
        direction TB
        SYSTEMIface["SYSTEM Vehicle HIDL v2.0"]:::interface
        VENDORIface["VENDOR Vehicle HIDL v1.0"]:::interface
        VENDORTypes["types.hal"]:::build
    end

    %% HAL Service Process
    subgraph "VENDOR HAL Service Process\n(vendor.nlab.vehicle@1.0-service)" 
        direction TB
        VehicleService["VehicleService.cpp"]:::implementation
        VehicleHalImplCPP["VehicleHalImpl.cpp"]:::implementation
        VehicleHalImplH["VehicleHalImpl.h"]:::implementation
        VehicleHalClientCPP["VehicleHalClient.cpp"]:::implementation
        VehicleHalClientH["VehicleHalClient.h"]:::implementation
        SimulatorCPP["Simulator.cpp"]:::implementation
        SimulatorH["Simulator.h"]:::implementation
        RunnableH["Runnable.h"]:::implementation
        RC["vendor.nlab.vehicle@1.0-service.rc"]:::config
        XML["vendor.nlab.vehicle@1.0-service.xml"]:::config
    end

    %% Policy and Build Files
    subgraph "Build & Policy"
        direction TB
        SoongHAL["impl/Android.bp"]:::build
        SoongIface["1.0/Android.bp"]:::build
        LegacyMake["vehicle-hal.mk"]:::build
        FileCtx["file_contexts"]:::policy
        TEPolicy["hal_vehicle_nlab.te"]:::policy
    end

    %% Connections
    CarApiClient -->|"calls via Binder"| BinderDriver
    BinderDriver -->|"IPC to service"| VehicleService
    Init -->|"starts"| VehicleService
    FileCtx -->|"SELinux rules applied to"| VehicleService
    TEPolicy -->|"SELinux allows"| VehicleService
    VehicleService -->|"invokes methods on"| VehicleHalImplCPP
    VehicleHalImplCPP -->|"uses stub"| VehicleHalClientCPP
    VehicleHalImplCPP -->|"retrieves data from"| SimulatorCPP
    SimulatorCPP -->|"schedules via"| RunnableH
    VehicleHalImplCPP -->|"reads config from"| SystemProps
    VehicleHalImplCPP -->|"responds via Binder"| BinderDriver
    BinderDriver -->|"returns to"| CarApiClient

    SoongHAL --> VehicleService
    SoongHAL --> VehicleHalImplCPP
    SoongIface --> VENDORTypes
    SoongIface --> VENDORIface
    LegacyMake --> VehicleService
    LegacyMake --> VENDORTypes

    SYSTEMIface -.-> VENDORTypes

    %% Click Events
    click VENDORTypes "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/1.0/types.hal"
    click SoongIface "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/1.0/Android.bp"
    click SoongHAL "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/Android.bp"
    click FileCtx "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/tree/master/impl/sepolicy/file_contexts"
    click TEPolicy "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/sepolicy/hal_vehicle_nlab.te"
    click VehicleService "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/VehicleService.cpp"
    click VehicleHalImplCPP "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/VehicleHalImpl.cpp"
    click VehicleHalImplH "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/VehicleHalImpl.h"
    click VehicleHalClientCPP "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/VehicleHalClient.cpp"
    click VehicleHalClientH "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/VehicleHalClient.h"
    click SimulatorCPP "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/hw-clients/Simulator.cpp"
    click SimulatorH "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/hw-clients/Simulator.h"
    click RunnableH "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/src/utils/Runnable.h"
    click RC "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/vendor.nlab.vehicle@1.0-service.rc"
    click XML "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/impl/vendor.nlab.vehicle@1.0-service.xml"
    click LegacyMake "https://github.com/nkh-lab/aosp-ncar-vehicle-hal/blob/master/vehicle-hal.mk"

    %% Styles
    classDef framework fill:#AEDFF7,stroke:#036fab,color:#000
    classDef interface fill:#FDE68A,stroke:#B45309,color:#000
    classDef implementation fill:#C7F9CC,stroke:#15803D,color:#000
    classDef build fill:#E0E7FF,stroke:#4338CA,color:#000
    classDef policy fill:#FFCCCC,stroke:#DC2626,color:#000
    classDef config fill:#FFF4E5,stroke:#D97706,color:#000
```
