fix: Service stop

This commit is contained in:
J-Jamet
2025-10-28 15:48:07 +01:00
parent 56b7cc9118
commit ffaf4a761a
6 changed files with 17 additions and 17 deletions

View File

@@ -165,7 +165,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
} }
} }
if (attachmentNotificationList.isEmpty()) { if (attachmentNotificationList.isEmpty()) {
stopSelf() stopService()
} }
} }
} }

View File

@@ -62,7 +62,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
sendBroadcast(Intent(LOCK_ACTION)) sendBroadcast(Intent(LOCK_ACTION))
} }
// Stop the service // Stop the service
stopSelf() stopService()
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

View File

@@ -339,7 +339,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
val intentAction = intent?.action val intentAction = intent?.action
if (intentAction == null && !database.loaded) { if (intentAction == null && !database.loaded) {
stopSelf() stopService()
} }
val actionRunnable: ActionRunnable? = when (intentAction) { val actionRunnable: ActionRunnable? = when (intentAction) {
@@ -448,10 +448,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
TimeoutHelper.releaseTemporarilyDisableTimeout() TimeoutHelper.releaseTemporarilyDisableTimeout()
// Stop service after save if user remove task // Stop service after save if user remove task
if (save && mTaskRemovedRequested) { if (save && mTaskRemovedRequested) {
actionOnLock() stopService()
} else if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) { } else if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
if (!database.loaded) { if (!database.loaded) {
stopSelf() stopService()
} else { } else {
// Restart the service to open lock notification // Restart the service to open lock notification
try { try {
@@ -673,7 +673,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
updateMessage(R.string.decrypting_db) updateMessage(R.string.decrypting_db)
} }
override fun actionOnLock() { override fun stopService() {
if (!TimeoutHelper.temporarilyDisableLock) { if (!TimeoutHelper.temporarilyDisableLock) {
closeDatabase(mDatabase) closeDatabase(mDatabase)
// Remove the database during the lock // 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) // Remove the lock timer (no more needed if it exists)
TimeoutHelper.cancelLockTimer(this) TimeoutHelper.cancelLockTimer(this)
// Service is stopped after receive the broadcast // Service is stopped after receive the broadcast
super.actionOnLock() super.stopService()
} }
} }

View File

@@ -55,7 +55,7 @@ class KeyboardEntryNotificationService : LockNotificationService() {
sendBroadcast(Intent(LOCK_ACTION)) sendBroadcast(Intent(LOCK_ACTION))
} }
// Stop the service // Stop the service
stopSelf() stopService()
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

View File

@@ -20,7 +20,6 @@
package com.kunzisoft.keepass.services package com.kunzisoft.keepass.services
import android.content.Intent import android.content.Intent
import androidx.core.app.ServiceCompat
import com.kunzisoft.keepass.timeout.TimeoutHelper import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.LockReceiver import com.kunzisoft.keepass.utils.LockReceiver
import com.kunzisoft.keepass.utils.registerLockReceiver import com.kunzisoft.keepass.utils.registerLockReceiver
@@ -29,13 +28,7 @@ import com.kunzisoft.keepass.utils.unregisterLockReceiver
abstract class LockNotificationService : NotificationService() { abstract class LockNotificationService : NotificationService() {
private var mLockReceiver: LockReceiver = LockReceiver { private var mLockReceiver: LockReceiver = LockReceiver {
actionOnLock() stopService()
}
protected open fun actionOnLock() {
// Stop the service in all cases
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
stopSelf()
} }
override fun onCreate() { override fun onCreate() {
@@ -46,7 +39,7 @@ abstract class LockNotificationService : NotificationService() {
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {
if (!TimeoutHelper.temporarilyDisableLock) { if (!TimeoutHelper.temporarilyDisableLock) {
actionOnLock() stopService()
} }
super.onTaskRemoved(rootIntent) super.onTaskRemoved(rootIntent)
} }

View File

@@ -17,6 +17,7 @@ import android.util.TypedValue
import android.widget.Toast import android.widget.Toast
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.stylish.Stylish 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, protected fun defineTimerJob(builder: NotificationCompat.Builder,
type: NotificationServiceType, type: NotificationServiceType,
timeoutMilliseconds: Long, timeoutMilliseconds: Long,