Enable rust backend
Enable rust EVS HAL backend and add its empty implementation that
returns binder::StatusCode::UNKNOWN_ERROR for all API except deprecated
ultrasonic API.
Fix: 319475162
Test: Build android.hardware.automotive.evs-aidl-rust-service and
manually run it on cf_x86_64_auto lunch target.
Flag: EXEMPT HAL interface change
Change-Id: Ib9a1ee5fb224c114f57b6b6dca21d7b1cee005f0
diff --git a/automotive/evs/aidl/Android.bp b/automotive/evs/aidl/Android.bp
index dfb15c6..5b2f82f 100644
--- a/automotive/evs/aidl/Android.bp
+++ b/automotive/evs/aidl/Android.bp
@@ -44,6 +44,9 @@
ndk: {
min_sdk_version: "29",
},
+ rust: {
+ enabled: true,
+ },
},
versions_with_info: [
{
diff --git a/automotive/evs/aidl/rust_impl/Android.bp b/automotive/evs/aidl/rust_impl/Android.bp
new file mode 100644
index 0000000..ac8b90f
--- /dev/null
+++ b/automotive/evs/aidl/rust_impl/Android.bp
@@ -0,0 +1,30 @@
+/*
+ * 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.evs-aidl-rust-service",
+ relative_install_path: "hw",
+ vendor: true,
+ srcs: ["src/*.rs"],
+ crate_root: "src/main.rs",
+ vintf_fragments: ["manifest_evs-rust-service.xml"],
+ init_rc: ["evs-rust-service.rc"],
+ rustlibs: [
+ "android.hardware.automotive.evs-V2-rust",
+ "libbinder_rs",
+ "liblog_rust",
+ ],
+}
diff --git a/automotive/evs/aidl/rust_impl/README.md b/automotive/evs/aidl/rust_impl/README.md
new file mode 100644
index 0000000..bf00aed
--- /dev/null
+++ b/automotive/evs/aidl/rust_impl/README.md
@@ -0,0 +1,21 @@
+# Rust Skeleton EVS HAL implementation.
+
+WARNING: This is not a reference EVS HAL implementation and therefore does not
+provide any actual functionality.
+
+This folder contains a skeleton EVS HAL implementation in Rust to demonstrate
+how vendors could implement their EVS HAL in Rust. To compile and run this
+implementation, please include below package to the device build script:
+
+* `android.hardware.automotive.evs-aidl-rust-service`
+
+Please note that this service will attempt to register the service as
+`IEvsEnumerator/rust/0` and therefore is also required to be declared in the
+service context by adding below line to a proper `service_contexts` file:
+
+> android.hardware.automotive.evs.IEvsEnumerator/rust/0 u:object_r:hal_evs_service:s0
+
+This implementation intentionally returns `binder::StatusCode::UNKNOWN_ERROR`
+for any API call except deprecated API for ultrasonics; the process will be
+panicked on these methods instead. Hence, this implementation does not comply
+with VTS tests and vendors must replace each method with actual implementation.
diff --git a/automotive/evs/aidl/rust_impl/evs-rust-service.rc b/automotive/evs/aidl/rust_impl/evs-rust-service.rc
new file mode 100644
index 0000000..3741b21
--- /dev/null
+++ b/automotive/evs/aidl/rust_impl/evs-rust-service.rc
@@ -0,0 +1,8 @@
+service vendor.evs-hal-rust-default /vendor/bin/hw/android.hardware.automotive.evs-aidl-rust-service
+ class early_hal
+ priority -20
+ user graphics
+ group automotive_evs camera
+ onrestart restart cardisplayproxyd
+ onrestart restart evsmanagerd
+ disabled
diff --git a/automotive/evs/aidl/rust_impl/manifest_evs-rust-service.xml b/automotive/evs/aidl/rust_impl/manifest_evs-rust-service.xml
new file mode 100644
index 0000000..813cbb2
--- /dev/null
+++ b/automotive/evs/aidl/rust_impl/manifest_evs-rust-service.xml
@@ -0,0 +1,7 @@
+<manifest version="2.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.automotive.evs</name>
+ <version>2</version>
+ <fqname>IEvsEnumerator/rust/0</fqname>
+ </hal>
+</manifest>
diff --git a/automotive/evs/aidl/rust_impl/src/default_evs_hal.rs b/automotive/evs/aidl/rust_impl/src/default_evs_hal.rs
new file mode 100644
index 0000000..72b2d53
--- /dev/null
+++ b/automotive/evs/aidl/rust_impl/src/default_evs_hal.rs
@@ -0,0 +1,113 @@
+//
+// 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.
+//
+
+use android_hardware_automotive_evs::aidl::android::hardware::automotive::evs::{
+ CameraDesc::CameraDesc, DisplayState::DisplayState, IEvsCamera::IEvsCamera,
+ IEvsDisplay::IEvsDisplay, IEvsEnumerator::IEvsEnumerator,
+ IEvsEnumeratorStatusCallback::IEvsEnumeratorStatusCallback,
+ IEvsUltrasonicsArray::IEvsUltrasonicsArray, Stream::Stream,
+ UltrasonicsArrayDesc::UltrasonicsArrayDesc,
+};
+
+pub struct DefaultEvsHal {}
+
+impl binder::Interface for DefaultEvsHal {}
+
+impl IEvsEnumerator for DefaultEvsHal {
+ fn closeCamera(
+ &self,
+ _: &binder::Strong<(dyn IEvsCamera + 'static)>,
+ ) -> std::result::Result<(), binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn closeDisplay(
+ &self,
+ _: &binder::Strong<(dyn IEvsDisplay + 'static)>,
+ ) -> std::result::Result<(), binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn closeUltrasonicsArray(
+ &self,
+ _: &binder::Strong<(dyn IEvsUltrasonicsArray + 'static)>,
+ ) -> std::result::Result<(), binder::Status> {
+ unimplemented!()
+ }
+
+ fn getCameraList(&self) -> std::result::Result<std::vec::Vec<CameraDesc>, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn getDisplayIdList(&self) -> std::result::Result<std::vec::Vec<u8>, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn getDisplayState(&self) -> std::result::Result<DisplayState, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn getStreamList(
+ &self,
+ _: &CameraDesc,
+ ) -> std::result::Result<std::vec::Vec<Stream>, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn getUltrasonicsArrayList(
+ &self,
+ ) -> std::result::Result<std::vec::Vec<UltrasonicsArrayDesc>, binder::Status> {
+ unimplemented!()
+ }
+
+ fn isHardware(&self) -> std::result::Result<bool, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn openCamera(
+ &self,
+ _: &str,
+ _: &Stream,
+ ) -> std::result::Result<binder::Strong<(dyn IEvsCamera + 'static)>, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn openDisplay(
+ &self,
+ _: i32,
+ ) -> std::result::Result<binder::Strong<(dyn IEvsDisplay + 'static)>, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn openUltrasonicsArray(
+ &self,
+ _: &str,
+ ) -> std::result::Result<binder::Strong<(dyn IEvsUltrasonicsArray + 'static)>, binder::Status>
+ {
+ unimplemented!()
+ }
+
+ fn registerStatusCallback(
+ &self,
+ _: &binder::Strong<(dyn IEvsEnumeratorStatusCallback + 'static)>,
+ ) -> std::result::Result<(), binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+
+ fn getDisplayStateById(&self, _: i32) -> std::result::Result<DisplayState, binder::Status> {
+ Err(binder::StatusCode::UNKNOWN_ERROR.into())
+ }
+}
diff --git a/automotive/evs/aidl/rust_impl/src/main.rs b/automotive/evs/aidl/rust_impl/src/main.rs
new file mode 100644
index 0000000..df312c0
--- /dev/null
+++ b/automotive/evs/aidl/rust_impl/src/main.rs
@@ -0,0 +1,42 @@
+//
+// 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.
+//
+
+mod default_evs_hal;
+
+use crate::default_evs_hal::DefaultEvsHal;
+
+use android_hardware_automotive_evs::aidl::android::hardware::automotive::evs::IEvsEnumerator::BnEvsEnumerator;
+
+use log::info;
+
+fn main() {
+ binder::ProcessState::start_thread_pool();
+
+ let service = DefaultEvsHal {};
+
+ // Register HAL implementation as rust/0 instance.
+ let service_name = "android.hardware.automotive.evs.IEvsEnumerator/rust/0";
+ let service_binder = BnEvsEnumerator::new_binder(service, binder::BinderFeatures::default());
+
+ binder::add_service(service_name, service_binder.as_binder())
+ .expect(format!("Failed to register {}.", service_name).as_str());
+ info!("EVS Hardware Enumerator is ready");
+
+ binder::ProcessState::join_thread_pool();
+
+ // In normal operation, we don't expect the thread pool to exit.
+ info!("EVS Hardware Enumerator is shutting down");
+}