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] {
diff --git a/virtualizationmanager/src/debug_config.rs b/virtualizationmanager/src/debug_config.rs
index a2ea40d..6b74353 100644
--- a/virtualizationmanager/src/debug_config.rs
+++ b/virtualizationmanager/src/debug_config.rs
@@ -26,6 +26,7 @@
 use std::fs;
 use std::io::ErrorKind;
 use std::path::{Path, PathBuf};
+use vmconfig::get_debug_level;
 
 const CUSTOM_DEBUG_POLICY_OVERLAY_SYSPROP: &str =
     "hypervisor.virtualizationmanager.debug_policy.path";
@@ -157,10 +158,7 @@
 
 impl DebugConfig {
     pub fn new(config: &VirtualMachineConfig) -> Self {
-        let debug_level = match config {
-            VirtualMachineConfig::AppConfig(config) => config.debugLevel,
-            _ => DebugLevel::NONE,
-        };
+        let debug_level = get_debug_level(config).unwrap_or(DebugLevel::NONE);
 
         let dp_sysprop = system_properties::read(CUSTOM_DEBUG_POLICY_OVERLAY_SYSPROP);
         let custom_dp = dp_sysprop.unwrap_or_else(|e| {