Close service after save if task removed by the user

This commit is contained in:
J-Jamet committed 2021-08-18 15:10:37 +02:00
1 parent a0f5ed66e2
commit 649dffc3e0
4 files changed
+19 -9

No files matched your search

@@ -62,6 +62,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private var mActionTaskBinder = ActionTaskBinder()
private var mActionTaskListeners = LinkedList<ActionTaskListener>()
private var mActionRunning = false
private var mTaskRemovedRequested = false
private var mIconId: Int = R.drawable.notification_ic_database_load
private var mTitleId: Int = R.string.database_opened
@@ -301,7 +302,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
removeIntentData(intent)
TimeoutHelper.releaseTemporarilyDisableTimeout()
// Stop service after save if user remove task
if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
if (save && mTaskRemovedRequested) {
actionOnLock()
} else if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
if (!database.loaded) {
stopSelf()
} else {
@@ -312,6 +315,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
} catch (e: IllegalStateException) {}
}
}
mTaskRemovedRequested = false
}
sendBroadcast(Intent(DATABASE_STOP_TASK_ACTION))
@@ -485,7 +489,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
override fun actionOnLock() {
if (!TimeoutHelper.temporarilyDisableTimeout) {
if (!TimeoutHelper.temporarilyDisableLock) {
closeDatabase(mDatabase)
// Remove the lock timer (no more needed if it exists)
TimeoutHelper.cancelLockTimer(this)
@@ -494,6 +498,13 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
override fun onTaskRemoved(rootIntent: Intent?) {
if (TimeoutHelper.temporarilyDisableLock) {
mTaskRemovedRequested = true
}
super.onTaskRemoved(rootIntent)
}
private fun buildDatabaseCreateActionTask(intent: Intent, database: Database): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY)
@@ -43,7 +43,7 @@ abstract class LockNotificationService : NotificationService() {
}
override fun onTaskRemoved(rootIntent: Intent?) {
if (!TimeoutHelper.temporarilyDisableTimeout) {
if (!TimeoutHelper.temporarilyDisableLock) {
actionOnLock()
}
super.onTaskRemoved(rootIntent)
@@ -25,7 +25,6 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.LOCK_ACTION
@@ -39,7 +38,7 @@ object TimeoutHelper {
private const val TAG = "TimeoutHelper"
private var lastAppTimeoutRecord: Long? = null
var temporarilyDisableTimeout = false
var temporarilyDisableLock = false
private set
private fun getLockPendingIntent(context: Context): PendingIntent {
@@ -103,7 +102,7 @@ object TimeoutHelper {
*/
fun checkTime(context: Context, timeoutAction: (() -> Unit)? = null): Boolean {
// No effect if temporarily disable
if (temporarilyDisableTimeout)
if (temporarilyDisableLock)
return true
// Check whether the timeout has expired
@@ -159,13 +158,13 @@ object TimeoutHelper {
* Temporarily disable timeout, checkTime() function always return true
*/
fun temporarilyDisableTimeout() {
temporarilyDisableTimeout = true
temporarilyDisableLock = true
}
/**
* Release the temporarily disable timeout
*/
fun releaseTemporarilyDisableTimeout() {
temporarilyDisableTimeout = false
temporarilyDisableLock = false
}
}
@@ -51,7 +51,7 @@ class LockReceiver(var lockAction: () -> Unit) : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// If allowed, lock and exit
if (!TimeoutHelper.temporarilyDisableTimeout) {
if (!TimeoutHelper.temporarilyDisableLock) {
intent.action?.let {
when (it) {
Intent.ACTION_SCREEN_ON -> {