-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Mark PendingIntents with FLAG_IMMUTABLE #2124
Conversation
Checking for SDK_INT > 30 doesn't work because, while Android 12 is in developer preview, SDK_INT is still 30. FLAG_IMMUTABLE was introduced in M, so it can be used in M+ devices.
It looks like FLAG_IMMUTABLE was introduced in API 23, and FLAG_MUTABLE in Android 12. The requirement for using FLAG_IMMUTABLE was also added in Android 12. https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE As you pointed out, the SDK_INT for Android 12 is probably still API 30. I'm confused though, I thought this was fixed by #2090 . @ihrupin did you check that the crash was fixed? |
@@ -40,7 +40,7 @@ internal class NotificationReceiver : BroadcastReceiver() { | |||
): PendingIntent { | |||
val broadcastIntent = Intent(context, NotificationReceiver::class.java) | |||
broadcastIntent.action = action.name | |||
val flags = if (Build.VERSION.SDK_INT > 30) { | |||
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
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.
Why >= Build.VERSION_CODES.M
and not just >= 30
?
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.
Also, should we instead use >= 23
?
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.
It's true that ">= 30" would work for fixing the crash on S.
That being said, I think ">= 23" makes more sense. Specifying pending intent immutability is desirable, so why not do it on every Android version in which it's possible to do so?
Regarding 23 vs M, I believe VERSION_CODES.M is more explicit. Looking at existing SDK_INT checks in leakcanary, there is a mix of VERSION_CODES.x and plain numbers. If you prefer to use 23, that would work too.
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.
Our Lord Jake has spoken: https://twitter.com/JakeWharton/status/1049421501559128065
I probably missed some spots though.
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.
Let's go with 23 if you don't mind.
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 disagree with that, but who am I to question? ;)
Amended to 23.
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.
Just to clarify, are there any other concerns? Thanks!
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.
Nope, thanks!
The crash isn't fixed with #2090 (or at least I can reproduce with DP3). |
Great to see there's a fix for this. Any chance that it's going to be released? |
It will definitely be released some day. I don't know if that'll happen while I'm on paternity leave. |
Mark PendingIntents with FLAG_IMMUTABLE
Checking for SDK_INT > 30 doesn't work on Android 12 because, while it is in developer preview, SDK_INT is still 30. FLAG_IMMUTABLE was introduced in M, so it can be used in M+ devices.