use super::types::DetectionConfidence;
#[derive(Debug, Clone)]
pub struct AndroidApiInfo {
pub api_level: Option<u32>,
pub confidence: DetectionConfidence,
}
pub fn detect_android_api_level() -> AndroidApiInfo {
if let Ok(sdk_str) = std::env::var("ANDROID_SDK_VERSION") {
if let Ok(level) = sdk_str.parse::<u32>() {
return AndroidApiInfo {
api_level: Some(level),
confidence: DetectionConfidence::Medium,
};
}
}
for env_var in &["ANDROID_API_LEVEL", "SDK_INT", "TARGET_SDK_VERSION"] {
if let Ok(sdk_str) = std::env::var(env_var) {
if let Ok(level) = sdk_str.parse::<u32>() {
return AndroidApiInfo {
api_level: Some(level),
confidence: DetectionConfidence::Medium,
};
}
}
}
AndroidApiInfo {
api_level: None,
confidence: DetectionConfidence::Low,
}
}
pub fn detect_nnapi_availability() -> bool {
#[cfg(target_os = "android")]
{
let api_info = detect_android_api_level();
match api_info.api_level {
Some(level) => {
level >= 27
}
None => {
false
}
}
}
#[cfg(not(target_os = "android"))]
{
false
}
}