Update to improved system_properties API.
We'll now return an error if there is an actual error reading the
property, rather than treating it the same as the property not being
set.
Bug: 217728265
Test: mm
Change-Id: I81f22d9ed07443b094f9a64a0737f4d24a2afe15
diff --git a/compos/common/compos_client.rs b/compos/common/compos_client.rs
index 72d2b76..69f095a 100644
--- a/compos/common/compos_client.rs
+++ b/compos/common/compos_client.rs
@@ -200,21 +200,20 @@
fn want_protected_vm() -> Result<bool> {
let have_protected_vm =
- system_properties::read_bool("ro.boot.hypervisor.protected_vm.supported", false)
- .unwrap_or(false);
+ system_properties::read_bool("ro.boot.hypervisor.protected_vm.supported", false)?;
if have_protected_vm {
info!("Starting protected VM");
return Ok(true);
}
- let build_type = system_properties::read("ro.build.type")?;
+ let build_type = system_properties::read("ro.build.type")?.context("ro.build.type not set")?;
let is_debug_build = matches!(build_type.as_str(), "userdebug" | "eng");
if !is_debug_build {
bail!("Protected VM not supported, unable to start VM");
}
let have_unprotected_vm =
- system_properties::read_bool("ro.boot.hypervisor.vm.supported", false).unwrap_or(false);
+ system_properties::read_bool("ro.boot.hypervisor.vm.supported", false)?;
if have_unprotected_vm {
warn!("Protected VM not supported, falling back to unprotected on {} build", build_type);
return Ok(false);
diff --git a/compos/common/timeouts.rs b/compos/common/timeouts.rs
index c86ae34..e6cc430 100644
--- a/compos/common/timeouts.rs
+++ b/compos/common/timeouts.rs
@@ -35,8 +35,11 @@
/// Whether the current platform requires extra time for operations inside a VM.
pub fn need_extra_time() -> Result<bool> {
// Nested virtualization is slow. Check if we are running on vsoc as a proxy for this.
- let value = system_properties::read("ro.build.product")?;
- Ok(value == "vsoc_x86_64" || value == "vsoc_x86")
+ if let Some(value) = system_properties::read("ro.build.product")? {
+ Ok(value == "vsoc_x86_64" || value == "vsoc_x86")
+ } else {
+ Ok(false)
+ }
}
/// Return the timeouts that are appropriate on the current platform.
diff --git a/compos/composd/src/instance_manager.rs b/compos/composd/src/instance_manager.rs
index 2f15cb5..9761a3e 100644
--- a/compos/composd/src/instance_manager.rs
+++ b/compos/composd/src/instance_manager.rs
@@ -83,15 +83,15 @@
}
fn new_vm_parameters() -> Result<VmParameters> {
- let cpus = match system_properties::read(DEX2OAT_THREADS_PROP_NAME) {
- Ok(s) => Some(NonZeroU32::from_str(&s)?),
- Err(_) => {
+ let cpus = match system_properties::read(DEX2OAT_THREADS_PROP_NAME)? {
+ Some(s) => Some(NonZeroU32::from_str(&s)?),
+ None => {
// dex2oat uses all CPUs by default. To match the behavior, give the VM all CPUs by
// default.
NonZeroU32::new(num_cpus::get() as u32)
}
};
- let cpu_set = system_properties::read(DEX2OAT_CPU_SET_PROP_NAME).ok();
+ let cpu_set = system_properties::read(DEX2OAT_CPU_SET_PROP_NAME)?;
Ok(VmParameters { cpus, cpu_set, ..Default::default() })
}
diff --git a/compos/composd/src/odrefresh_task.rs b/compos/composd/src/odrefresh_task.rs
index 82eedc4..d1d0e28 100644
--- a/compos/composd/src/odrefresh_task.rs
+++ b/compos/composd/src/odrefresh_task.rs
@@ -145,9 +145,9 @@
};
let fd_server_raii = fd_server_config.into_fd_server()?;
- let zygote_arch = system_properties::read("ro.zygote")?;
+ let zygote_arch = system_properties::read("ro.zygote")?.context("ro.zygote not set")?;
let system_server_compiler_filter =
- system_properties::read("dalvik.vm.systemservercompilerfilter").unwrap_or_default();
+ system_properties::read("dalvik.vm.systemservercompilerfilter")?.unwrap_or_default();
let exit_code = service.odrefresh(
compilation_mode,
system_dir.as_raw_fd(),
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index ebb01b3..7e0c634 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -868,7 +868,7 @@
/// a system property so that restart of virtualizationservice doesn't reuse CID while the host
/// Android is up.
fn next_cid() -> Result<Cid> {
- let next = if let Ok(val) = system_properties::read(SYSPROP_LAST_CID) {
+ let next = if let Some(val) = system_properties::read(SYSPROP_LAST_CID)? {
if let Ok(num) = val.parse::<u32>() {
num.checked_add(1).ok_or_else(|| anyhow!("run out of CID"))?
} else {
diff --git a/vm/src/main.rs b/vm/src/main.rs
index 2514424..2cbae3e 100644
--- a/vm/src/main.rs
+++ b/vm/src/main.rs
@@ -251,7 +251,7 @@
(true, true) => println!("Both protected and unprotected VMs are supported."),
}
- if let Ok(version) = system_properties::read("ro.boot.hypervisor.version") {
+ if let Some(version) = system_properties::read("ro.boot.hypervisor.version")? {
println!("Hypervisor version: {}", version);
} else {
println!("Hypervisor version not set.");