Improve the Rust property bindings.
Add a utility function to get the current value of a property and
remove some keystore2-specific strings.
Bug: 182498247
Test: Build
Change-Id: Ie7e9903546a4d4cd6c54a118c42257a23510dda6
diff --git a/libc/rust/system_properties.rs b/libc/rust/system_properties.rs
index a1f4835..189e8ee 100644
--- a/libc/rust/system_properties.rs
+++ b/libc/rust/system_properties.rs
@@ -196,6 +196,14 @@
}
}
+/// Reads a system property.
+pub fn read(name: &str) -> AnyhowResult<String> {
+ PropertyWatcher::new(name)
+ .context("Failed to create a PropertyWatcher.")?
+ .read(|_name, value| Ok(value.to_owned()))
+ .with_context(|| format!("Failed to read the system property {}.", name))
+}
+
/// Writes a system property.
pub fn write(name: &str, value: &str) -> AnyhowResult<()> {
if
@@ -204,10 +212,10 @@
// If successful, __system_property_set returns 0, otherwise, returns -1.
system_properties_bindgen::__system_property_set(
CString::new(name)
- .context("In keystore2::system_property::write: Construction CString from name.")?
+ .context("Failed to construct CString from name.")?
.as_ptr(),
CString::new(value)
- .context("In keystore2::system_property::write: Constructing CString from value.")?
+ .context("Failed to construct CString from value.")?
.as_ptr(),
)
} == 0