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

Update push notification to support Android SDK 31+ #10914

Merged
merged 5 commits into from
Feb 1, 2023

Conversation

cshfang
Copy link
Member

@cshfang cshfang commented Jan 31, 2023

Description of changes

Android 12 included two behavior changes which affected Amplify push notification:

  1. Pending intents mutability - PendingIntents now require mutability flag to be specified
  2. Notification trampoline restrictions - Services and broadcast receivers can no longer start activities

This PR updates Amplify push notification to address these two behavioral changes:

  1. PendingIntents now include mutability flag (set to immutable)
  2. Activity opening is now built into the notification's content intent. As a result, the broadcast receiver for notifications is bypassed and thus no longer needed.

This PR also cleans up the state of the Android artifacts checked into this repo to remove the .gradle/ folder but include the gradle wrapper.

Issue #, if available

#10118 May not actually be relevant
#10252

Description of how you validated changes

Tested locally with sample Android apps targeting < SDK 31 and >= SDK 31

Checklist

  • PR description included

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@cshfang cshfang requested a review from a team as a code owner January 31, 2023 18:33
@cshfang cshfang changed the title Fix/issue 10252 Update push notification to support Android SDK 31+ Jan 31, 2023
Copy link
Contributor

@jimblanc jimblanc left a comment

Choose a reason for hiding this comment

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

LGTM, discussed gradle wrappers offline.

Copy link
Member

@Samaritan1011001 Samaritan1011001 left a comment

Choose a reason for hiding this comment

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

Just two questions.

@@ -78,7 +81,7 @@ private PendingIntent toScheduleNotificationIntent(Bundle bundle) {
notificationIntent.putExtra(RNPushNotificationPublisher.NOTIFICATION_ID, notificationID);
notificationIntent.putExtras(bundle);

return PendingIntent.getBroadcast(context, notificationID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getBroadcast(context, notificationID, notificationIntent, getPendingIntentFlags());
Copy link
Member

Choose a reason for hiding this comment

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

Should this be getActivity?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not update these as our library does not support scheduled notifications at this time despite including this underlying native code

@@ -353,16 +353,11 @@ public void sendToNotificationCentre(Bundle bundle) {
// Add "action" for later identifying which button gets pressed.
bundle.putString("action", action);
actionIntent.putExtra("notification", bundle);
PendingIntent pendingActionIntent = PendingIntent.getBroadcast(context, notificationID, actionIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingActionIntent = PendingIntent.getBroadcast(context, notificationID, actionIntent, getPendingIntentFlags());
Copy link
Member

Choose a reason for hiding this comment

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

Should this be getActivity too?

Copy link
Member Author

@cshfang cshfang Jan 31, 2023

Choose a reason for hiding this comment

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

Ditto here in that we don't really support actions ootb

Copy link
Member

@Samaritan1011001 Samaritan1011001 left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

3 participants