From 9813c905c98c553728b48725e29231e7f6a6093c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 9 Sep 2021 11:58:38 +0200 Subject: [PATCH] Fixed missing pending intent IMMUTABLE flag causing crash on Android 12 --- app/build.gradle | 2 +- .../notifications/NotificationsManager.kt | 35 +++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ff15054e0..c57757371 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -218,7 +218,7 @@ dependencies { implementation 'androidx.fragment:fragment-ktx:1.4.0-alpha08' implementation 'androidx.core:core-ktx:1.7.0-alpha02' - def nav_version = "2.3.5" + def nav_version = "2.4.0-alpha08" implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 213c7e4d7..0650388e9 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -397,7 +397,12 @@ class NotificationsManager(private val context: Context) { val incomingCallNotificationIntent = Intent(context, IncomingCallActivity::class.java) incomingCallNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - val pendingIntent = PendingIntent.getActivity(context, 0, incomingCallNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val pendingIntent = PendingIntent.getActivity( + context, + 0, + incomingCallNotificationIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE + ) val notificationLayoutHeadsUp = RemoteViews(context.packageName, R.layout.call_incoming_notification_heads_up) notificationLayoutHeadsUp.setTextViewText(R.id.caller, displayName) @@ -545,7 +550,12 @@ class NotificationsManager(private val context: Context) { val callNotificationIntent = Intent(context, callActivity) callNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - val pendingIntent = PendingIntent.getActivity(context, 0, callNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val pendingIntent = PendingIntent.getActivity( + context, + 0, + callNotificationIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE + ) val builder = NotificationCompat.Builder( context, channelToUse @@ -612,7 +622,12 @@ class NotificationsManager(private val context: Context) { val target = Intent(context, ChatBubbleActivity::class.java) target.putExtra("RemoteSipUri", peerAddress) target.putExtra("LocalSipUri", localAddress) - val bubbleIntent = PendingIntent.getActivity(context, notifiable.notificationId, target, PendingIntent.FLAG_UPDATE_CURRENT) + val bubbleIntent = PendingIntent.getActivity( + context, + notifiable.notificationId, + target, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE + ) val id = LinphoneUtils.getChatRoomId(localAddress, peerAddress) val notification = createMessageNotification(notifiable, pendingIntent, bubbleIntent, id) @@ -816,7 +831,10 @@ class NotificationsManager(private val context: Context) { answerIntent.putExtra(INTENT_REMOTE_ADDRESS, notifiable.remoteAddress) val answerPendingIntent = PendingIntent.getBroadcast( - context, notifiable.notificationId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT + context, + notifiable.notificationId, + answerIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) return NotificationCompat.Action.Builder( @@ -833,7 +851,10 @@ class NotificationsManager(private val context: Context) { hangupIntent.putExtra(INTENT_REMOTE_ADDRESS, notifiable.remoteAddress) val hangupPendingIntent = PendingIntent.getBroadcast( - context, notifiable.notificationId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT + context, + notifiable.notificationId, + hangupIntent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) return NotificationCompat.Action.Builder( @@ -859,7 +880,7 @@ class NotificationsManager(private val context: Context) { context, notifiable.notificationId, replyIntent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) return NotificationCompat.Action.Builder( R.drawable.chat_send_over, @@ -883,7 +904,7 @@ class NotificationsManager(private val context: Context) { context, notifiable.notificationId, markAsReadIntent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE ) }