diff --git a/src/common/system.rs b/src/common/system.rs index b8b5ae774..dab1ca35a 100644 --- a/src/common/system.rs +++ b/src/common/system.rs @@ -735,8 +735,8 @@ impl System { /// /// | example platform | value of `System::long_os_version()` | /// |---|---| - /// | linux laptop | "Linux 24.04 Ubuntu" | - /// | android phone | "Android 15 Pixel 9 Pro" | + /// | linux laptop | "Linux (Ubuntu 24.04)" | + /// | android phone | "Android 15 on Pixel 9 Pro" | /// | apple laptop | "macOS 15.1.1 Sequoia" | /// | windows server | "Windows Server 2022 Datacenter" | /// diff --git a/src/unix/linux/system.rs b/src/unix/linux/system.rs index 3f14e4824..f285606f1 100644 --- a/src/unix/linux/system.rs +++ b/src/unix/linux/system.rs @@ -385,23 +385,44 @@ impl SystemInner { get_system_info_android(InfoType::Name) } + #[cfg(not(target_os = "android"))] pub(crate) fn long_os_version() -> Option { - #[cfg(target_os = "android")] - let system_name = "Android"; + let mut long_name = "Linux".to_owned(); + + let distro_name = Self::name(); + let distro_version = Self::os_version(); + if let Some(distro_version) = &distro_version { + // "Linux (Ubuntu 24.04)" + long_name.push_str(" ("); + long_name.push_str(distro_name.as_deref().unwrap_or("unknown")); + long_name.push(' '); + long_name.push_str(distro_version); + long_name.push(')'); + } else if let Some(distro_name) = &distro_name { + // "Linux (Ubuntu)" + long_name.push_str(" ("); + long_name.push_str(distro_name); + long_name.push(')'); + } - #[cfg(not(target_os = "android"))] - let system_name = "Linux"; + Some(long_name) + } - let mut long_name = system_name.to_owned(); + #[cfg(target_os = "android")] + pub(crate) fn long_os_version() -> Option { + let mut long_name = "Android".to_owned(); if let Some(os_version) = Self::os_version() { long_name.push(' '); long_name.push_str(&os_version); } - if let Some(short_name) = Self::name() { - long_name.push(' '); - long_name.push_str(&short_name); + // Android's name() is extracted from the system property "ro.product.model" + // which is documented as "The end-user-visible name for the end product." + // So this produces a long_os_version like "Android 15 on Pixel 9 Pro". + if let Some(product_name) = Self::name() { + long_name.push_str(" on "); + long_name.push_str(&product_name); } Some(long_name)