mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 09:58:08 +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:
parent
551b089d9a
commit
ba98e21d40
@ -163,7 +163,7 @@ class BackgroundService : Service() {
|
||||
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 {
|
||||
setSmallIcon(R.drawable.ic_notification)
|
||||
setOngoing(true)
|
||||
@ -189,7 +189,7 @@ class BackgroundService : Service() {
|
||||
// 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) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ class BackgroundService : Service() {
|
||||
// Setting up Send File Intent.
|
||||
val sendFile = Intent(this, SendFileActivity::class.java)
|
||||
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)
|
||||
|
||||
// Checking if there are registered commands and adding the button.
|
||||
@ -209,7 +209,7 @@ class BackgroundService : Service() {
|
||||
if (plugin != null && plugin.commandList.isNotEmpty()) {
|
||||
val runCommand = Intent(this, RunCommandActivity::class.java)
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -249,7 +249,7 @@ class BackgroundService : Service() {
|
||||
companion object {
|
||||
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
|
||||
|
||||
@JvmStatic
|
||||
|
@ -257,7 +257,7 @@ class Device : PacketReceiver {
|
||||
context,
|
||||
1,
|
||||
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 {
|
||||
@ -273,13 +273,13 @@ class Device : PacketReceiver {
|
||||
context,
|
||||
2,
|
||||
acceptIntent,
|
||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val rejectedPendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
4,
|
||||
rejectIntent,
|
||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
val res = context.resources
|
||||
|
@ -28,7 +28,7 @@ public class IntentHelper {
|
||||
*/
|
||||
public static void startActivityFromBackgroundOrCreateNotification(Context context, Intent intent, String title) {
|
||||
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
|
||||
.Builder(context, NotificationHelper.Channels.HIGHPRIORITY)
|
||||
.setContentIntent(pendingIntent)
|
||||
|
@ -141,7 +141,7 @@ public class FindMyPhonePlugin extends Plugin {
|
||||
intent.setAction(FindMyPhoneReceiver.ACTION_FOUND_IT);
|
||||
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);
|
||||
}
|
||||
@ -150,7 +150,7 @@ public class FindMyPhonePlugin extends Plugin {
|
||||
Intent intent = new Intent(context, FindMyPhoneActivity.class);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
|
||||
context,
|
||||
0,
|
||||
iPlay,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val aPlay = NotificationCompat.Action.Builder(
|
||||
R.drawable.ic_play_white, context!!.getString(R.string.mpris_play), piPlay
|
||||
@ -317,7 +317,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
|
||||
context,
|
||||
0,
|
||||
iPause,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val aPause = NotificationCompat.Action.Builder(
|
||||
R.drawable.ic_pause_white, context!!.getString(R.string.mpris_pause), piPause
|
||||
@ -332,7 +332,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
|
||||
context,
|
||||
0,
|
||||
iPrevious,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val aPrevious = NotificationCompat.Action.Builder(
|
||||
R.drawable.ic_previous_white, context!!.getString(R.string.mpris_previous), piPrevious
|
||||
@ -347,7 +347,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
|
||||
context,
|
||||
0,
|
||||
iNext,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val aNext = NotificationCompat.Action.Builder(
|
||||
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!!)
|
||||
.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)
|
||||
|
||||
@ -398,7 +398,7 @@ class MprisMediaSession : OnSharedPreferenceChangeListener, NotificationReceiver
|
||||
context,
|
||||
0,
|
||||
iCloseNotification,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
notification.setDeleteIntent(piCloseNotification)
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class PingPlugin : Plugin() {
|
||||
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 (id: Int, message: String) = if (np.has("message")) {
|
||||
|
@ -77,7 +77,7 @@ public class ReceiveNotificationsPlugin extends Plugin {
|
||||
context,
|
||||
0,
|
||||
new Intent(context, MainActivity.class),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||
);
|
||||
|
||||
Bitmap largeIcon = null;
|
||||
|
@ -187,6 +187,7 @@ private fun assignListIntent(context: Context, appWidgetId: Int, views: RemoteVi
|
||||
val runCommandTemplateIntent = Intent(context, RunCommandWidgetProvider::class.java)
|
||||
runCommandTemplateIntent.action = RUN_COMMAND_ACTION
|
||||
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)
|
||||
views.setPendingIntentTemplate(R.id.widget_command_list, runCommandTemplatePendingIntent)
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class ReceiveNotification {
|
||||
cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE);
|
||||
cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId);
|
||||
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);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class UploadNotification {
|
||||
cancelIntent.setAction(SharePlugin.ACTION_CANCEL_SHARE);
|
||||
cancelIntent.putExtra(SharePlugin.CANCEL_SHARE_BACKGROUND_JOB_ID_EXTRA, jobId);
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user