-
Notifications
You must be signed in to change notification settings - Fork 88
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
Android 14 (compile SDK 34) and BroadcastReceiver changes #582
Conversation
…castReceiver changes.
applicationContext.unregisterReceiver(receiver) | ||
} | ||
}.shareIn(GlobalScope, started = WhileSubscribed(replayExpirationMillis = 0)) | ||
internal val bluetoothState = broadcastReceiverFlow(intentFilter, RECEIVER_NOT_EXPORTED) |
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.
nit: RECEIVER_NOT_EXPORTED
is default, right?
internal val bluetoothState = broadcastReceiverFlow(intentFilter, RECEIVER_NOT_EXPORTED) | |
internal val bluetoothState = broadcastReceiverFlow(intentFilter) |
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.
Tons of conflicting information about this.
ContextCompat
documentation says system BroadcastReceivers need to be exported:
flags – If this receiver is listening for broadcasts sent from the system or from other apps—even other apps that you own—use the RECEIVER_EXPORTED flag. If instead this receiver is listening only for broadcasts sent by your app, use the RECEIVER_NOT_EXPORTED flag.
But Google says that's a security vulnerability and isn't allowed in Android 14 (system receivers should have no flag at all):
https://developer.android.com/about/versions/14/behavior-changes-14#system-broadcasts
Documentation in Context
seems to be most up to date, so I'm sticking with that:
For apps targeting Build.VERSION_CODES.UPSIDE_DOWN_CAKE, either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED must be specified if the receiver is not being registered for system broadcasts or a SecurityException will be thrown. See registerReceiver(BroadcastReceiver, IntentFilter, int) to register a receiver with flags.
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.
Maybe you misunderstood my comment?
I was saying that we don't really need to specify the parameter because RECEIVER_NOT_EXPORTED
is the default in Tuulbox: https://github.com/JuulLabs/tuulbox/blob/b592470845918d99e5d6c128243a5038e753fc38/coroutines/src/androidMain/kotlin/flow/BroadcastReceiverFlow.kt#L18
So, I wasn't saying we should not use RECEIVER_NOT_EXPORTED
, rather: that flag will be used (by Tuulbox) if we omit the parameter?
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 understood the comment, but it got me looking closer at the documentation since I realized it didn't jive with what Google's Android 14 migration docs said.
# Conflicts: # core/src/androidMain/kotlin/broadcastReceiverFlow.kt
Upgrades compile-sdk to Android 14 (34) and makes required BroadcastReceiver changes (must include export flag when registering).
Waiting on Tuulbox7.0.0
release.Internal ticket: CA-2225