From ac47748e41b5e2ab090b27f690eda96e55f6962c Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 22 Nov 2021 11:51:30 +0100 Subject: [PATCH] Fix pending intent --- .../AdvancedUnlockNotificationService.kt | 4 ++++ .../ClipboardEntryNotificationService.kt | 17 +++++++++++++++-- .../services/DatabaseTaskNotificationService.kt | 6 +++++- .../KeyboardEntryNotificationService.kt | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/services/AdvancedUnlockNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/AdvancedUnlockNotificationService.kt index 9f63b9ce2..9a93fa700 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/AdvancedUnlockNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/AdvancedUnlockNotificationService.kt @@ -1,5 +1,6 @@ package com.kunzisoft.keepass.services +import android.annotation.SuppressLint import android.app.PendingIntent import android.content.* import android.net.Uri @@ -50,6 +51,9 @@ class AdvancedUnlockNotificationService : NotificationService() { mTempCipherDao = ArrayList() } + // It's simpler to use pendingIntent to perform REMOVE_ADVANCED_UNLOCK_KEY_ACTION + // because can be directly broadcast to another module or app + @SuppressLint("LaunchActivityFromNotification") override fun onBind(intent: Intent): IBinder { super.onBind(intent) diff --git a/app/src/main/java/com/kunzisoft/keepass/services/ClipboardEntryNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/ClipboardEntryNotificationService.kt index f31f0472e..9372ab85b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/ClipboardEntryNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/ClipboardEntryNotificationService.kt @@ -22,6 +22,7 @@ package com.kunzisoft.keepass.services import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.os.Build import android.util.Log import com.kunzisoft.keepass.R import com.kunzisoft.keepass.model.EntryInfo @@ -112,7 +113,13 @@ class ClipboardEntryNotificationService : LockNotificationService() { putParcelableArrayListExtra(EXTRA_CLIPBOARD_FIELDS, fieldsToAdd) } return PendingIntent.getService( - this, 0, copyIntent, PendingIntent.FLAG_UPDATE_CURRENT) + this, 0, copyIntent, + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + } else { + PendingIntent.FLAG_UPDATE_CURRENT + } + ) } private fun newNotification(title: String?, fieldsToAdd: ArrayList) { @@ -162,7 +169,13 @@ class ClipboardEntryNotificationService : LockNotificationService() { val cleanIntent = Intent(this, ClipboardEntryNotificationService::class.java) cleanIntent.action = ACTION_CLEAN_CLIPBOARD val cleanPendingIntent = PendingIntent.getService( - this, 0, cleanIntent, PendingIntent.FLAG_UPDATE_CURRENT) + this, 0, cleanIntent, + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + } else { + PendingIntent.FLAG_UPDATE_CURRENT + } + ) builder.setDeleteIntent(cleanPendingIntent) //Get settings diff --git a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt index b2a1a1776..0236aead0 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt @@ -408,7 +408,11 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress this, 0, Intent(this, GroupActivity::class.java), - PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + } else { + PendingIntent.FLAG_UPDATE_CURRENT + } ) val pendingDeleteIntent = PendingIntent.getBroadcast( this, diff --git a/app/src/main/java/com/kunzisoft/keepass/services/KeyboardEntryNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/KeyboardEntryNotificationService.kt index eb6776449..031a4c1ed 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/KeyboardEntryNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/KeyboardEntryNotificationService.kt @@ -22,6 +22,7 @@ package com.kunzisoft.keepass.services import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.os.Build import android.util.Log import android.widget.Toast import androidx.preference.PreferenceManager @@ -93,7 +94,13 @@ class KeyboardEntryNotificationService : LockNotificationService() { val deleteIntent = Intent(this, KeyboardEntryNotificationService::class.java).apply { action = ACTION_CLEAN_KEYBOARD_ENTRY } - pendingDeleteIntent = PendingIntent.getService(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT) + pendingDeleteIntent = PendingIntent.getService(this, 0, deleteIntent, + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + } else { + PendingIntent.FLAG_UPDATE_CURRENT + } + ) val builder = buildNewNotification() .setSmallIcon(R.drawable.notification_ic_keyboard_key_24dp)