Skip to content

OSDescription: Returns a user-friendly name instead of kernel info on Android & Apple platforms#113041

Merged
akoeplinger merged 16 commits intodotnet:mainfrom
makazeu:os-description-android
Mar 10, 2025
Merged

OSDescription: Returns a user-friendly name instead of kernel info on Android & Apple platforms#113041
akoeplinger merged 16 commits intodotnet:mainfrom
makazeu:os-description-android

Conversation

@makazeu
Copy link
Copy Markdown
Contributor

@makazeu makazeu commented Mar 2, 2025

When running on Android, RuntimeInformation.OSDescription returns:
Before: Linux 6.6.30-android15-8-gdd9c02ccfe27-ab11987101 #1 SMP PREEMPT Tue Jun 18 20:50:32 UTC 2024
After: Android (API level 35)

When running on macOS:
Before: Darwin 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:06:23 PDT 2024; root:xnu-11215.41.3~3/RELEASE_ARM64_T8132
After: macOS 15.1.0

This aligns with the OSVersion:

#if defined(TARGET_ANDROID)
// get the Android API level
char sdk_ver_str[PROP_VALUE_MAX];
if (__system_property_get("ro.build.version.sdk", sdk_ver_str))
{
return strdup(sdk_ver_str);
}

and
/// <summary>
/// Check for the Android API level (returned by 'ro.build.version.sdk') with a >= version comparison. Used to guard APIs that were added in the given Android release.
/// </summary>
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
=> IsAndroid() && IsOSVersionAtLeast(major, minor, build, revision);

Copilot AI review requested due to automatic review settings March 2, 2025 08:36
@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 2, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR updates Android's OS description to return a user-friendly string format instead of the raw Linux kernel information.

  • Adds a conditional branch in the Unix runtime information provider to check for Android and format the OS description accordingly.
  • Introduces a new test case to verify that the Android OS description contains the expected substring.

Reviewed Changes

File Description
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Unix.cs Adds a branch to return "Android (API {version})" for Android OS.
src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs Adds a test to check the Android OS description behavior.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 2, 2025
@am11
Copy link
Copy Markdown
Member

am11 commented Mar 2, 2025

This aligns with the OSVersion:

I think it should align with what other platforms (including e.g. iOS) return from OSDescription instead, as it's happening right now. We had some discussion about it in #37923 and there is no concrete proposal yet. It would be better to work out the proposal and have this breaking change for all platforms once.

@am11 am11 added area-System.Runtime.InteropServices and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Mar 2, 2025
@makazeu
Copy link
Copy Markdown
Contributor Author

makazeu commented Mar 2, 2025

This aligns with the OSVersion:

I think it should align with what other platforms (including e.g. iOS) return from OSDescription instead, as it's happening right now. We had some discussion about it in #37923 and there is no concrete proposal yet. It would be better to work out the proposal and have this breaking change for all platforms once.

Since #37923 was raised, the output of OSDescription has undergone significant changes.
For example, PR #83976 modified the OSDescription in most Linux distributions, and in the current Debian system, its value is similar to Debian GNU/Linux 12 (bookworm) while in Ubuntu, it looks like Ubuntu 22.04.5 LTS.
In other words, the value of this OSDescription itself varies widely across different Linux distributions.

So I believe that in the five years since #37923 was raised, with no concrete proposal yet, it still makes sense for us to continue optimizing OSDescription to make it more user-friendly, just as PR #83976 did.

@am11
Copy link
Copy Markdown
Member

am11 commented Mar 2, 2025

For example, PR #83976 modified the OSDescription in most Linux distributions

It was for all linux based systems and still a broader change. The preferred way for OS detection is to use targeted APIs such as https://learn.microsoft.com/dotnet/api/system.operatingsystem.isandroid and https://learn.microsoft.com/dotnet/api/system.operatingsystem.isandroidversionatleast based on the discussion which transpired during those APIs review process.

@MichalPetryka
Copy link
Copy Markdown
Contributor

Should this be labeled as a breaking change?

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Mar 4, 2025

Should this be labeled as a breaking change?

I do not think that this is a breaking change. This property is documented as opaque string that should not be parsed.

It comes down to whether we like the new description.

@akoeplinger
Copy link
Copy Markdown
Member

I don't have a strong opinion but I'm in favor of the change, the new string is much more useful than the kernel version. It'd be nice to do the same for iOS/tvOS (and maybe macOS?) too.

@steveisok
Copy link
Copy Markdown
Member

I'm not opposed to this change as i think it's better than what we have currently.

@makazeu makazeu changed the title OSDescription.Android: Returns a user-friendly name instead of Linux kernel OSDescription: Returns a user-friendly name instead of kernel info on Android & Apple platforms Mar 4, 2025
@am11 am11 added os-mac-os-x macOS aka OSX os-ios Apple iOS os-maccatalyst MacCatalyst OS labels Mar 4, 2025
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to 'os-maccatalyst': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

@akoeplinger akoeplinger merged commit d737b22 into dotnet:main Mar 10, 2025
137 of 140 checks passed
@makazeu makazeu deleted the os-description-android branch March 10, 2025 17:20
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtime.InteropServices community-contribution Indicates that the PR has been added by a community member os-android os-ios Apple iOS os-mac-os-x macOS aka OSX os-maccatalyst MacCatalyst OS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants