vmconfig: Introduce get_debug_level()
Add helper function to centralize deducing the debug level from a VM
config (either app or raw).
Test: m libvmconfig vm virtmgr
Change-Id: Ia04202fe3b1659b0428fd772e83e075d329f4cca
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index c5f1ab7..769ac4c 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -89,7 +89,7 @@
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, Weak};
use vbmeta::VbMetaImage;
-use vmconfig::VmConfig;
+use vmconfig::{VmConfig, get_debug_level};
use vsock::VsockStream;
use zip::ZipArchive;
@@ -1356,17 +1356,12 @@
.or_binder_exception(ExceptionCode::SECURITY);
}
- match config {
- VirtualMachineConfig::RawConfig(_) => Ok(()),
- VirtualMachineConfig::AppConfig(config) => {
- if config.debugLevel != DebugLevel::FULL {
- Err(anyhow!("Can't use gdb with non-debuggable VMs"))
- .or_binder_exception(ExceptionCode::SECURITY)
- } else {
- Ok(())
- }
- }
+ if get_debug_level(config) == Some(DebugLevel::NONE) {
+ return Err(anyhow!("Can't use gdb with non-debuggable VMs"))
+ .or_binder_exception(ExceptionCode::SECURITY);
}
+
+ Ok(())
}
fn extract_instance_id(config: &VirtualMachineConfig) -> [u8; 64] {