From ef25be8f1b574e3c34969071cb24e63ef503e405 Mon Sep 17 00:00:00 2001 From: Ahmad Vazirna Date: Thu, 28 Nov 2024 21:36:40 +0200 Subject: [PATCH] Fix pendingIntent mutability flag --- .../services/CommCareFirebaseMessagingService.java | 10 +++++----- .../org/commcare/services/CommCareSessionService.java | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/org/commcare/services/CommCareFirebaseMessagingService.java b/app/src/org/commcare/services/CommCareFirebaseMessagingService.java index f189193956..96826247ee 100644 --- a/app/src/org/commcare/services/CommCareFirebaseMessagingService.java +++ b/app/src/org/commcare/services/CommCareFirebaseMessagingService.java @@ -92,11 +92,11 @@ private void showNotification(RemoteMessage.Notification notification) { i.setAction(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); - PendingIntent contentIntent; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_IMMUTABLE); - else - contentIntent = PendingIntent.getActivity(this, 0, i, 0); + int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + pendingIntentFlags = pendingIntentFlags | PendingIntent.FLAG_IMMUTABLE; + } + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, pendingIntentFlags); NotificationCompat.Builder fcmNotification = new NotificationCompat.Builder(this, CommCareNoficationManager.NOTIFICATION_CHANNEL_PUSH_NOTIFICATIONS_ID) diff --git a/app/src/org/commcare/services/CommCareSessionService.java b/app/src/org/commcare/services/CommCareSessionService.java index 7aa18dcdca..7e3770423a 100644 --- a/app/src/org/commcare/services/CommCareSessionService.java +++ b/app/src/org/commcare/services/CommCareSessionService.java @@ -706,12 +706,11 @@ private Notification createSessionNotification(){ callable.setAction("android.intent.action.MAIN"); callable.addCategory("android.intent.category.LAUNCHER"); - // The PendingIntent to launch our activity if the user selects this notification - PendingIntent contentIntent; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - contentIntent = PendingIntent.getActivity(this, 0, callable, PendingIntent.FLAG_IMMUTABLE); - else - contentIntent = PendingIntent.getActivity(this, 0, callable, 0); + int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + pendingIntentFlags = pendingIntentFlags | PendingIntent.FLAG_IMMUTABLE; + } + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, callable, pendingIntentFlags); String notificationText; if (AppUtils.getInstalledAppRecords().size() > 1) {