Skip to content

Remove obsolete System.AndroidPlatform methods and native implementations #10385

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

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

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 7, 2025

This PR removes obsolete managed code that references System.AndroidPlatform, which was part of the Mono Android runtime but was never used in modern .NET. The issue was identified by @filipnavara and confirmed safe to remove by @jonathanpeppers after verifying that these APIs don't exist in dotnet/runtime.

Changes Made

Removed Methods from AndroidEnvironment.cs:

  • GetDisplayDPI() - Previously called by System.Drawing.GraphicsAndroid.FromAndroidSurface() (already marked as obsolete for android31.0)
  • GetDefaultTimeZone() - Previously called by System.Core!System.AndroidPlatform.GetDefaultTimeZone()
  • GetDefaultSyncContext() - Previously called by mscorlib.dll!System.AndroidPlatform.GetDefaultSyncContext()
  • GetInterfaceAddresses() - Previously called by System.dll!System.AndroidPlatform.getifaddrs
  • FreeInterfaceAddresses() - Previously called by System.dll!System.AndroidPlatform.freeifaddrs
  • GetDefaultProxy() - Previously called by System.dll!System.AndroidPlatform.GetDefaultProxy()

Additional Cleanup:

  • Removed the _Proxy class that was only used by GetDefaultProxy()
  • Removed unused P/Invoke declarations from RuntimeNativeMethods.cs:
    • _monodroid_timezone_get_default_id()
    • _monodroid_getifaddrs()
    • _monodroid_freeifaddrs()

Native Code Cleanup:

  • Removed P/Invoke method entries from both CLR and Mono P/Invoke table generators
  • Regenerated P/Invoke tables using generate-pinvoke-tables.sh
  • Removed unused native C++ implementations:
    • _monodroid_timezone_get_default_id() functions (CLR & Mono)
    • Complete xamarin_getifaddrs.cc files and header (CLR & Mono - 2,200+ lines)
    • Updated CMakeLists.txt files to remove build references
  • Fixed linker error by removing obsolete symbols from Mono version script

Impact

This is a breaking change that removes internal APIs that were never intended for public use in modern .NET for Android. No external code should be affected as these were internal implementation details for obsolete System.AndroidPlatform methods.

Total lines removed: 2,456 lines across 16 files
Build status: ✅ Successful with no new warnings or errors

Fixes #10381.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Obsolete code referring to System.AndroidPlatform Remove obsolete System.AndroidPlatform methods and dependencies Aug 7, 2025
@Copilot Copilot AI requested a review from jonathanpeppers August 7, 2025 15:14
Copilot finished work on behalf of jonathanpeppers August 7, 2025 15:14
@jonathanpeppers
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

@copilot check my review comments

@Copilot Copilot AI changed the title Remove obsolete System.AndroidPlatform methods and dependencies Remove obsolete System.AndroidPlatform methods and native implementations Aug 7, 2025
@Copilot Copilot AI requested a review from jonathanpeppers August 7, 2025 20:44
Copilot finished work on behalf of jonathanpeppers August 7, 2025 20:44
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

@copilot there is a new error:

(_BuildAndroidRuntimes target) -> 
         ld.lld : error : version script assignment of 'LIBMONO_ANDROID' to symbol '_monodroid_freeifaddrs' failed: symbol not defined [/Users/builder/azdo/_work/4/s/android/src/native/native-mono.csproj]
         ld.lld : error : version script assignment of 'LIBMONO_ANDROID' to symbol '_monodroid_getifaddrs' failed: symbol not defined [/Users/builder/azdo/_work/4/s/android/src/native/native-mono.csproj]
         clang++ : error : linker command failed with exit code 1 (use -v to see invocation)

Is something using these methods? or is there another file to update?

Copy link
Contributor Author

Copilot AI commented Aug 8, 2025

@copilot there is a new error:

(_BuildAndroidRuntimes target) -> 

...

The error was caused by the Mono version script file still referencing the removed symbols. I've fixed it by removing _monodroid_freeifaddrs and _monodroid_getifaddrs from src/native/mono/libmono-android.map.txt. The CLR version was unaffected since it didn't have these symbols in its version script. Fix in commit a6a34d5.

@Copilot Copilot AI requested a review from jonathanpeppers August 8, 2025 14:08
Copilot finished work on behalf of jonathanpeppers August 8, 2025 14:08
Copy link
Member

@filipnavara filipnavara left a comment

Choose a reason for hiding this comment

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

LGTM (if the build passes)

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

@copilot there are a few minor formatting issues

Copy link
Contributor Author

Copilot AI commented Aug 8, 2025

@copilot there are a few minor formatting issues

Fixed all formatting issues in commit 0dc673c - removed unnecessary blank lines from the three affected files.

@Copilot Copilot AI requested a review from jonathanpeppers August 8, 2025 15:53
Copilot finished work on behalf of jonathanpeppers August 8, 2025 15:53
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 8, 2025 16:00
@grendello
Copy link
Contributor

I would hold off with this PR until we branch for .NET10 release. The Mono changes can potentially be breaking ones, especially removal of the *ifaddr p/invokes. There's a slim but non-zero chance that some app out there is using any of those APIs.

@filipnavara
Copy link
Member

filipnavara commented Aug 8, 2025

I find it very unlikely that any app would depend on it. This was internal implementation detail that has not been used since .NET 5 (unified .NET always shipped the shims in their native libraries).

The reason I found this in the first place is that I looked into reusing the native code for CoreCLR GC bridge for NativeAOT (which now has the same API). I was very surprised to find that this is still lurking around and that it was even ported to CoreCLR host code base.

(in fact, I would argue that from security perspective it's safer to ship less dead code in a LTS release; well, even if LTS is irrelevant for the mobile workloads)

@jonathanpeppers
Copy link
Member

main is basically .NET 10 RC 1, given it is deleting 2,400 lines. I'm ok to defer to @grendello's suggestion. We can wait to merge until we've branched for .NET 10 to put this in .NET 11. If we were on earlier previews, I would say just merge it.

It must not affect app size too much, as we have tests that fail if file sizes change within a certain percentage.

@dartasen
Copy link

There's a slim but non-zero chance that some app out there is using any of those APIs.

Isn't it internal APIs ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Obsolete code referring to System.AndroidPlatform
5 participants