virtualizationmanager: Prevent tests from using debug policy
Debug policy isn't suitable for tests because:
- Test result may vary per device
- Debug policy emits confusing SELinux denial (`scontext=shell`)
This refactors code to prevent tests from using debug policy.
Change-Id: I6dbe8c435fd7d7f2ed036a5d0b6e56ae4a2bfd53
Test: T/H
Bug: 329228840
diff --git a/virtualizationmanager/src/aidl.rs b/virtualizationmanager/src/aidl.rs
index 278365c..22bea58 100644
--- a/virtualizationmanager/src/aidl.rs
+++ b/virtualizationmanager/src/aidl.rs
@@ -434,11 +434,7 @@
None
};
- let debug_level = match config {
- VirtualMachineConfig::AppConfig(config) => config.debugLevel,
- _ => DebugLevel::NONE,
- };
- let debug_config = DebugConfig::new(debug_level);
+ let debug_config = DebugConfig::new(config);
let ramdump = if debug_config.is_ramdump_needed() {
Some(prepare_ramdump_file(&temporary_directory)?)
diff --git a/virtualizationmanager/src/debug_config.rs b/virtualizationmanager/src/debug_config.rs
index bcf643b..39097e0 100644
--- a/virtualizationmanager/src/debug_config.rs
+++ b/virtualizationmanager/src/debug_config.rs
@@ -15,17 +15,17 @@
//! Functions for AVF debug policy and debug level
use android_system_virtualizationservice::aidl::android::system::virtualizationservice::{
- VirtualMachineAppConfig::DebugLevel::DebugLevel,
+ VirtualMachineAppConfig::DebugLevel::DebugLevel, VirtualMachineConfig::VirtualMachineConfig,
};
use anyhow::{anyhow, Context, Error, Result};
+use lazy_static::lazy_static;
+use libfdt::{Fdt, FdtError};
+use log::{info, warn};
+use rustutils::system_properties;
+use std::ffi::{CString, NulError};
use std::fs;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
-use std::ffi::{CString, NulError};
-use log::{warn, info};
-use rustutils::system_properties;
-use libfdt::{Fdt, FdtError};
-use lazy_static::lazy_static;
const CUSTOM_DEBUG_POLICY_OVERLAY_SYSPROP: &str =
"hypervisor.virtualizationmanager.debug_policy.path";
@@ -156,7 +156,12 @@
}
impl DebugConfig {
- pub fn new(debug_level: DebugLevel) -> Self {
+ pub fn new(config: &VirtualMachineConfig) -> Self {
+ let debug_level = match config {
+ VirtualMachineConfig::AppConfig(config) => config.debugLevel,
+ _ => DebugLevel::NONE,
+ };
+
match system_properties::read(CUSTOM_DEBUG_POLICY_OVERLAY_SYSPROP).unwrap_or_default() {
Some(path) if !path.is_empty() => {
match Self::from_custom_debug_overlay_policy(debug_level, Path::new(&path)) {
@@ -179,6 +184,11 @@
}
info!("Debug policy is disabled");
+ Self::new_with_debug_level(debug_level)
+ }
+
+ /// Creates a new DebugConfig with debug level. Only use this for test purpose.
+ pub fn new_with_debug_level(debug_level: DebugLevel) -> Self {
Self {
debug_level,
debug_policy_log: false,
diff --git a/virtualizationmanager/src/payload.rs b/virtualizationmanager/src/payload.rs
index 05626d3..9d0c7d6 100644
--- a/virtualizationmanager/src/payload.rs
+++ b/virtualizationmanager/src/payload.rs
@@ -631,7 +631,7 @@
collect_apex_infos(
&apex_info_list,
&apex_configs,
- &DebugConfig::new(DebugLevel::FULL)
+ &DebugConfig::new_with_debug_level(DebugLevel::FULL)
)?,
vec![
// Pass active/required APEXes
@@ -660,8 +660,11 @@
};
let apex_configs = vec![ApexConfig { name: "apex-vendor".to_string() }];
- let ret =
- collect_apex_infos(&apex_info_list, &apex_configs, &DebugConfig::new(DebugLevel::NONE));
+ let ret = collect_apex_infos(
+ &apex_info_list,
+ &apex_configs,
+ &DebugConfig::new_with_debug_level(DebugLevel::NONE),
+ );
assert!(ret
.is_err_and(|ret| ret.to_string()
== "Non-system APEX apex-vendor is not supported in Microdroid"));
@@ -687,7 +690,7 @@
collect_apex_infos(
&apex_info_list,
&apex_configs,
- &DebugConfig::new(DebugLevel::NONE)
+ &DebugConfig::new_with_debug_level(DebugLevel::NONE)
)?,
vec![&apex_info_list.list[0]]
);