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
diff --git a/automotive/vehicle/Android.bp b/automotive/vehicle/Android.bp
index 3549519..e614937 100644
--- a/automotive/vehicle/Android.bp
+++ b/automotive/vehicle/Android.bp
@@ -25,3 +25,11 @@
         "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",
+    ],
+}
diff --git a/automotive/vehicle/aidl/rust_impl/README.md b/automotive/vehicle/aidl/rust_impl/README.md
new file mode 100644
index 0000000..33f996b
--- /dev/null
+++ b/automotive/vehicle/aidl/rust_impl/README.md
@@ -0,0 +1,12 @@
+# 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.
diff --git a/automotive/vehicle/aidl/rust_impl/vhal/Android.bp b/automotive/vehicle/aidl/rust_impl/vhal/Android.bp
new file mode 100644
index 0000000..46f37d8
--- /dev/null
+++ b/automotive/vehicle/aidl/rust_impl/vhal/Android.bp
@@ -0,0 +1,29 @@
+/*
+ * 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",
+    ],
+}
diff --git a/automotive/vehicle/aidl/rust_impl/vhal/src/default_vehicle_hal.rs b/automotive/vehicle/aidl/rust_impl/vhal/src/default_vehicle_hal.rs
new file mode 100644
index 0000000..1f5dc95
--- /dev/null
+++ b/automotive/vehicle/aidl/rust_impl/vhal/src/default_vehicle_hal.rs
@@ -0,0 +1,55 @@
+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())
+    }
+}
diff --git a/automotive/vehicle/aidl/rust_impl/vhal/src/main.rs b/automotive/vehicle/aidl/rust_impl/vhal/src/main.rs
new file mode 100644
index 0000000..59b248d
--- /dev/null
+++ b/automotive/vehicle/aidl/rust_impl/vhal/src/main.rs
@@ -0,0 +1,18 @@
+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()
+}
diff --git a/automotive/vehicle/aidl/rust_impl/vhal/vhal-rust-service.rc b/automotive/vehicle/aidl/rust_impl/vhal/vhal-rust-service.rc
new file mode 100644
index 0000000..dff9894
--- /dev/null
+++ b/automotive/vehicle/aidl/rust_impl/vhal/vhal-rust-service.rc
@@ -0,0 +1,4 @@
+service vendor.vehicle-hal-default /vendor/bin/hw/android.hardware.automotive.vehicle-V3-rust-service
+    class early_hal
+    user vehicle_network
+    group system inet
diff --git a/automotive/vehicle/aidl/rust_impl/vhal/vhal-rust-service.xml b/automotive/vehicle/aidl/rust_impl/vhal/vhal-rust-service.xml
new file mode 100644
index 0000000..b0c6ae7
--- /dev/null
+++ b/automotive/vehicle/aidl/rust_impl/vhal/vhal-rust-service.xml
@@ -0,0 +1,7 @@
+<manifest version="1.0" type="device">
+    <hal format="aidl">
+        <name>android.hardware.automotive.vehicle</name>
+        <version>3</version>
+        <fqname>IVehicle/default</fqname>
+    </hal>
+</manifest>