Use immutable pending intents

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

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

@ -43,7 +43,11 @@ class Notifier @Inject constructor(
} }
val intent = TaskIntents.getTaskListIntent(context, filter) val intent = TaskIntents.getTaskListIntent(context, filter)
val pendingIntent = PendingIntent.getActivity( 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 summaryTitle = context.resources.getQuantityString(R.plurals.task_count, count, count)
val style = NotificationCompat.InboxStyle().setBigContentTitle(summaryTitle) val style = NotificationCompat.InboxStyle().setBigContentTitle(summaryTitle)
var maxPriority = 3 var maxPriority = 3

@ -279,9 +279,19 @@ class WorkManagerImpl constructor(
private val notificationPendingIntent: PendingIntent private val notificationPendingIntent: PendingIntent
get() { get() {
return if (AndroidUtilities.atLeastOreo()) { 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 { } 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, 0,
Intent(context, AndroidGeofenceTransitionIntentService.Broadcast::class.java) Intent(context, AndroidGeofenceTransitionIntentService.Broadcast::class.java)
.setData(Uri.parse("tasks://geofence/$place")), .setData(Uri.parse("tasks://geofence/$place")),
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
) )
companion object { companion object {

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

@ -35,7 +35,8 @@ class CalendarNotificationIntentService : RecurringIntervalIntentService() {
context, context,
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER, CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER,
eventAlarm, eventAlarm,
PendingIntent.FLAG_UPDATE_CURRENT) PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val reminderTime = event.start - FIFTEEN_MINUTES val reminderTime = event.start - FIFTEEN_MINUTES
alarmManager.wakeup(reminderTime, pendingIntent) alarmManager.wakeup(reminderTime, pendingIntent)
Timber.d("Scheduled reminder for %s at %s", event, reminderTime) 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)}]") Timber.d("running now [nextRun=${DateTimeUtils.printTimestamp(nextRun)}]")
run() run()
val pendingIntent = PendingIntent.getBroadcast( 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) alarmManager.wakeup(nextRun, pendingIntent)
} }

@ -152,18 +152,32 @@ class TasksWidget : AppWidgetProvider() {
private fun getPendingIntentTemplate(context: Context): PendingIntent = private fun getPendingIntentTemplate(context: Context): PendingIntent =
PendingIntent.getActivity( 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 { private fun getOpenListIntent(context: Context, filter: Filter, widgetId: Int): PendingIntent {
val intent = TaskIntents.getTaskListIntent(context, filter) val intent = TaskIntents.getTaskListIntent(context, filter)
intent.action = "open_list" 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 { private fun getNewTaskIntent(context: Context, filter: Filter, widgetId: Int): PendingIntent {
val intent = TaskIntents.getNewTaskIntent(context, filter) val intent = TaskIntents.getNewTaskIntent(context, filter)
intent.action = "new_task" 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 { private fun getWidgetConfigIntent(context: Context, widgetId: Int): PendingIntent {
@ -171,7 +185,12 @@ class TasksWidget : AppWidgetProvider() {
intent.flags = flags intent.flags = flags
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId) intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId)
intent.action = "widget_settings" 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 { 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(FilterSelectionActivity.EXTRA_FILTER, filter)
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId) intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId)
intent.action = "choose_list" 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 { companion object {

Loading…
Cancel
Save