Merge branch 'main' of github.com:binwiederhier/ntfy-android into auth

This commit is contained in:
Philipp Heckel 2022-01-28 13:48:20 -05:00
commit 437bc76b8c
2 changed files with 7 additions and 7 deletions

View file

@ -132,7 +132,7 @@ class NotificationService(val context: Context) {
} else { } else {
try { try {
val uri = Uri.parse(notification.click) val uri = Uri.parse(notification.click)
val viewIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, uri), 0) val viewIntent = PendingIntent.getActivity(context, 0, Intent(Intent.ACTION_VIEW, uri), PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(viewIntent) builder.setContentIntent(viewIntent)
} catch (e: Exception) { } catch (e: Exception) {
builder.setContentIntent(detailActivityIntent(subscription)) builder.setContentIntent(detailActivityIntent(subscription))
@ -155,7 +155,7 @@ class NotificationService(val context: Context) {
val intent = Intent(Intent.ACTION_VIEW, contentUri) val intent = Intent(Intent.ACTION_VIEW, contentUri)
intent.setDataAndType(contentUri, notification.attachment.type ?: "application/octet-stream") // Required for Android <= P intent.setDataAndType(contentUri, notification.attachment.type ?: "application/octet-stream") // Required for Android <= P
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_open), pendingIntent).build()) builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_open), pendingIntent).build())
} }
} }
@ -164,7 +164,7 @@ class NotificationService(val context: Context) {
if (notification.attachment?.contentUri != null) { if (notification.attachment?.contentUri != null) {
val intent = Intent(android.app.DownloadManager.ACTION_VIEW_DOWNLOADS) val intent = Intent(android.app.DownloadManager.ACTION_VIEW_DOWNLOADS)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_browse), pendingIntent).build()) builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_browse), pendingIntent).build())
} }
} }
@ -174,7 +174,7 @@ class NotificationService(val context: Context) {
val intent = Intent(context, DownloadBroadcastReceiver::class.java) val intent = Intent(context, DownloadBroadcastReceiver::class.java)
intent.putExtra("action", DOWNLOAD_ACTION_START) intent.putExtra("action", DOWNLOAD_ACTION_START)
intent.putExtra("id", notification.id) intent.putExtra("id", notification.id)
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_download), pendingIntent).build()) builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_download), pendingIntent).build())
} }
} }
@ -184,7 +184,7 @@ class NotificationService(val context: Context) {
val intent = Intent(context, DownloadBroadcastReceiver::class.java) val intent = Intent(context, DownloadBroadcastReceiver::class.java)
intent.putExtra("action", DOWNLOAD_ACTION_CANCEL) intent.putExtra("action", DOWNLOAD_ACTION_CANCEL)
intent.putExtra("id", notification.id) intent.putExtra("id", notification.id)
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_cancel), pendingIntent).build()) builder.addAction(NotificationCompat.Action.Builder(0, context.getString(R.string.notification_popup_action_cancel), pendingIntent).build())
} }
} }
@ -209,7 +209,7 @@ class NotificationService(val context: Context) {
intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_MUTED_UNTIL, subscription.mutedUntil) intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_MUTED_UNTIL, subscription.mutedUntil)
return TaskStackBuilder.create(context).run { return TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(intent) // Add the intent, which inflates the back stack addNextIntentWithParentStack(intent) // Add the intent, which inflates the back stack
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) // Get the PendingIntent containing the entire back stack getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) // Get the PendingIntent containing the entire back stack
} }
} }

View file

@ -298,7 +298,7 @@ class SubscriberService : Service() {
val restartServiceIntent = Intent(applicationContext, SubscriberService::class.java).also { val restartServiceIntent = Intent(applicationContext, SubscriberService::class.java).also {
it.setPackage(packageName) it.setPackage(packageName)
}; };
val restartServicePendingIntent: PendingIntent = PendingIntent.getService(this, 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); val restartServicePendingIntent: PendingIntent = PendingIntent.getService(this, 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE);
applicationContext.getSystemService(Context.ALARM_SERVICE); applicationContext.getSystemService(Context.ALARM_SERVICE);
val alarmService: AlarmManager = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager; val alarmService: AlarmManager = applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager;
alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent); alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent);