android_properties/
lib.rs1#![deny(missing_docs, missing_debug_implementations, unused)]
4
5use std::{fmt, os::raw::c_void};
6
7#[cfg(target_os = "android")]
8use crate::android::*;
9#[cfg(not(target_os = "android"))]
10use crate::mock::*;
11
12#[cfg(target_os = "android")]
13pub mod android;
15
16#[cfg(not(target_os = "android"))]
17pub mod mock;
19
20#[derive(Debug)]
24pub struct AndroidProperty {
25 name: String,
27 property_info: *const c_void,
29}
30
31impl AndroidProperty {
32 pub fn new(name: &str) -> Self {
34 AndroidProperty {
35 name: name.to_string(),
36 property_info: std::ptr::null(),
37 }
38 }
39
40 pub fn name(&self) -> String {
42 self.name.clone()
43 }
44
45 pub fn value(&mut self) -> Option<String> {
47 if self.property_info.is_null() {
48 self.property_info = plat_get_property_info(&self.name);
49 }
50 plat_getprop(&self.name, self.property_info)
51 }
52
53 pub fn set_value(&self, value: &str) -> Result<(), String> {
55 plat_setprop(&self.name, value)
56 }
57}
58
59impl fmt::Display for AndroidProperty {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62 let mut property_info = self.property_info;
63 if property_info.is_null() {
64 property_info = plat_get_property_info(&self.name);
65 }
66 write!(
67 f,
68 "[{}]: [{}]",
69 self.name,
70 plat_getprop(&self.name, property_info).unwrap_or_else(|| "".into())
71 )
72 }
73}
74
75pub fn getprop(name: &str) -> AndroidProperty {
77 AndroidProperty::new(name)
78}
79
80pub fn setprop(name: &str, value: &str) -> Result<(), String> {
82 AndroidProperty::new(name).set_value(value)
83}
84
85pub fn prop_values() -> impl Iterator<Item = AndroidProperty> {
87 #[cfg(target_os = "android")]
88 return crate::android::plat_prop_values();
89
90 #[cfg(not(target_os = "android"))]
91 return crate::mock::plat_prop_values();
92}