summaryrefslogtreecommitdiff
path: root/system/gd/rust/common/src/sys_prop.rs
blob: c63cd48efd5373de21a1f24b83217f6e0008d9b7 (plain)
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
//! System properties on Android

/// Gets the value of a system property on Android
#[cfg(target_os = "android")]
pub fn get(name: &str) -> Option<String> {
    rustutils::system_properties::read(name).unwrap_or(None)
}

/// Fake getter for non-Android, which will always return nothing.
/// Only added so it compiles & you can conditionally using cfg!
#[cfg(not(target_os = "android"))]
pub fn get(_name: &str) -> Option<String> {
    None
}

/// Gets the specified property as a u32
pub fn get_u32(name: &str) -> Option<u32> {
    if let Some(value) = get(name) {
        value.parse().ok()
    } else {
        None
    }
}

/// Gets the specified property as a bool (logic follows libcutils/properties.cpp)
pub fn get_bool(name: &str) -> Option<bool> {
    if let Some(value) = get(name) {
        match value.as_str() {
            "0" | "n" | "no" | "false" | "off" => Some(false),
            "1" | "y" | "yes" | "true" | "on" => Some(true),
            _ => None,
        }
    } else {
        None
    }
}

/// Gets whether the current build is debuggable
pub fn get_debuggable() -> bool {
    get_bool("ro.debuggable").unwrap_or(false)
}