summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2021-03-22 21:58:56 +0800
committerYi Kong <yikong@google.com>2021-03-22 22:01:39 +0800
commit6b3fca3288938f55e643897d0152d7e841b72573 (patch)
treea5b665ad04eba11532a3ca33479c2947217a5ed6
parent29f356ed8a0cb407d663c71ee5b47065d3bcf181 (diff)
downloadextras-6b3fca3288938f55e643897d0152d7e841b72573.tar.gz
profcollectd: Add Rust bindings for android::base::SetProperty
Test: build Change-Id: Ib41a5c9f4beccd7451f86c28a996a3c3ff06eb0f
-rw-r--r--profcollectd/libprofcollectd/bindings/libbase/lib.rs9
-rw-r--r--profcollectd/libprofcollectd/bindings/libbase/properties.cpp4
-rw-r--r--profcollectd/libprofcollectd/bindings/libbase/properties.hpp1
3 files changed, 14 insertions, 0 deletions
diff --git a/profcollectd/libprofcollectd/bindings/libbase/lib.rs b/profcollectd/libprofcollectd/bindings/libbase/lib.rs
index 8edbdf45..6ac34d58 100644
--- a/profcollectd/libprofcollectd/bindings/libbase/lib.rs
+++ b/profcollectd/libprofcollectd/bindings/libbase/lib.rs
@@ -28,3 +28,12 @@ pub fn get_property<'a>(key: &str, default_value: &'a str) -> &'a str {
CStr::from_ptr(cstr).to_str().unwrap()
}
}
+
+/// Sets the system property `key` to `value`.
+pub fn set_property(key: &str, value: &str) {
+ let key = CString::new(key).unwrap();
+ let value = CString::new(value).unwrap();
+ unsafe {
+ profcollect_libbase_bindgen::SetProperty(key.as_ptr(), value.as_ptr());
+ }
+}
diff --git a/profcollectd/libprofcollectd/bindings/libbase/properties.cpp b/profcollectd/libprofcollectd/bindings/libbase/properties.cpp
index e50b048d..01be7c73 100644
--- a/profcollectd/libprofcollectd/bindings/libbase/properties.cpp
+++ b/profcollectd/libprofcollectd/bindings/libbase/properties.cpp
@@ -21,3 +21,7 @@ const char* GetProperty(const char* key, const char* default_value) {
auto v = android::base::GetProperty(std::string(key), std::string(default_value));
return strdup(v.c_str());
}
+
+void SetProperty(const char* key, const char* value) {
+ android::base::SetProperty(std::string(key), std::string(value));
+}
diff --git a/profcollectd/libprofcollectd/bindings/libbase/properties.hpp b/profcollectd/libprofcollectd/bindings/libbase/properties.hpp
index c1b5cbb9..d6785a28 100644
--- a/profcollectd/libprofcollectd/bindings/libbase/properties.hpp
+++ b/profcollectd/libprofcollectd/bindings/libbase/properties.hpp
@@ -16,3 +16,4 @@
// C declaration for bindgen.
const char* GetProperty(const char*, const char*);
+void SetProperty(const char*, const char*);