Define skeleton code of vmnic(Virtual Machine Network Interface Creator)

Purpose of this change is to define skeleton code of vmnic, so that
com.android.virt APEX contain the initial version of vmnic rust binary
with flag guarding. Vmnic called by other components is the scope of
following change, not this one.

Bug: 340376951
Test: adb shell ls /apex/com.android.virt/bin
Change-Id: Ic389944ecf4a98568a4d1771778844dbadeb2bf3
diff --git a/virtualizationservice/aidl/android/system/virtualizationservice_internal/IVmnic.aidl b/virtualizationservice/aidl/android/system/virtualizationservice_internal/IVmnic.aidl
new file mode 100644
index 0000000..3796763
--- /dev/null
+++ b/virtualizationservice/aidl/android/system/virtualizationservice_internal/IVmnic.aidl
@@ -0,0 +1,25 @@
+/*
+ * Copyright 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.
+ */
+package android.system.virtualizationservice_internal;
+
+interface IVmnic {
+    /**
+     * Create TAP network interface for a VM.
+     * @param CID of VM.
+     * @return file descriptor of the TAP network interface.
+     */
+    ParcelFileDescriptor createTapInterface(int cid);
+}
diff --git a/virtualizationservice/vmnic/Android.bp b/virtualizationservice/vmnic/Android.bp
new file mode 100644
index 0000000..4313a82
--- /dev/null
+++ b/virtualizationservice/vmnic/Android.bp
@@ -0,0 +1,21 @@
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+rust_binary {
+    name: "vmnic",
+    crate_name: "vmnic",
+    defaults: ["avf_build_flags_rust"],
+    edition: "2021",
+    srcs: ["src/main.rs"],
+    prefer_rlib: true,
+    rustlibs: [
+        "android.system.virtualizationservice_internal-rust",
+        "libandroid_logger",
+        "libanyhow",
+        "libbinder_rs",
+        "liblog_rust",
+    ],
+    apex_available: ["com.android.virt"],
+    init_rc: ["vmnic.rc"],
+}
diff --git a/virtualizationservice/vmnic/src/aidl.rs b/virtualizationservice/vmnic/src/aidl.rs
new file mode 100644
index 0000000..26a0eff
--- /dev/null
+++ b/virtualizationservice/vmnic/src/aidl.rs
@@ -0,0 +1,37 @@
+// Copyright 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.
+
+//! Implementation of the AIDL interface of Vmnic.
+
+use anyhow::anyhow;
+use android_system_virtualizationservice_internal::aidl::android::system::virtualizationservice_internal::IVmnic::IVmnic;
+use binder::{self, ExceptionCode, Interface, IntoBinderResult, ParcelFileDescriptor};
+
+#[derive(Debug, Default)]
+pub struct Vmnic {}
+
+impl Vmnic {
+    pub fn init() -> Vmnic {
+        Vmnic::default()
+    }
+}
+
+impl Interface for Vmnic {}
+
+impl IVmnic for Vmnic {
+    fn createTapInterface(&self, _cid: i32) -> binder::Result<ParcelFileDescriptor> {
+        Err(anyhow!("Creating TAP network interface is not supported yet"))
+            .or_binder_exception(ExceptionCode::UNSUPPORTED_OPERATION)
+    }
+}
diff --git a/virtualizationservice/vmnic/src/main.rs b/virtualizationservice/vmnic/src/main.rs
new file mode 100644
index 0000000..8c73c40
--- /dev/null
+++ b/virtualizationservice/vmnic/src/main.rs
@@ -0,0 +1,44 @@
+// Copyright 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.
+
+//! Android Vmnic (Virtual Machine Network Interface Creator)
+
+mod aidl;
+
+use crate::aidl::Vmnic;
+use android_logger::Config;
+use android_system_virtualizationservice_internal::aidl::android::system::virtualizationservice_internal::IVmnic::{
+    BnVmnic,
+    BpVmnic,
+    IVmnic,
+};
+use binder::{register_lazy_service, BinderFeatures, ProcessState};
+use log::{info, LevelFilter};
+
+const LOG_TAG: &str = "Vmnic";
+
+fn main() {
+    android_logger::init_once(
+        Config::default()
+            .with_tag(LOG_TAG)
+            .with_max_level(LevelFilter::Info)
+            .with_log_buffer(android_logger::LogId::System),
+    );
+
+    let service = Vmnic::init();
+    let service = BnVmnic::new_binder(service, BinderFeatures::default());
+    register_lazy_service(<BpVmnic as IVmnic>::get_descriptor(), service.as_binder()).unwrap();
+    info!("Registered Binder service, joining threadpool.");
+    ProcessState::join_thread_pool();
+}
diff --git a/virtualizationservice/vmnic/vmnic.rc b/virtualizationservice/vmnic/vmnic.rc
new file mode 100644
index 0000000..486f387
--- /dev/null
+++ b/virtualizationservice/vmnic/vmnic.rc
@@ -0,0 +1,20 @@
+# 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.
+
+service vmnic /apex/com.android.virt/bin/vmnic
+    user system
+    group system
+    interface aidl android.system.virtualizationservice_internal.IVmnic
+    disabled
+    oneshot