From 0a48cb50168298ffc23c271531b77cc0127c4e98 Mon Sep 17 00:00:00 2001 From: Dave Heineman Date: Mon, 21 Feb 2022 15:19:34 +0100 Subject: [PATCH] fix: set required (im)mutable flag when creating pending intent When targeting SDK S+ (version 31 and above) a (im)mutable flags is required when creating a PendingInent. --- .../net/schueller/peertube/activity/VideoPlayActivity.kt | 9 +++++---- .../net/schueller/peertube/service/VideoPlayerService.kt | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.kt b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.kt index bdb4ae0..1887deb 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.kt +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.kt @@ -54,9 +54,10 @@ class VideoPlayActivity : CommonActivity() { val videoPlayerFragment = fragmentManager.findFragmentById(R.id.video_player_fragment) as VideoPlayerFragment? val actions = ArrayList() + val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 var actionIntent = Intent(getString(R.string.app_background_audio)) var pendingIntent = - PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0) + PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags) @SuppressLint("NewApi", "LocalSuppress") var icon = Icon.createWithResource( applicationContext, android.R.drawable.stat_sys_speakerphone ) @@ -65,7 +66,7 @@ class VideoPlayActivity : CommonActivity() { actions.add(remoteAction) actionIntent = Intent(PlayerNotificationManager.ACTION_STOP) pendingIntent = - PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0) + PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags) icon = Icon.createWithResource( applicationContext, com.google.android.exoplayer2.ui.R.drawable.exo_notification_stop @@ -77,7 +78,7 @@ class VideoPlayActivity : CommonActivity() { Log.e(TAG, "setting actions with play button") actionIntent = Intent(PlayerNotificationManager.ACTION_PLAY) pendingIntent = - PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0) + PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags) icon = Icon.createWithResource( applicationContext, com.google.android.exoplayer2.ui.R.drawable.exo_notification_play @@ -87,7 +88,7 @@ class VideoPlayActivity : CommonActivity() { Log.e(TAG, "setting actions with pause button") actionIntent = Intent(PlayerNotificationManager.ACTION_PAUSE) pendingIntent = - PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, 0) + PendingIntent.getBroadcast(applicationContext, REQUEST_CODE, actionIntent, flags) icon = Icon.createWithResource( applicationContext, com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.kt b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.kt index 80964c2..63ff046 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.kt +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.kt @@ -16,6 +16,7 @@ */ package net.schueller.peertube.service +import android.annotation.SuppressLint import android.app.Notification import net.schueller.peertube.helper.MetaDataHelper.getMetaString import net.schueller.peertube.model.Video.Companion.getMediaDescription @@ -46,6 +47,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.net.Uri import android.os.Binder +import android.os.Build import android.util.Log import android.webkit.URLUtil import androidx.core.app.NotificationCompat @@ -217,11 +219,15 @@ class VideoPlayerService : Service() { return currentVideo!!.name } + @SuppressLint("UnspecifiedImmutableFlag") override fun createCurrentContentIntent(player: Player): PendingIntent? { val intent = Intent(context, VideoPlayActivity::class.java) intent.putExtra(VideoListActivity.EXTRA_VIDEOID, currentVideo!!.uuid) - return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + else + PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } override fun getCurrentContentText(player: Player): CharSequence {