1 //! System properties on Android 2 3 /// Gets the value of a system property on Android 4 #[cfg(target_os = "android")] get(name: &str) -> Option<String>5pub fn get(name: &str) -> Option<String> { 6 rustutils::system_properties::read(name).unwrap_or(None) 7 } 8 9 /// Fake getter for non-Android, which will always return nothing. 10 /// Only added so it compiles & you can conditionally using cfg! 11 #[cfg(not(target_os = "android"))] get(_name: &str) -> Option<String>12pub fn get(_name: &str) -> Option<String> { 13 None 14 } 15 16 /// Gets the specified property as a u32 get_u32(name: &str) -> Option<u32>17pub fn get_u32(name: &str) -> Option<u32> { 18 if let Some(value) = get(name) { 19 value.parse().ok() 20 } else { 21 None 22 } 23 } 24 25 /// Gets the specified property as a bool (logic follows libcutils/properties.cpp) get_bool(name: &str) -> Option<bool>26pub fn get_bool(name: &str) -> Option<bool> { 27 if let Some(value) = get(name) { 28 match value.as_str() { 29 "0" | "n" | "no" | "false" | "off" => Some(false), 30 "1" | "y" | "yes" | "true" | "on" => Some(true), 31 _ => None, 32 } 33 } else { 34 None 35 } 36 } 37 38 /// Gets whether the current build is debuggable get_debuggable() -> bool39pub fn get_debuggable() -> bool { 40 get_bool("ro.debuggable").unwrap_or(false) 41 } 42