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