-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix broadcast receiver register on android 14.0/34+ #18520
Conversation
I haven't been able to test on an Android 14.0 (API 34) device, and the documentation is not the clearest to me:
We are listening for system events, so it sounds like we should use |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the connectivity sample in essentials and it no longer crashes with these changes
This adds a new helper method for registering broadcast receivers, which takes a bool for exporting the service or not, and on API 34 and higher, it calls the newer overload which takes the `ReceiverFlags` and passes the corresponding `NotExported` or `Exported` value to the bool parameter of the util method. This allows us to call the right overload if we are on API 34 (Android 14.0) or newer where the declaration is required. Also some older GetLocale()/SetLocale() methods are removed which were unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests, will add.
afd5840
to
17d928a
Compare
I tested on a Pixel 6 with Android 14 / API 34 and a Samsung A53 5G with Android 13 / API 33. I could reproduce the crash for Connectivity, and this PR fixed it. I did not observe crashes for Battery, and this PR does not seem to change anything. I added some tests that confirmed my observations before & after the PR. |
Once this is merged, it should appear on the nightly feeds. |
When this fix will be released? Today I've downloaded new VS with .net 8 and other updates and got this crash |
This adds a new helper method for registering broadcast receivers, which takes a bool for exporting the service or not, and on API 34 and higher, it calls the newer overload which takes the
ReceiverFlags
and passes the correspondingNotExported
orExported
value to the bool parameter of the util method.This allows us to call the right overload if we are on API 34 (Android 14.0) or newer where the declaration is required.
Also some older GetLocale()/SetLocale() methods are removed which were unused.
Fixes #17861