Skip to content

[Mono.Android] Fix incorrect Context.RegisterReceiver enumification. - #7735

Merged
jonpryor merged 1 commit into
mainfrom
register-receiver
Jul 25, 2023
Merged

[Mono.Android] Fix incorrect Context.RegisterReceiver enumification.#7735
jonpryor merged 1 commit into
mainfrom
register-receiver

Conversation

@jpobst

@jpobstjpobst commented Jan 24, 2023

Copy link
Copy Markdown
Contributor

Fixes#7503

Android.Content.Context.RegisterReceiver(BroadcastReceiver, IntentFilter, int) (+1 overload) was incorrectly enumified as ActivityFlags when it should have been ReceiverFlags.

To fix without breaking API:

  • Create new overloads methods that chain to the existing incorrectly enumified methods.
  • Mark the existing methods as [Obsolete] with description.

Additionally, it was noticed that the public API tracking added in #8171 did not get flagged as an error, only a warning. Change to an error to ensure any new public API is accounted for.

@jpobst
jpobstforce-pushed the register-receiver branch 2 times, most recently from fc5a525 to a7a8fb1CompareFebruary 6, 2023 18:30
@jpobst
jpobstforce-pushed the register-receiver branch 2 times, most recently from 4637626 to 2f4b164CompareJuly 25, 2023 15:21
@jpobst
jpobstforce-pushed the register-receiver branch from 2f4b164 to df33021CompareJuly 25, 2023 17:00
@jpobst
jpobst marked this pull request as ready for review July 25, 2023 19:07
@jpobst
jpobst requested a review from jonpryor as a code ownerJuly 25, 2023 19:07
@jonpryor

Copy link
Copy Markdown
Contributor

What gives me pause is that the resulting binding makes an abstract method [Obsolete], a'la:

partialclassContext{[Obsolete("This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.")]publicabstractAndroid.Content.Intent?RegisterReceiver(Android.Content.BroadcastReceiver?receiver,Android.Content.IntentFilter?filter,[global::Android.Runtime.GeneratedEnum]Android.Content.ActivityFlagsflags);}

which I believe means that every override also needs to be [Obsolete], hence the changes in this PR to ContextWrapper and MockContext. This feels "weird".

On the plus side, (effectively) nobody should ever override Context.RegisterReceiver(), so this should be safe.

@jpobst

Copy link
Copy Markdown
ContributorAuthor

This feels "weird".

Agreed.

On the plus side, (effectively) nobody should ever override Context.RegisterReceiver(), so this should be safe.

This is the rationale I eventually went with. ~No one should override this, users should only be calling the system provided version(s) of it.

@jonpryor
jonpryor merged commit d9e4407 into mainJul 25, 2023
@jonpryor
jonpryor deleted the register-receiver branch July 25, 2023 20:26
grendello added a commit to grendello/xamarin-android that referenced this pull request Jul 25, 2023
* main:
Bump to dotnet/installer@f8bab721ae 8.0.100-rc.1.23373.1 (dotnet#8202)
[Mono.Android] Fix Context.RegisterReceiver() enumification (dotnet#7735)
grendello added a commit to grendello/xamarin-android that referenced this pull request Jul 27, 2023
* main:
[ci] Remove .NET branches from classic release trigger (dotnet#8218)
Bump to dotnet/installer@f8bab721ae 8.0.100-rc.1.23373.1 (dotnet#8202)
[Mono.Android] Fix Context.RegisterReceiver() enumification (dotnet#7735)
[ci] Add MAUI integration job (dotnet#8200)
[vs-workload] Set EnableSideBySideManifests=true (dotnet#8179)
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main:
Bump to dotnet/installer@f8bab721ae 8.0.100-rc.1.23373.1 (dotnet#8202)
[Mono.Android] Fix Context.RegisterReceiver() enumification (dotnet#7735)
[ci] Add MAUI integration job (dotnet#8200)
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jan 23, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Argument type of Context.RegisterReceiver() is different from native API

2 participants

@jpobst@jonpryor