Create a skeleton Rust audio control HAL

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

Bug: 319474244
Flag: EXEMPT HAL interface change
Test: m android.hardware.automotive.audiocontrol-V4-rust-service

Change-Id: I64916b3eaa8410e0b137b5b34578710899f91324
diff --git a/automotive/audiocontrol/aidl/rust_impl/Android.bp b/automotive/audiocontrol/aidl/rust_impl/Android.bp
new file mode 100644
index 0000000..062d989
--- /dev/null
+++ b/automotive/audiocontrol/aidl/rust_impl/Android.bp
@@ -0,0 +1,32 @@
+/*
+ * 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.audiocontrol-V4-rust-service",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["src/*.rs"],
+    crate_root: "src/main.rs",
+    defaults: [
+        "latest_android_hardware_automotive_audiocontrol_rust",
+        "latest_android_hardware_audio_common_rust",
+    ],
+    vintf_fragments: ["audiocontrol-rust-service.xml"],
+    init_rc: ["audiocontrol-rust-service.rc"],
+    rustlibs: [
+        "libbinder_rs",
+    ],
+}
diff --git a/automotive/audiocontrol/aidl/rust_impl/README.md b/automotive/audiocontrol/aidl/rust_impl/README.md
new file mode 100644
index 0000000..ed22356
--- /dev/null
+++ b/automotive/audiocontrol/aidl/rust_impl/README.md
@@ -0,0 +1,13 @@
+# Rust Skeleton Audio Control HAL implementation.
+
+WARNING: This is not a reference audio control HAl implementation and does
+not contain any actual implementation.
+
+This folder contains a skeleton audio control HAL implementation in Rust to
+demonstrate  how vendor may implement a Rust audio control HAL. To run this
+audio control HAL, include
+`android.hardware.automotive.audiocontrol-V4-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_audio_control_hal.rs` with the actual implementation.
diff --git a/automotive/audiocontrol/aidl/rust_impl/audiocontrol-rust-service.rc b/automotive/audiocontrol/aidl/rust_impl/audiocontrol-rust-service.rc
new file mode 100644
index 0000000..88d180d
--- /dev/null
+++ b/automotive/audiocontrol/aidl/rust_impl/audiocontrol-rust-service.rc
@@ -0,0 +1,4 @@
+service vendor.audiocontrol-default /vendor/bin/hw/android.hardware.automotive.audiocontrol-service.example
+    class hal
+    user audioserver
+    group system
diff --git a/automotive/audiocontrol/aidl/rust_impl/audiocontrol-rust-service.xml b/automotive/audiocontrol/aidl/rust_impl/audiocontrol-rust-service.xml
new file mode 100644
index 0000000..e54c1d3
--- /dev/null
+++ b/automotive/audiocontrol/aidl/rust_impl/audiocontrol-rust-service.xml
@@ -0,0 +1,23 @@
+<!--
+  ~ 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.
+  -->
+
+<manifest version="2.0" type="device">
+    <hal format="aidl">
+        <name>android.hardware.automotive.audiocontrol</name>
+        <version>4</version>
+        <fqname>IAudioControl/default</fqname>
+    </hal>
+</manifest>
diff --git a/automotive/audiocontrol/aidl/rust_impl/src/default_audio_control_hal.rs b/automotive/audiocontrol/aidl/rust_impl/src/default_audio_control_hal.rs
new file mode 100644
index 0000000..ba0ca23
--- /dev/null
+++ b/automotive/audiocontrol/aidl/rust_impl/src/default_audio_control_hal.rs
@@ -0,0 +1,84 @@
+/*
+ * 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_audiocontrol::aidl::android::hardware::automotive::audiocontrol::{
+    AudioFocusChange::AudioFocusChange,
+    AudioGainConfigInfo::AudioGainConfigInfo,
+    DuckingInfo::DuckingInfo,
+    IAudioControl::IAudioControl,
+    IAudioGainCallback::IAudioGainCallback,
+    IFocusListener::IFocusListener,
+    IModuleChangeCallback::IModuleChangeCallback,
+    MutingInfo::MutingInfo,
+    Reasons::Reasons,
+};
+use android_hardware_audio_common::aidl::android::hardware::audio::common::PlaybackTrackMetadata::PlaybackTrackMetadata;
+use binder::{Interface, Result as BinderResult, StatusCode, Strong};
+
+/// This struct is defined to implement IAudioControl AIDL interface.
+pub struct DefaultAudioControlHal;
+
+impl Interface for DefaultAudioControlHal {}
+
+impl IAudioControl for DefaultAudioControlHal {
+    fn onAudioFocusChange(&self, _usage : &str, _zone_id : i32, _focus_change : AudioFocusChange
+        ) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn onDevicesToDuckChange(&self, _ducking_infos : &[DuckingInfo]) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn onDevicesToMuteChange(&self, _muting_infos : &[MutingInfo]) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn registerFocusListener(&self, _listener : &Strong<dyn IFocusListener>) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn setBalanceTowardRight(&self, _value : f32) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn setFadeTowardFront(&self, _value : f32) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn onAudioFocusChangeWithMetaData(&self, _playback_metadata : &PlaybackTrackMetadata,
+            _zone_id : i32, _focus_change : AudioFocusChange) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn setAudioDeviceGainsChanged(&self, _reasons : &[Reasons], _gains : &[AudioGainConfigInfo]
+        ) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn registerGainCallback(&self, _callback : &Strong<dyn IAudioGainCallback>
+        ) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn setModuleChangeCallback(&self, _callback : &Strong<dyn IModuleChangeCallback>
+        ) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+
+    fn clearModuleChangeCallback(&self) -> BinderResult<()> {
+        Err(StatusCode::UNKNOWN_ERROR.into())
+    }
+}
diff --git a/automotive/audiocontrol/aidl/rust_impl/src/main.rs b/automotive/audiocontrol/aidl/rust_impl/src/main.rs
new file mode 100644
index 0000000..2ed4810
--- /dev/null
+++ b/automotive/audiocontrol/aidl/rust_impl/src/main.rs
@@ -0,0 +1,33 @@
+/*
+ * 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_audio_control_hal;
+
+use android_hardware_automotive_audiocontrol::aidl::android::hardware::automotive::audiocontrol::IAudioControl::BnAudioControl;
+use crate::default_audio_control_hal::DefaultAudioControlHal;
+
+fn main() {
+    binder::ProcessState::start_thread_pool();
+    let my_service = DefaultAudioControlHal;
+    let service_name = "android.hardware.automotive.audiocontrol.IAudioControl/default";
+    let my_service_binder = BnAudioControl::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()
+}