diff --git a/app/src/main/java/com/kunzisoft/keepass/services/AttachmentFileNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/AttachmentFileNotificationService.kt index 00fa14a9e..d9aacb1f9 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/AttachmentFileNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/AttachmentFileNotificationService.kt @@ -165,7 +165,7 @@ class AttachmentFileNotificationService: LockNotificationService() { } } if (attachmentNotificationList.isEmpty()) { - stopSelf() + stopService() } } } 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 98cf199c6..b1068060e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/ClipboardEntryNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/ClipboardEntryNotificationService.kt @@ -62,7 +62,7 @@ class ClipboardEntryNotificationService : LockNotificationService() { sendBroadcast(Intent(LOCK_ACTION)) } // Stop the service - stopSelf() + stopService() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { 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 ed1f2ccce..2bcda248b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt @@ -339,7 +339,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress val intentAction = intent?.action if (intentAction == null && !database.loaded) { - stopSelf() + stopService() } val actionRunnable: ActionRunnable? = when (intentAction) { @@ -448,10 +448,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress TimeoutHelper.releaseTemporarilyDisableTimeout() // Stop service after save if user remove task if (save && mTaskRemovedRequested) { - actionOnLock() + stopService() } else if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) { if (!database.loaded) { - stopSelf() + stopService() } else { // Restart the service to open lock notification try { @@ -673,7 +673,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress updateMessage(R.string.decrypting_db) } - override fun actionOnLock() { + override fun stopService() { if (!TimeoutHelper.temporarilyDisableLock) { closeDatabase(mDatabase) // Remove the database during the lock @@ -685,7 +685,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress // Remove the lock timer (no more needed if it exists) TimeoutHelper.cancelLockTimer(this) // Service is stopped after receive the broadcast - super.actionOnLock() + super.stopService() } } 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 557f00cd7..9a1c555e7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/KeyboardEntryNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/KeyboardEntryNotificationService.kt @@ -55,7 +55,7 @@ class KeyboardEntryNotificationService : LockNotificationService() { sendBroadcast(Intent(LOCK_ACTION)) } // Stop the service - stopSelf() + stopService() } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { diff --git a/app/src/main/java/com/kunzisoft/keepass/services/LockNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/LockNotificationService.kt index 5118fc203..4215f2043 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/LockNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/LockNotificationService.kt @@ -20,7 +20,6 @@ package com.kunzisoft.keepass.services import android.content.Intent -import androidx.core.app.ServiceCompat import com.kunzisoft.keepass.timeout.TimeoutHelper import com.kunzisoft.keepass.utils.LockReceiver import com.kunzisoft.keepass.utils.registerLockReceiver @@ -29,13 +28,7 @@ import com.kunzisoft.keepass.utils.unregisterLockReceiver abstract class LockNotificationService : NotificationService() { private var mLockReceiver: LockReceiver = LockReceiver { - actionOnLock() - } - - protected open fun actionOnLock() { - // Stop the service in all cases - ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) - stopSelf() + stopService() } override fun onCreate() { @@ -46,7 +39,7 @@ abstract class LockNotificationService : NotificationService() { override fun onTaskRemoved(rootIntent: Intent?) { if (!TimeoutHelper.temporarilyDisableLock) { - actionOnLock() + stopService() } super.onTaskRemoved(rootIntent) } diff --git a/app/src/main/java/com/kunzisoft/keepass/services/NotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/NotificationService.kt index 4d7fae28c..ea4abcf4b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/NotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/NotificationService.kt @@ -17,6 +17,7 @@ import android.util.TypedValue import android.widget.Toast import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.ServiceCompat import androidx.core.content.ContextCompat import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.stylish.Stylish @@ -114,6 +115,12 @@ abstract class NotificationService : Service() { } } + protected open fun stopService() { + // Stop the service in all cases + ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) + stopSelf() + } + protected fun defineTimerJob(builder: NotificationCompat.Builder, type: NotificationServiceType, timeoutMilliseconds: Long,