[service-vm] Extract service-vm module in a separate library

This allows us to test the library with rialto_test and to remove
the duplicate code in the tests.

Test: m MicrodroidHostTests
Bug: 299089107
Change-Id: Idb9c6bf7c96a334d1f0982d8118e0d5b39915003
diff --git a/service_vm_manager/Android.bp b/service_vm_manager/Android.bp
new file mode 100644
index 0000000..47867f5
--- /dev/null
+++ b/service_vm_manager/Android.bp
@@ -0,0 +1,23 @@
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+rust_library {
+    name: "libservice_vm_manager",
+    crate_name: "service_vm_manager",
+    defaults: ["avf_build_flags_rust"],
+    srcs: ["src/lib.rs"],
+    prefer_rlib: true,
+    rustlibs: [
+        "android.system.virtualizationservice-rust",
+        "libanyhow",
+        "libciborium",
+        "liblog_rust",
+        "libservice_vm_comm",
+        "libvmclient",
+        "libvsock",
+    ],
+    apex_available: [
+        "com.android.virt",
+    ],
+}
diff --git a/virtualizationservice/src/service_vm.rs b/service_vm_manager/src/lib.rs
similarity index 97%
rename from virtualizationservice/src/service_vm.rs
rename to service_vm_manager/src/lib.rs
index 23eae91..86b6575 100644
--- a/virtualizationservice/src/service_vm.rs
+++ b/service_vm_manager/src/lib.rs
@@ -12,6 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+//! This module contains the functions to start, stop and communicate with the
 //! Service VM.
 
 use android_system_virtualizationservice::{
diff --git a/virtualizationservice/Android.bp b/virtualizationservice/Android.bp
index 56be95b..c00445d 100644
--- a/virtualizationservice/Android.bp
+++ b/virtualizationservice/Android.bp
@@ -31,7 +31,6 @@
         "libanyhow",
         "libavflog",
         "libbinder_rs",
-        "libciborium",
         "liblibc",
         "liblog_rust",
         "libnix",
@@ -43,6 +42,7 @@
         "libserde",
         "libserde_xml_rs",
         "libservice_vm_comm",
+        "libservice_vm_manager",
     ],
     apex_available: ["com.android.virt"],
 }
diff --git a/virtualizationservice/src/main.rs b/virtualizationservice/src/main.rs
index cdb3ac9..9778599 100644
--- a/virtualizationservice/src/main.rs
+++ b/virtualizationservice/src/main.rs
@@ -18,7 +18,6 @@
 mod atom;
 mod remote_provisioning;
 mod rkpvm;
-mod service_vm;
 
 use crate::aidl::{
     remove_temporary_dir, BINDER_SERVICE_IDENTIFIER, TEMPORARY_DIRECTORY,
diff --git a/virtualizationservice/src/rkpvm.rs b/virtualizationservice/src/rkpvm.rs
index f638503..2c9230b 100644
--- a/virtualizationservice/src/rkpvm.rs
+++ b/virtualizationservice/src/rkpvm.rs
@@ -16,9 +16,9 @@
 //! The RKP VM will be recognized and attested by the RKP server periodically and
 //! serves as a trusted platform to attest a client VM.
 
-use crate::service_vm::ServiceVm;
 use anyhow::{bail, Context, Result};
 use service_vm_comm::{Request, Response};
+use service_vm_manager::ServiceVm;
 
 pub(crate) fn request_certificate(csr: &[u8]) -> Result<Vec<u8>> {
     let mut vm = ServiceVm::start()?;