immutable flag for PendingIntent

This commit is contained in:
Milos Kozak 2021-06-02 16:56:13 +02:00
parent ec73c4b0cb
commit 74dfe80433
7 changed files with 14 additions and 14 deletions

View file

@ -311,15 +311,15 @@ open class LoopPlugin @Inject constructor(
if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) { if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) {
val intentAction5m = Intent(context, CarbSuggestionReceiver::class.java) val intentAction5m = Intent(context, CarbSuggestionReceiver::class.java)
intentAction5m.putExtra("ignoreDuration", 5) intentAction5m.putExtra("ignoreDuration", 5)
val pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
val actionIgnore5m = NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore5m, "Ignore 5m"), pendingIntent5m) val actionIgnore5m = NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore5m, "Ignore 5m"), pendingIntent5m)
val intentAction15m = Intent(context, CarbSuggestionReceiver::class.java) val intentAction15m = Intent(context, CarbSuggestionReceiver::class.java)
intentAction15m.putExtra("ignoreDuration", 15) intentAction15m.putExtra("ignoreDuration", 15)
val pendingIntent15m = PendingIntent.getBroadcast(context, 1, intentAction15m, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent15m = PendingIntent.getBroadcast(context, 1, intentAction15m, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
val actionIgnore15m = NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore15m, "Ignore 15m"), pendingIntent15m) val actionIgnore15m = NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore15m, "Ignore 15m"), pendingIntent15m)
val intentAction30m = Intent(context, CarbSuggestionReceiver::class.java) val intentAction30m = Intent(context, CarbSuggestionReceiver::class.java)
intentAction30m.putExtra("ignoreDuration", 30) intentAction30m.putExtra("ignoreDuration", 30)
val pendingIntent30m = PendingIntent.getBroadcast(context, 1, intentAction30m, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent30m = PendingIntent.getBroadcast(context, 1, intentAction30m, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
val actionIgnore30m = NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore30m, "Ignore 30m"), pendingIntent30m) val actionIgnore30m = NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore30m, "Ignore 30m"), pendingIntent30m)
val builder = NotificationCompat.Builder(context, CHANNEL_ID) val builder = NotificationCompat.Builder(context, CHANNEL_ID)
builder.setSmallIcon(R.drawable.notif_icon) builder.setSmallIcon(R.drawable.notif_icon)
@ -441,7 +441,7 @@ open class LoopPlugin @Inject constructor(
stackBuilder.addParentStack(MainActivity::class.java) stackBuilder.addParentStack(MainActivity::class.java)
// Adds the Intent that starts the Activity to the top of the stack // Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent) stackBuilder.addNextIntent(resultIntent)
val resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) val resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
builder.setContentIntent(resultPendingIntent) builder.setContentIntent(resultPendingIntent)
builder.setVibrate(longArrayOf(1000, 1000, 1000, 1000, 1000)) builder.setVibrate(longArrayOf(1000, 1000, 1000, 1000, 1000))
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

View file

