Use immutable pending intents

pull/1508/head
Alex Baker 3 years ago
parent 6ab0643ac3
commit 590293421d

@ -37,14 +37,16 @@ class LocationServiceGooglePlay @Inject constructor(
@SuppressLint("MissingPermission")
override fun addGeofences(geofence: MergedGeofence) {
LocationServices
.getGeofencingClient(context)
.addGeofences(
.getGeofencingClient(context)
.addGeofences(
GeofencingRequest.Builder().addGeofence(toGoogleGeofence(geofence)).build(),
PendingIntent.getBroadcast(
context,
0,
Intent(context, GoogleGeofenceTransitionIntentService.Broadcast::class.java),
PendingIntent.FLAG_UPDATE_CURRENT))
context,
0,
Intent(context, GoogleGeofenceTransitionIntentService.Broadcast::class.java),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
)
}
override fun removeGeofences(place: Place) {

@ -43,7 +43,11 @@ class Notifier @Inject constructor(
}
val intent = TaskIntents.getTaskListIntent(context, filter)
val pendingIntent = PendingIntent.getActivity(
context, filter.listingTitle.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
context,
filter.listingTitle.hashCode(),
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val summaryTitle = context.resources.getQuantityString(R.plurals.task_count, count, count)
val style = NotificationCompat.InboxStyle().setBigContentTitle(summaryTitle)
var maxPriority = 3

@ -279,9 +279,19 @@ class WorkManagerImpl constructor(
private val notificationPendingIntent: PendingIntent
get() {
return if (AndroidUtilities.atLeastOreo()) {
PendingIntent.getForegroundService(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
PendingIntent.getForegroundService(
context,
0,
notificationIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
} else {
PendingIntent.getService(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
PendingIntent.getService(
context,
0,
notificationIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}
}
}

@ -56,7 +56,7 @@ class LocationServiceAndroid @Inject constructor(
0,
Intent(context, AndroidGeofenceTransitionIntentService.Broadcast::class.java)
.setData(Uri.parse("tasks://geofence/$place")),
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
companion object {

@ -199,7 +199,11 @@ class NotificationManager @Inject constructor(
val deleteIntent = Intent(context, NotificationClearedReceiver::class.java)
deleteIntent.putExtra(EXTRA_NOTIFICATION_ID, notificationId)
notification.deleteIntent = PendingIntent.getBroadcast(
context, notificationId.toInt(), deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)
context,
notificationId.toInt(),
deleteIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val evicted = queue.add(notificationId)
if (evicted.size > 0) {
cancel(evicted)
@ -249,7 +253,9 @@ class NotificationManager @Inject constructor(
context,
0,
TaskIntents.getTaskListIntent(context, NotificationsFilter(context)),
PendingIntent.FLAG_UPDATE_CURRENT))
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
)
.setGroupSummary(true)
.setGroup(GROUP_KEY)
.setTicker(
@ -261,7 +267,13 @@ class NotificationManager @Inject constructor(
builder.addAction(
R.drawable.ic_snooze_white_24dp,
context.getString(R.string.snooze_all),
PendingIntent.getActivity(context, 0, snoozeIntent, PendingIntent.FLAG_CANCEL_CURRENT))
PendingIntent.getActivity(
context,
0,
snoozeIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT
)
)
notify(SUMMARY_NOTIFICATION_ID.toLong(), builder, notify, nonStop, fiveTimes)
}
@ -316,7 +328,13 @@ class NotificationManager @Inject constructor(
.setTicker(taskTitle)
val intent = NotificationActivity.newIntent(context, taskTitle.toString(), id)
builder.setContentIntent(
PendingIntent.getActivity(context, id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT))
PendingIntent.getActivity(
context,
id.toInt(),
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
)
if (type == ReminderService.TYPE_GEOFENCE_ENTER || type == ReminderService.TYPE_GEOFENCE_EXIT) {
val place = locationDao.getPlace(notification.location!!)
if (place != null) {
@ -333,7 +351,11 @@ class NotificationManager @Inject constructor(
val completeIntent = Intent(context, CompleteTaskReceiver::class.java)
completeIntent.putExtra(CompleteTaskReceiver.TASK_ID, id)
val completePendingIntent = PendingIntent.getBroadcast(
context, id.toInt(), completeIntent, PendingIntent.FLAG_UPDATE_CURRENT)
context,
id.toInt(),
completeIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val completeAction = NotificationCompat.Action.Builder(
R.drawable.ic_check_white_24dp,
context.getString(R.string.rmd_NoA_done),
@ -341,7 +363,11 @@ class NotificationManager @Inject constructor(
.build()
val snoozeIntent = SnoozeActivity.newIntent(context, id)
val snoozePendingIntent = PendingIntent.getActivity(
context, id.toInt(), snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT)
context,
id.toInt(),
snoozeIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val wearableExtender = NotificationCompat.WearableExtender()
wearableExtender.addAction(completeAction)
for (snoozeOption in SnoozeDialog.getSnoozeOptions(preferences)) {
@ -350,7 +376,11 @@ class NotificationManager @Inject constructor(
wearableIntent.action = String.format("snooze-%s-%s", id, timestamp)
wearableIntent.putExtra(SnoozeActivity.EXTRA_SNOOZE_TIME, timestamp)
val wearablePendingIntent = PendingIntent.getActivity(
context, id.toInt(), wearableIntent, PendingIntent.FLAG_UPDATE_CURRENT)
context,
id.toInt(),
wearableIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
wearableExtender.addAction(
NotificationCompat.Action.Builder(
R.drawable.ic_snooze_white_24dp,

@ -35,7 +35,8 @@ class CalendarNotificationIntentService : RecurringIntervalIntentService() {
context,
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER,
eventAlarm,
PendingIntent.FLAG_UPDATE_CURRENT)
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val reminderTime = event.start - FIFTEEN_MINUTES
alarmManager.wakeup(reminderTime, pendingIntent)
Timber.d("Scheduled reminder for %s at %s", event, reminderTime)

@ -22,7 +22,11 @@ abstract class RecurringIntervalIntentService : InjectingJobIntentService() {
Timber.d("running now [nextRun=${DateTimeUtils.printTimestamp(nextRun)}]")
run()
val pendingIntent = PendingIntent.getBroadcast(
this, 0, Intent(this, broadcastClass), PendingIntent.FLAG_UPDATE_CURRENT)
this,
0,
Intent(this, broadcastClass),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
alarmManager.wakeup(nextRun, pendingIntent)
}

@ -152,18 +152,32 @@ class TasksWidget : AppWidgetProvider() {
private fun getPendingIntentTemplate(context: Context): PendingIntent =
PendingIntent.getActivity(
context, 0, Intent(context, WidgetClickActivity::class.java), PendingIntent.FLAG_UPDATE_CURRENT)
context,
0,
Intent(context, WidgetClickActivity::class.java),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
private fun getOpenListIntent(context: Context, filter: Filter, widgetId: Int): PendingIntent {
val intent = TaskIntents.getTaskListIntent(context, filter)
intent.action = "open_list"
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getActivity(
context,
widgetId,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}
private fun getNewTaskIntent(context: Context, filter: Filter, widgetId: Int): PendingIntent {
val intent = TaskIntents.getNewTaskIntent(context, filter)
intent.action = "new_task"
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getActivity(
context,
widgetId,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}
private fun getWidgetConfigIntent(context: Context, widgetId: Int): PendingIntent {
@ -171,7 +185,12 @@ class TasksWidget : AppWidgetProvider() {
intent.flags = flags
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId)
intent.action = "widget_settings"
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getActivity(
context,
widgetId,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}
private fun getChooseListIntent(context: Context, filter: Filter, widgetId: Int): PendingIntent {
@ -180,7 +199,12 @@ class TasksWidget : AppWidgetProvider() {
intent.putExtra(FilterSelectionActivity.EXTRA_FILTER, filter)
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId)
intent.action = "choose_list"
return PendingIntent.getActivity(context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getActivity(
context,
widgetId,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
}
companion object {

Loading…
Cancel
Save