Repository: GuillaumeGomez/sysinfo (language: rust)

Issue:
Android `long_os_version`
In https://github.com/GuillaumeGomez/sysinfo/pull/1416 I observed that `long_os_version` on Android includes an Android version and the hardware platform, such as "Android 15 Pixel 9 Pro".

If this is a consistent phenomenon across different Android devices, I think it would be friendlier to render this as "Android 15 on Pixel 9 Pro".


Discussion / hints:
What do you think about "Android 15 - Pixel 9 Pro"?
I looked into where the second part of the name is coming from. Sysinfo is using this:

https://android.googlesource.com/platform/frameworks/base/+/bc3378bf08f908335c721e597f51f6b95374f0c8/core/java/android/os/Build.java#137

```java
/** The end-user-visible name for the end product. */
public static final String MODEL = getString("ro.product.model");
```

so I think we can be confident that the value is either the name of a product, or is the string "unknown". After checking for "unknown" (which the current implementation does not do) my preference would be to use "on" with the product name, not "-".
Fine by me!

Fix patch:
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<String> {
-        #[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<String> {
+        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)


Test patch: