This commit is contained in:
J-Jamet
2021-05-07 08:31:05 +02:00
parent edc5985a7e
commit 9d2fd53073

View File

@@ -26,8 +26,9 @@ import com.kunzisoft.keepass.utils.unregisterLockReceiver
abstract class LockNotificationService : NotificationService() { abstract class LockNotificationService : NotificationService() {
private var onStart: Boolean = false private var mLockReceiver: LockReceiver = LockReceiver {
private var mLockReceiver: LockReceiver? = null actionOnLock()
}
protected open fun actionOnLock() { protected open fun actionOnLock() {
// Stop the service in all cases // Stop the service in all cases
@@ -36,30 +37,17 @@ abstract class LockNotificationService : NotificationService() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
// Register a lock receiver to stop notification service when lock on keyboard is performed // Register a lock receiver to stop notification service when lock on keyboard is performed
mLockReceiver = LockReceiver {
if (onStart)
actionOnLock()
}
registerLockReceiver(mLockReceiver) registerLockReceiver(mLockReceiver)
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
onStart = true
return super.onStartCommand(intent, flags, startId)
}
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {
notificationManager?.cancel(notificationId) stopSelf()
super.onTaskRemoved(rootIntent) super.onTaskRemoved(rootIntent)
} }
override fun onDestroy() { override fun onDestroy() {
unregisterLockReceiver(mLockReceiver) unregisterLockReceiver(mLockReceiver)
mLockReceiver = null
super.onDestroy() super.onDestroy()
} }
} }