2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-28 20:57:42 +00:00

Make every pending intent immutable except the one for the widget

The widget runs as part of the launcher (so, a different app) which needs
to modify the intent to tell us what command the user selected.
This commit is contained in:
Albert Vaca Cintora 2024-10-08 22:12:47 +02:00
parent 551b089d9a
commit ba98e21d40
No known key found for this signature in database
10 changed files with 22 additions and 21 deletions

View File

@ -163,7 +163,7 @@ class BackgroundService : Service() {
intent.putExtra(MainActivity.EXTRA_DEVICE_ID, connectedDeviceIds[0]) intent.putExtra(MainActivity.EXTRA_DEVICE_ID, connectedDeviceIds[0])
} }
val pi = PendingIntent.getActivity(this, 0, intent, UPDATE_MUTABLE_FLAGS) val pi = PendingIntent.getActivity(this, 0, intent, UPDATE_IMMUTABLE_FLAGS)
val notification = NotificationCompat.Builder(this, NotificationHelper.Channels.PERSISTENT).apply { val notification = NotificationCompat.Builder(this, NotificationHelper.Channels.PERSISTENT).apply {
setSmallIcon(R.drawable.ic_notification) setSmallIcon(R.drawable.ic_notification)
setOngoing(true) setOngoing(true)
@ -189,7 +189,7 @@ class BackgroundService : Service() {
// Adding an action button to send clipboard manually in Android 10 and later. // Adding an action button to send clipboard manually in Android 10 and later.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_LOGS) == PackageManager.PERMISSION_DENIED) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_LOGS) == PackageManager.PERMISSION_DENIED) {
val sendClipboard = ClipboardFloatingActivity.getIntent(this, true) val sendClipboard = ClipboardFloatingActivity.getIntent(this, true)
val sendPendingClipboard = PendingIntent.getActivity(this, 3, sendClipboard, UPDATE_MUTABLE_FLAGS) val sendPendingClipboard = PendingIntent.getActivity(this, 3, sendClipboard, UPDATE_IMMUTABLE_FLAGS)
notification.addAction(0, getString(R.string.foreground_notification_send_clipboard), sendPendingClipboard) notification.addAction(0, getString(R.string.foreground_notification_send_clipboard), sendPendingClipboard)
} }
@ -201,7 +201,7 @@ class BackgroundService : Service() {
// Setting up Send File Intent. // Setting up Send File Intent.
val sendFile = Intent(this, SendFileActivity::class.java) val sendFile = Intent(this, SendFileActivity::class.java)
sendFile.putExtra("deviceId", deviceId) sendFile.putExtra("deviceId", deviceId)
val sendPendingFile = PendingIntent.getActivity(this, 1, sendFile, UPDATE_MUTABLE_FLAGS) val sendPendingFile = PendingIntent.getActivity(this, 1, sendFile, UPDATE_IMMUTABLE_FLAGS)
notification.addAction(0, getString(R.string.send_files), sendPendingFile) notification.addAction(0, getString(R.string.send_files), sendPendingFile)
// Checking if there are registered commands and adding the button. // Checking if there are registered commands and adding the button.
@ -209,7 +209,7 @@ class BackgroundService : Service() {
if (plugin != null && plugin.commandList.isNotEmpty()) { if (plugin != null && plugin.commandList.isNotEmpty()) {
val runCommand = Intent(this, RunCommandActivity::class.java) val runCommand = Intent(this, RunCommandActivity::class.java)
runCommand.putExtra("deviceId", connectedDeviceIds[0]) runCommand.putExtra("deviceId", connectedDeviceIds[0])
val runPendingCommand = PendingIntent.getActivity(this, 2, runCommand, UPDATE_MUTABLE_FLAGS) val runPendingCommand = PendingIntent.getActivity(this, 2, runCommand, UPDATE_IMMUTABLE_FLAGS)
notification.addAction(0, getString(R.string.pref_plugin_runcommand), runPendingCommand) notification.addAction(0, getString(R.string.pref_plugin_runcommand), runPendingCommand)
} }
} }
@ -249,7 +249,7 @@ class BackgroundService : Service() {
companion object { companion object {
const val LOG_TAG = "KDE/BackgroundService" const val LOG_TAG = "KDE/BackgroundService"
const val UPDATE_MUTABLE_FLAGS = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE const val UPDATE_IMMUTABLE_FLAGS = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
private const val FOREGROUND_NOTIFICATION_ID = 1 private const val FOREGROUND_NOTIFICATION_ID = 1
@JvmStatic @JvmStatic

View File

@ -257,7 +257,7 @@ class Device : PacketReceiver {
context, context,
1, 1,
intent, intent,
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
val acceptIntent = Intent(context, MainActivity::class.java).apply { val acceptIntent = Intent(context, MainActivity::class.java).apply {
@ -273,13 +273,13 @@ class Device : PacketReceiver {
context, context,
2, 2,
acceptIntent, acceptIntent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
) )
val rejectedPendingIntent = PendingIntent.getActivity( val rejectedPendingIntent = PendingIntent.getActivity(
context, context,
4, 4,
rejectIntent, rejectIntent,
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
) )
val res = context.resources val res = context.resources

View File

@ -28,7 +28,7 @@ public class IntentHelper {
*/ */
public static void startActivityFromBackgroundOrCreateNotification(Context context, Intent intent, String title) { public static void startActivityFromBackgroundOrCreateNotification(Context context, Intent intent, String title) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !LifecycleHelper.isInForeground()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !LifecycleHelper.isInForeground()) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_MUTABLE); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
Notification notification = new NotificationCompat Notification notification = new NotificationCompat
.Builder(context, NotificationHelper.Channels.HIGHPRIORITY) .Builder(context, NotificationHelper.Channels.HIGHPRIORITY)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)

View File

@ -141,7 +141,7 @@ public class FindMyPhonePlugin extends Plugin {
intent.setAction(FindMyPhoneReceiver.ACTION_FOUND_IT); intent.setAction(FindMyPhoneReceiver.ACTION_FOUND_IT);
intent.putExtra(FindMyPhoneReceiver.EXTRA_DEVICE_ID, getDevice().getDeviceId()); intent.putExtra(FindMyPhoneReceiver.EXTRA_DEVICE_ID, getDevice().getDeviceId());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
createNotification(pendingIntent); createNotification(pendingIntent);
} }
@ -150,7 +150,7 @@ public class FindMyPhonePlugin extends Plugin {
Intent intent = new Intent(context, FindMyPhoneActivity.class); Intent intent = new Intent(context, FindMyPhoneActivity.class);
intent.putExtra(FindMyPhoneActivity.EXTRA_DEVICE_ID, getDevice().getDeviceId()); intent.putExtra(FindMyPhoneActivity.EXTRA_DEVICE_ID, getDevice().getDeviceId());
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
createNotification(pi); createNotification(pi);
} }

View File

@ -302,7 +302,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
context, context,
0, 0,
iPlay, iPlay,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
val aPlay = NotificationCompat.Action.Builder( val aPlay = NotificationCompat.Action.Builder(
R.drawable.ic_play_white, context!!.getString(R.string.mpris_play), piPlay R.drawable.ic_play_white, context!!.getString(R.string.mpris_play), piPlay
@ -317,7 +317,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
context, context,
0, 0,
iPause, iPause,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
val aPause = NotificationCompat.Action.Builder( val aPause = NotificationCompat.Action.Builder(
R.drawable.ic_pause_white, context!!.getString(R.string.mpris_pause), piPause R.drawable.ic_pause_white, context!!.getString(R.string.mpris_pause), piPause
@ -332,7 +332,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
context, context,
0, 0,
iPrevious, iPrevious,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
val aPrevious = NotificationCompat.Action.Builder( val aPrevious = NotificationCompat.Action.Builder(
R.drawable.ic_previous_white, context!!.getString(R.string.mpris_previous), piPrevious R.drawable.ic_previous_white, context!!.getString(R.string.mpris_previous), piPrevious
@ -347,7 +347,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
context, context,
0, 0,
iNext, iNext,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
val aNext = NotificationCompat.Action.Builder( val aNext = NotificationCompat.Action.Builder(
R.drawable.ic_next_white, context!!.getString(R.string.mpris_next), piNext R.drawable.ic_next_white, context!!.getString(R.string.mpris_next), piNext
@ -360,7 +360,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
val piOpenActivity = TaskStackBuilder.create(context!!) val piOpenActivity = TaskStackBuilder.create(context!!)
.addNextIntentWithParentStack(iOpenActivity) .addNextIntentWithParentStack(iOpenActivity)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val notification = NotificationCompat.Builder(context!!, NotificationHelper.Channels.MEDIA_CONTROL) val notification = NotificationCompat.Builder(context!!, NotificationHelper.Channels.MEDIA_CONTROL)
@ -398,7 +398,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
context, context,
0, 0,
iCloseNotification, iCloseNotification,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
notification.setDeleteIntent(piCloseNotification) notification.setDeleteIntent(piCloseNotification)
} }

View File

@ -42,7 +42,7 @@ class PingPlugin : Plugin() {
return false return false
} }
val mutableUpdateFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE val mutableUpdateFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
val resultPendingIntent = PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), mutableUpdateFlags) val resultPendingIntent = PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), mutableUpdateFlags)
val (id: Int, message: String) = if (np.has("message")) { val (id: Int, message: String) = if (np.has("message")) {

View File

@ -77,7 +77,7 @@ public class ReceiveNotificationsPlugin extends Plugin {
context, context,
0, 0,
new Intent(context, MainActivity.class), new Intent(context, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
); );
Bitmap largeIcon = null; Bitmap largeIcon = null;

View File

@ -187,6 +187,7 @@ private fun assignListIntent(context: Context, appWidgetId: Int, views: RemoteVi
val runCommandTemplateIntent = Intent(context, RunCommandWidgetProvider::class.java) val runCommandTemplateIntent = Intent(context, RunCommandWidgetProvider::class.java)
runCommandTemplateIntent.action = RUN_COMMAND_ACTION runCommandTemplateIntent.action = RUN_COMMAND_ACTION
runCommandTemplateIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId) runCommandTemplateIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId)
// Needs to be mutable because the launcher will modify it to indicate which command was selected
val runCommandTemplatePendingIntent = PendingIntent.getBroadcast(context, appWidgetId, runCommandTemplateIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE) val runCommandTemplatePendingIntent = PendingIntent.getBroadcast(context, appWidgetId, runCommandTemplateIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
views.setPendingIntentTemplate(R.id.widget_command_list, runCommandTemplatePendingIntent) views.setPendingIntentTemplate(R.id.widget_command_list, runCommandTemplatePendingIntent)
} }

View File

@ -69,7 +69,7 @@ class ReceiveNotification {
cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE); cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE);
cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId); cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId);
cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA, device.getDeviceId()); cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA, device.getDeviceId());
PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(device.getContext(), 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(device.getContext(), 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
builder.addAction(R.drawable.ic_reject_pairing_24dp, device.getContext().getString(R.string.cancel), cancelPendingIntent); builder.addAction(R.drawable.ic_reject_pairing_24dp, device.getContext().getString(R.string.cancel), cancelPendingIntent);
} }

View File

@ -47,7 +47,7 @@ class UploadNotification {
cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE); cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE);
cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId); cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId);
cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA, device.getDeviceId()); cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_DEVICE_ID_EXTRA, device.getDeviceId());
PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(device.getContext(), 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(device.getContext(), 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
builder.addAction(R.drawable.ic_reject_pairing_24dp, device.getContext().getString(R.string.cancel), cancelPendingIntent); builder.addAction(R.drawable.ic_reject_pairing_24dp, device.getContext().getString(R.string.cancel), cancelPendingIntent);
} }