Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0b71c1f authored by Yu Shan's avatar Yu Shan
Browse files

Create a skeleton Rust VHAL.

This is to prove that rust VHAL can be built and can run. The
skeleton Rust VHAL will return UNKNOWN_ERROR for all APIs.

Test: m android.hardware.automotive.vehicle-V3-rust-service
Manually replace VHAL on emulator with Selinux policy manually
updated to allow rust VHAL.
Bug: 320320087

Change-Id: I7d2dab392bf2ef982001df10c9b602c5c75888f7
parent ead15a23
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -25,3 +25,11 @@ cc_defaults {
        "android.hardware.automotive.vehicle.property-V3-ndk",
    ],
}

rust_defaults {
    name: "VehicleHalInterfaceRustDefaults",
    rustlibs: [
        "android.hardware.automotive.vehicle-V3-rust",
        "android.hardware.automotive.vehicle.property-V3-rust",
    ],
}
+12 −0
Original line number Diff line number Diff line
# Rust Skeleton VHAL implementation.

WARNING: This is not a reference VHAL implementation and does not contain
any actual implementation.

This folder contains a skeleton VHAL implementation in Rust to demonstrate
how vendor may implement a Rust VHAL. To run this VHAL, include
`android.hardware.automotive.vehicle-V3-rust-service` in your image.

This implementation returns `StatusCode::UNKNOWN_ERROR` for all operations
and does not pass VTS/CTS. Vendor must replace the logic in
`default_vehicle_hal.rs` with the actual implementation.
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

rust_binary {
    name: "android.hardware.automotive.vehicle-V3-rust-service",
    relative_install_path: "hw",
    vendor: true,
    srcs: ["src/*.rs"],
    crate_root: "src/main.rs",
    defaults: ["VehicleHalInterfaceRustDefaults"],
    vintf_fragments: ["vhal-rust-service.xml"],
    init_rc: ["vhal-rust-service.rc"],
    rustlibs: [
        "libbinder_rs",
    ],
}
+55 −0
Original line number Diff line number Diff line
use android_hardware_automotive_vehicle::aidl::android::hardware::automotive::vehicle::{
    IVehicle::IVehicle,
    IVehicleCallback::IVehicleCallback,
    VehiclePropConfigs::VehiclePropConfigs,
    GetValueRequests::GetValueRequests,
    SetValueRequests::SetValueRequests,
    SubscribeOptions::SubscribeOptions,
};
use binder::{Interface, Result as BinderResult, StatusCode, Strong};

/// This struct is defined to implement IVehicle AIDL interface.
pub struct DefaultVehicleHal;

impl Interface for DefaultVehicleHal {}

impl IVehicle for DefaultVehicleHal {
    fn getAllPropConfigs(&self) -> BinderResult<VehiclePropConfigs> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }

    fn getPropConfigs(&self, _props: &[i32]) -> BinderResult<VehiclePropConfigs> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }

    fn getValues(
            &self, _callback: &Strong<dyn IVehicleCallback>, _requests: &GetValueRequests
        ) -> BinderResult<()> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }

    fn setValues(
            &self, _callback: &Strong<dyn IVehicleCallback>, _requests: &SetValueRequests
        ) -> BinderResult<()> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }

    fn subscribe(
            &self, _callback: &Strong<dyn IVehicleCallback>, _options: &[SubscribeOptions],
            _max_shared_memory_file_count: i32
        ) -> BinderResult<()> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }

    fn unsubscribe(
            &self, _callback: &Strong<dyn IVehicleCallback>, _prop_ids: &[i32]
        ) -> BinderResult<()> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }

    fn returnSharedMemory(
            &self, _callback: &Strong<dyn IVehicleCallback>, _shared_memory_id: i64
        ) -> BinderResult<()> {
        Err(StatusCode::UNKNOWN_ERROR.into())
    }
}
+18 −0
Original line number Diff line number Diff line
mod default_vehicle_hal;

use android_hardware_automotive_vehicle::aidl::android::hardware::automotive::vehicle::IVehicle::BnVehicle;
use crate::default_vehicle_hal::DefaultVehicleHal;

fn main() {
	binder::ProcessState::start_thread_pool();
	let my_service = DefaultVehicleHal;
	let service_name = "android.hardware.automotive.vehicle.IVehicle/default";
    let my_service_binder = BnVehicle::new_binder(
        my_service,
        binder::BinderFeatures::default(),
    );
    binder::add_service(service_name, my_service_binder.as_binder())
    		.expect(format!("Failed to register {}?", service_name).as_str());
    // Does not return.
    binder::ProcessState::join_thread_pool()
}
Loading