@ -128,7 +128,7 @@ class NotificationStore @Inject constructor(
private fun deleteIntent(id: Int): PendingIntent { private fun deleteIntent(id: Int): PendingIntent {
val intent = Intent(context, DismissNotificationService::class.java) val intent = Intent(context, DismissNotificationService::class.java)
intent.putExtra("alertID", id) intent.putExtra("alertID", id)
return PendingIntent.getService(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT) return PendingIntent.getService(context, id, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} }
fun createNotificationChannel() { fun createNotificationChannel() {

View file

@ -171,7 +171,7 @@ class PersistentNotificationPlugin @Inject constructor(
val msgReadPendingIntent = PendingIntent.getBroadcast(context, val msgReadPendingIntent = PendingIntent.getBroadcast(context,
notificationHolder.notificationID, notificationHolder.notificationID,
msgReadIntent, msgReadIntent,
PendingIntent.FLAG_UPDATE_CURRENT) PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
val msgReplyIntent = Intent() val msgReplyIntent = Intent()
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES) .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
.setAction(REPLY_ACTION) .setAction(REPLY_ACTION)
@ -181,7 +181,7 @@ class PersistentNotificationPlugin @Inject constructor(
context, context,
notificationHolder.notificationID, notificationHolder.notificationID,
msgReplyIntent, msgReplyIntent,
PendingIntent.FLAG_UPDATE_CURRENT) PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
// Build a RemoteInput for receiving voice input from devices // Build a RemoteInput for receiving voice input from devices
val remoteInput = RemoteInput.Builder(EXTRA_VOICE_REPLY).build() val remoteInput = RemoteInput.Builder(EXTRA_VOICE_REPLY).build()
// Create the UnreadConversation // Create the UnreadConversation

View file

@ -40,6 +40,6 @@ class NotificationHolderImpl @Inject constructor(
override fun openAppIntent(context: Context): PendingIntent? = TaskStackBuilder.create(context).run { override fun openAppIntent(context: Context): PendingIntent? = TaskStackBuilder.create(context).run {
addParentStack(MainActivity::class.java) addParentStack(MainActivity::class.java)
addNextIntent(Intent(context, MainActivity::class.java)) addNextIntent(Intent(context, MainActivity::class.java))
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} }
} }

View file

@ -302,17 +302,17 @@ public class InsightAlertService extends DaggerService implements InsightConnect
notificationBuilder.setContentText(HtmlHelper.INSTANCE.fromHtml(description).toString()); notificationBuilder.setContentText(HtmlHelper.INSTANCE.fromHtml(description).toString());
Intent fullScreenIntent = new Intent(this, InsightAlertActivity.class); Intent fullScreenIntent = new Intent(this, InsightAlertActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, fullScreenIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true); notificationBuilder.setFullScreenIntent(fullScreenPendingIntent, true);
switch (alert.getAlertStatus()) { switch (alert.getAlertStatus()) {
case ACTIVE: case ACTIVE:
Intent muteIntent = new Intent(this, InsightAlertService.class).putExtra("command", "mute"); Intent muteIntent = new Intent(this, InsightAlertService.class).putExtra("command", "mute");
PendingIntent mutePendingIntent = PendingIntent.getService(this, 1, muteIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent mutePendingIntent = PendingIntent.getService(this, 1, muteIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(0, resourceHelper.gs(R.string.mute_alert), mutePendingIntent); notificationBuilder.addAction(0, resourceHelper.gs(R.string.mute_alert), mutePendingIntent);
case SNOOZED: case SNOOZED:
Intent confirmIntent = new Intent(this, InsightAlertService.class).putExtra("command", "confirm"); Intent confirmIntent = new Intent(this, InsightAlertService.class).putExtra("command", "confirm");
PendingIntent confirmPendingIntent = PendingIntent.getService(this, 2, confirmIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent confirmPendingIntent = PendingIntent.getService(this, 2, confirmIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(0, resourceHelper.gs(R.string.confirm), confirmPendingIntent); notificationBuilder.addAction(0, resourceHelper.gs(R.string.confirm), confirmPendingIntent);
} }

View file

@ -142,7 +142,7 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
// Pass complicationId as the requestCode to ensure that different complications get // Pass complicationId as the requestCode to ensure that different complications get
// different intents. // different intents.
return PendingIntent.getBroadcast( return PendingIntent.getBroadcast(
context, complicationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, complicationId, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
} }
/** /**
@ -161,7 +161,7 @@ public class ComplicationTapBroadcastReceiver extends BroadcastReceiver {
// Pass complicationId as the requestCode to ensure that different complications get // Pass complicationId as the requestCode to ensure that different complications get
// different intents. // different intents.
return PendingIntent.getBroadcast( return PendingIntent.getBroadcast(
context, complicationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, complicationId, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
} }
} }

View file

@ -589,7 +589,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
intent.putExtras(params); intent.putExtras(params);
PendingIntent resultPendingIntent = PendingIntent resultPendingIntent =
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
builder = builder.setContentIntent(resultPendingIntent); builder = builder.setContentIntent(resultPendingIntent);