Skip to content
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

Merged
merged 2 commits into from
May 14, 2021
Merged

Mark PendingIntents with FLAG_IMMUTABLE #2124

merged 2 commits into from
May 14, 2021

Conversation

matiash
Copy link
Contributor

@matiash matiash commented May 11, 2021

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.

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.
@CLAassistant
Copy link

CLAassistant commented May 11, 2021

CLA assistant check
All committers have signed the CLA.

@pyricau
Copy link
Member

pyricau commented May 11, 2021

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) {
Copy link
Member

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 ?

Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

Copy link
Member

Choose a reason for hiding this comment

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

Nope, thanks!

@matiash
Copy link
Contributor Author

matiash commented May 12, 2021

The crash isn't fixed with #2090 (or at least I can reproduce with DP3).

@pyricau pyricau merged commit 14d724d into square:main May 14, 2021
@eartle
Copy link

eartle commented Jun 15, 2021

Great to see there's a fix for this. Any chance that it's going to be released?

@pyricau
Copy link
Member

pyricau commented Jun 26, 2021

It will definitely be released some day. I don't know if that'll happen while I'm on paternity leave.

ghost pushed a commit to shivagowda/leakcanary that referenced this pull request Nov 9, 2021
Mark PendingIntents with FLAG_IMMUTABLE
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.

None yet

4 participants