Skip to content

Conversation

rachaprince
Copy link

@rachaprince rachaprince commented Mar 8, 2022

Add a mutability flag to the pending intent to support apps targeting android 12.

See https://developer.android.com/guide/components/intents-filters#DeclareMutabilityPendingIntent

We use a pending intent because this is sent to the Notifications Manager. See https://developer.android.com/guide/components/intents-filters#PendingIntent

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 8, 2022

Coverage Report 1

Affected Products

  • firebase-appdistribution

    Overall coverage changed from 76.55% (5b10051) to 76.34% (ceb0390) by -0.22%.

    FilenameBase (5b10051)Merge (ceb0390)Diff
    FirebaseAppDistributionNotificationsManager.java92.68%84.44%-8.24%

Test Logs

Notes

  • Commit (ceb0390) is created by Prow via merging PR base commit (5b10051) and head commit (d2e8426).
  • Run gradle <product>:checkCoverage to produce HTML coverage reports locally. After gradle commands finished, report files can be found under <product-build-dir>/reports/jacoco/.

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/oiOe1qDsFA.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 8, 2022

Size Report 1

Affected Products

  • firebase-appdistribution

    TypeBase (5b10051)Merge (ceb0390)Diff
    aar124 kB124 kB+93 B (+0.1%)
    apk (release)1.57 MB1.57 MB+56 B (+0.0%)

Test Logs

Notes

  • Commit (ceb0390) is created by Prow via merging PR base commit (5b10051) and head commit (d2e8426).

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/uXKJOWkrIo.html

@@ -110,6 +110,7 @@ private PendingIntent createAppLaunchIntent() {
LogWrapper.getInstance().w(TAG + "No activity found to launch app");
return null;
}
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
return PendingIntent.getActivity(
context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me wonder if we should avoid using FLAG_IMMUTABLE on older SDK versions:

private static int getPendingIntentFlags(int baseFlags) {
// Only add on platform levels that support FLAG_IMMUTABLE.
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
? baseFlags | PendingIntent.FLAG_IMMUTABLE
: baseFlags;

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it looks like FLAG_IMMUTABLE was only added in API level 23 (M) https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE

Copy link
Member

Choose a reason for hiding this comment

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

The issue is that your sdk has misSdkVersion = 16, so it could crash at runtime?

Copy link
Contributor

Choose a reason for hiding this comment

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

But the check against Build.VERSION.SDK_INT would prevent that crash, right @vkryachko ?

Copy link
Member

Choose a reason for hiding this comment

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

right, but I don't see the check it in the pr, and I thought that in your previous comment you were suggesting that it's safe not to do the check given that this flag is 23+. If we have the check then it shouldn't be a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, no, sorry. I meant we need to add the check. We'll do that now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

@google-oss-bot
Copy link
Contributor

@rachaprince: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
smoke-tests d2e8426 link /test smoke-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@lfkellogg lfkellogg merged commit 2099192 into master Mar 8, 2022
@lfkellogg lfkellogg deleted the fix-android-12-pending-intent-bug branch March 8, 2022 16:37
jeremyjiang-dev pushed a commit that referenced this pull request Mar 9, 2022
* Add mutability flag to pending intent

* Fix styles

* Only add FLAG_IMMUTABLE on SDK level 23+

Co-authored-by: Lee Kellogg <lkellogg@google.com>
@firebase firebase locked and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants