1 //! System properties on Android 2 3 #[cfg(target_os = "android")] 4 mod wrap { 5 #[cxx::bridge(namespace = bluetooth::common::sys_prop)] 6 pub mod ffi { 7 unsafe extern "C++" { 8 include!("src/ffi/sys_prop.h"); get(name: &str) -> String9 fn get(name: &str) -> String; 10 } 11 } 12 } 13 14 #[cfg(target_os = "android")] 15 use wrap::ffi; 16 17 /// Gets the value of a system property on Android 18 #[cfg(target_os = "android")] get(name: &str) -> Option<String>19pub fn get(name: &str) -> Option<String> { 20 let value = ffi::get(name); 21 22 if !value.is_empty() { 23 Some(value) 24 } else { 25 None 26 } 27 } 28 29 /// Fake getter for non-Android, which will always return nothing. 30 /// Only added so it compiles & you can conditionally using cfg! 31 #[cfg(not(target_os = "android"))] get(_name: &str) -> Option<String>32pub fn get(_name: &str) -> Option<String> { 33 None 34 } 35 36 /// Gets the specified property as a u32 get_u32(name: &str) -> Option<u32>37pub fn get_u32(name: &str) -> Option<u32> { 38 if let Some(value) = get(name) { 39 value.parse().ok() 40 } else { 41 None 42 } 43 } 44 45 /// Gets the specified property as a bool (logic follows libcutils/properties.cpp) get_bool(name: &str) -> Option<bool>46pub fn get_bool(name: &str) -> Option<bool> { 47 if let Some(value) = get(name) { 48 match value.as_str() { 49 "0" | "n" | "no" | "false" | "off" => Some(false), 50 "1" | "y" | "yes" | "true" | "on" => Some(true), 51 _ => None, 52 } 53 } else { 54 None 55 } 56 } 57 58 /// Gets whether the current build is debuggable get_debuggable() -> bool59pub fn get_debuggable() -> bool { 60 get_bool("ro.debuggable").unwrap_or(false) 61 } 62