Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

makazeu
Copy link
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 Copilot bot review requested due to automatic review settings March 2, 2025 08:36
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 2, 2025

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
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
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
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
Contributor

Should this be labeled as a breaking change?

@jkotas
Copy link
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
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
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
Copy link
Contributor

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

@makazeu
Copy link
Contributor Author

makazeu commented Mar 4, 2025

@akoeplinger @am11 @steveisok @jkotas I pushed a new commit that does the same to Apple platforms.

Question: for Apple platforms, which description do you think is better?

  • macOS 12.14.0
  • macOS (version 12.14.0)
  • other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

6 participants