diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDialogThread.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDialogThread.kt
index 273012e9c..1a630f4b3 100644
--- a/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDialogThread.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/database/action/ProgressDialogThread.kt
@@ -215,10 +215,9 @@ class ProgressDialogThread(private val activity: FragmentActivity) {
}
private fun start(bundle: Bundle? = null, actionTask: String) {
- activity.stopService(intentDatabaseTask)
if (bundle != null)
intentDatabaseTask.putExtras(bundle)
- intentDatabaseTask.action = actionTask
+ intentDatabaseTask.action = actionTask
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
activity.startForegroundService(intentDatabaseTask)
} else {
diff --git a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt
deleted file mode 100644
index 7dc6569a5..000000000
--- a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseOpenNotificationService.kt
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2019 Jeremy Jamet / Kunzisoft.
- *
- * This file is part of KeePassDX.
- *
- * KeePassDX is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * KeePassDX is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with KeePassDX. If not, see .
- *
- */
-package com.kunzisoft.keepass.notifications
-
-import android.app.PendingIntent
-import android.content.Context
-import android.content.Intent
-import android.os.Build
-import android.os.IBinder
-import com.kunzisoft.keepass.R
-import com.kunzisoft.keepass.activities.GroupActivity
-import com.kunzisoft.keepass.database.element.Database
-import com.kunzisoft.keepass.timeout.TimeoutHelper
-import com.kunzisoft.keepass.utils.LOCK_ACTION
-import com.kunzisoft.keepass.utils.closeDatabase
-
-class DatabaseOpenNotificationService: LockNotificationService() {
-
- override val notificationId: Int = 340
-
- private fun stopNotificationAndSendLock() {
- // Send lock action
- sendBroadcast(Intent(LOCK_ACTION))
- }
-
- override fun actionOnLock() {
- closeDatabase()
- // Remove the lock timer (no more needed if it exists)
- TimeoutHelper.cancelLockTimer(this)
- // Service is stopped after receive the broadcast
- super.actionOnLock()
- }
-
- private fun checkIntent(intent: Intent?) {
- val notificationBuilder = buildNewNotification().apply {
- setSmallIcon(R.drawable.notification_ic_database_open)
- setContentTitle(getString(R.string.database_opened))
- setAutoCancel(false)
- }
-
- when(intent?.action) {
- ACTION_CLOSE_DATABASE -> {
- startForeground(notificationId, notificationBuilder.build())
- stopNotificationAndSendLock()
- }
- else -> {
- val databaseIntent = Intent(this, GroupActivity::class.java)
- var pendingDatabaseFlag = 0
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- pendingDatabaseFlag = PendingIntent.FLAG_IMMUTABLE
- }
- val pendingDatabaseIntent = PendingIntent.getActivity(this, 0, databaseIntent, pendingDatabaseFlag)
- val deleteIntent = Intent(this, DatabaseOpenNotificationService::class.java).apply {
- action = ACTION_CLOSE_DATABASE
- }
- val pendingDeleteIntent = PendingIntent.getService(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)
-
- val database = Database.getInstance()
- if (database.loaded) {
- startForeground(notificationId, notificationBuilder.apply {
- setContentText(database.name + " (" + database.version + ")")
- setContentIntent(pendingDatabaseIntent)
- // Unfortunately swipe is disabled in lollipop+
- setDeleteIntent(pendingDeleteIntent)
- addAction(R.drawable.ic_lock_white_24dp, getString(R.string.lock),
- pendingDeleteIntent)
- }.build())
- } else {
- startForeground(notificationId, notificationBuilder.build())
- stopSelf()
- }
- }
- }
- }
-
- override fun onBind(intent: Intent): IBinder? {
- checkIntent(intent)
- return super.onBind(intent)
- }
-
- override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
- super.onStartCommand(intent, flags, startId)
- checkIntent(intent)
- return START_STICKY
- }
-
- companion object {
- const val ACTION_CLOSE_DATABASE = "ACTION_CLOSE_DATABASE"
-
- fun start(context: Context) {
- // Start the opening notification, keep it active to receive lock
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- context.startForegroundService(Intent(context, DatabaseOpenNotificationService::class.java))
- } else {
- context.startService(Intent(context, DatabaseOpenNotificationService::class.java))
- }
- }
-
- fun stop(context: Context) {
- // Stop the opening notification
- context.stopService(Intent(context, DatabaseOpenNotificationService::class.java))
- }
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt
index 9949d4a58..ffb34f94d 100644
--- a/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/notifications/DatabaseTaskNotificationService.kt
@@ -19,12 +19,15 @@
*/
package com.kunzisoft.keepass.notifications
+import android.app.PendingIntent
import android.content.Intent
import android.net.Uri
import android.os.Binder
+import android.os.Build
import android.os.Bundle
import android.os.IBinder
import com.kunzisoft.keepass.R
+import com.kunzisoft.keepass.activities.GroupActivity
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
import com.kunzisoft.keepass.database.action.*
import com.kunzisoft.keepass.database.action.history.DeleteEntryHistoryDatabaseRunnable
@@ -42,22 +45,28 @@ import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.DATABASE_START_TASK_ACTION
import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
+import com.kunzisoft.keepass.utils.LOCK_ACTION
+import com.kunzisoft.keepass.utils.closeDatabase
import kotlinx.coroutines.*
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.collections.ArrayList
-class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdater {
+open class DatabaseTaskNotificationService : LockNotificationService(), ProgressTaskUpdater {
override val notificationId: Int = 575
+ private lateinit var mDatabase: Database
+
private val mainScope = CoroutineScope(Dispatchers.Main)
private var mActionTaskBinder = ActionTaskBinder()
private var mActionTaskListeners = LinkedList()
private var mAllowFinishAction = AtomicBoolean()
+ private var mActionRunning = false
- private var mTitleId: Int? = null
+ private var mIconId: Int = R.drawable.notification_ic_database_load
+ private var mTitleId: Int = R.string.database_opened
private var mMessageId: Int? = null
private var mWarningId: Int? = null
@@ -66,8 +75,8 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
fun getService(): DatabaseTaskNotificationService = this@DatabaseTaskNotificationService
fun addActionTaskListener(actionTaskListener: ActionTaskListener) {
- mActionTaskListeners.add(actionTaskListener)
mAllowFinishAction.set(true)
+ mActionTaskListeners.add(actionTaskListener)
}
fun removeActionTaskListener(actionTaskListener: ActionTaskListener) {
@@ -84,66 +93,41 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
fun onStopAction(actionTask: String, result: ActionRunnable.Result)
}
+ /**
+ * Force to call [ActionTaskListener.onStartAction] if the action is still running
+ */
fun checkAction() {
- mActionTaskListeners.forEach { actionTaskListener ->
- actionTaskListener.onStartAction(mTitleId, mMessageId, mWarningId)
- }
- }
-
- private fun buildNotification(intent: Intent?) {
- var saveAction = true
- if (intent != null && intent.hasExtra(SAVE_DATABASE_KEY)) {
- saveAction = intent.getBooleanExtra(SAVE_DATABASE_KEY, saveAction)
- }
-
- val intentAction = intent?.action
- val titleId: Int = when (intentAction) {
- ACTION_DATABASE_CREATE_TASK -> R.string.creating_database
- ACTION_DATABASE_LOAD_TASK -> R.string.loading_database
- else -> {
- if (saveAction)
- R.string.saving_database
- else
- R.string.command_execution
+ if (mActionRunning) {
+ mActionTaskListeners.forEach { actionTaskListener ->
+ actionTaskListener.onStartAction(mTitleId, mMessageId, mWarningId)
}
}
- val messageId: Int? = when (intentAction) {
- ACTION_DATABASE_LOAD_TASK -> null
- else -> null
- }
- val warningId: Int? =
- if (!saveAction
- || intentAction == ACTION_DATABASE_LOAD_TASK)
- null
- else
- R.string.do_not_kill_app
-
- // Assign elements for updates
- mTitleId = titleId
- mMessageId = messageId
- mWarningId = warningId
- // Create the notification
- startForeground(notificationId, buildNewNotification()
- .setSmallIcon(R.drawable.notification_ic_database_load)
- .setContentTitle(getString(intent?.getIntExtra(DATABASE_TASK_TITLE_KEY, titleId) ?: titleId))
- .setAutoCancel(false)
- .setContentIntent(null).build())
}
override fun onBind(intent: Intent): IBinder? {
- buildNotification(intent)
+ super.onBind(intent)
return mActionTaskBinder
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
- buildNotification(intent)
+ mDatabase = Database.getInstance()
- if (intent == null) return START_REDELIVER_INTENT
+ // Create the notification
+ buildMessage(intent)
- val intentAction = intent.action
- val actionRunnable: ActionRunnable? = when (intentAction) {
+ val intentAction = intent?.action
+
+ if (intentAction == null && !mDatabase.loaded) {
+ stopSelf()
+ }
+ if (intentAction == ACTION_DATABASE_CLOSE) {
+ // Send lock action
+ sendBroadcast(Intent(LOCK_ACTION))
+ }
+
+ val actionRunnable: ActionRunnable? = when (intentAction) {
ACTION_DATABASE_CREATE_TASK -> buildDatabaseCreateActionTask(intent)
ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent)
ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent)
@@ -172,12 +156,13 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
else -> null
}
- actionRunnable?.let { actionRunnableNotNull ->
-
- // Build and launch the action
+ // Build and launch the action
+ if (actionRunnable != null) {
mainScope.launch {
executeAction(this@DatabaseTaskNotificationService,
{
+ mActionRunning = true
+
sendBroadcast(Intent(DATABASE_START_TASK_ACTION).apply {
putExtra(DATABASE_TASK_TITLE_KEY, mTitleId)
putExtra(DATABASE_TASK_MESSAGE_KEY, mMessageId)
@@ -190,22 +175,143 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
},
{
- actionRunnableNotNull
+ actionRunnable
},
{ result ->
mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onStopAction(intentAction!!, result)
}
+ removeIntentData(intent)
+ buildMessage(intent)
+
sendBroadcast(Intent(DATABASE_STOP_TASK_ACTION))
- stopSelf()
+ mActionRunning = false
}
)
}
+ // Relaunch action if failed
+ return START_REDELIVER_INTENT
}
- return START_REDELIVER_INTENT
+ return START_STICKY
+ }
+
+ private fun buildMessage(intent: Intent?) {
+ // Assign elements for updates
+ val intentAction = intent?.action
+
+ var saveAction = false
+ if (intent != null && intent.hasExtra(SAVE_DATABASE_KEY)) {
+ saveAction = intent.getBooleanExtra(SAVE_DATABASE_KEY, saveAction)
+ }
+
+ mIconId = if (intentAction == null)
+ R.drawable.notification_ic_database_open
+ else
+ R.drawable.notification_ic_database_load
+
+ mTitleId = when {
+ saveAction -> {
+ R.string.saving_database
+ }
+ intentAction == null -> {
+ R.string.database_opened
+ }
+ else -> {
+ when (intentAction) {
+ ACTION_DATABASE_CREATE_TASK -> R.string.creating_database
+ ACTION_DATABASE_LOAD_TASK -> R.string.loading_database
+ ACTION_DATABASE_SAVE -> R.string.saving_database
+ else -> {
+ R.string.command_execution
+ }
+ }
+ }
+ }
+
+ mMessageId = when (intentAction) {
+ ACTION_DATABASE_LOAD_TASK -> null
+ else -> null
+ }
+
+ mWarningId =
+ if (!saveAction
+ || intentAction == ACTION_DATABASE_LOAD_TASK)
+ null
+ else
+ R.string.do_not_kill_app
+
+ val notificationBuilder = buildNewNotification().apply {
+ setSmallIcon(mIconId)
+ intent?.let {
+ setContentTitle(getString(intent.getIntExtra(DATABASE_TASK_TITLE_KEY, mTitleId)))
+ }
+ setAutoCancel(false)
+ setContentIntent(null)
+ }
+
+ if (intentAction == null) {
+ // Database is normally open
+ if (mDatabase.loaded) {
+ // Build Intents for notification action
+ var pendingDatabaseFlag = 0
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ pendingDatabaseFlag = PendingIntent.FLAG_IMMUTABLE
+ }
+ val pendingDatabaseIntent = PendingIntent.getActivity(this,
+ 0,
+ Intent(this, GroupActivity::class.java),
+ pendingDatabaseFlag)
+ val deleteIntent = Intent(this, DatabaseTaskNotificationService::class.java).apply {
+ action = ACTION_DATABASE_CLOSE
+ }
+ val pendingDeleteIntent = PendingIntent.getService(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)
+ // Add actions in notifications
+ notificationBuilder.apply {
+ setContentText(mDatabase.name + " (" + mDatabase.version + ")")
+ setContentIntent(pendingDatabaseIntent)
+ // Unfortunately swipe is disabled in lollipop+
+ setDeleteIntent(pendingDeleteIntent)
+ addAction(R.drawable.ic_lock_white_24dp, getString(R.string.lock),
+ pendingDeleteIntent)
+ }
+ }
+ }
+
+ // Create the notification
+ startForeground(notificationId, notificationBuilder.build())
+ }
+
+ private fun removeIntentData(intent: Intent?) {
+ intent?.action = null
+
+ intent?.removeExtra(DATABASE_TASK_TITLE_KEY)
+ intent?.removeExtra(DATABASE_TASK_MESSAGE_KEY)
+ intent?.removeExtra(DATABASE_TASK_WARNING_KEY)
+
+ intent?.removeExtra(DATABASE_URI_KEY)
+ intent?.removeExtra(MASTER_PASSWORD_CHECKED_KEY)
+ intent?.removeExtra(MASTER_PASSWORD_KEY)
+ intent?.removeExtra(KEY_FILE_CHECKED_KEY)
+ intent?.removeExtra(KEY_FILE_KEY)
+ intent?.removeExtra(READ_ONLY_KEY)
+ intent?.removeExtra(CIPHER_ENTITY_KEY)
+ intent?.removeExtra(FIX_DUPLICATE_UUID_KEY)
+ intent?.removeExtra(GROUP_KEY)
+ intent?.removeExtra(ENTRY_KEY)
+ intent?.removeExtra(GROUP_ID_KEY)
+ intent?.removeExtra(ENTRY_ID_KEY)
+ intent?.removeExtra(GROUPS_ID_KEY)
+ intent?.removeExtra(ENTRIES_ID_KEY)
+ intent?.removeExtra(PARENT_ID_KEY)
+ intent?.removeExtra(ENTRY_HISTORY_POSITION_KEY)
+ intent?.removeExtra(SAVE_DATABASE_KEY)
+ intent?.removeExtra(OLD_NODES_KEY)
+ intent?.removeExtra(NEW_NODES_KEY)
+ intent?.removeExtra(OLD_ELEMENT_KEY)
+ intent?.removeExtra(NEW_ELEMENT_KEY)
}
/**
@@ -241,7 +347,9 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
TimeoutHelper.releaseTemporarilyDisableTimeout()
// Start the opening notification
if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
- DatabaseOpenNotificationService.start(this@DatabaseTaskNotificationService)
+ if (!mDatabase.loaded) {
+ stopSelf()
+ }
}
}
}
@@ -256,6 +364,16 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
}
}
+ override fun actionOnLock() {
+ if (!TimeoutHelper.temporarilyDisableTimeout) {
+ closeDatabase()
+ // Remove the lock timer (no more needed if it exists)
+ TimeoutHelper.cancelLockTimer(this)
+ // Service is stopped after receive the broadcast
+ super.actionOnLock()
+ }
+ }
+
private fun buildDatabaseCreateActionTask(intent: Intent): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY)
@@ -271,7 +389,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
return null
return CreateDatabaseRunnable(this,
- Database.getInstance(),
+ mDatabase,
databaseUri,
getString(R.string.database_default_name),
getString(R.string.database),
@@ -294,7 +412,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(CIPHER_ENTITY_KEY)
&& intent.hasExtra(FIX_DUPLICATE_UUID_KEY)
) {
- val database = Database.getInstance()
val databaseUri: Uri? = intent.getParcelableExtra(DATABASE_URI_KEY)
val masterPassword: String? = intent.getStringExtra(MASTER_PASSWORD_KEY)
val keyFileUri: Uri? = intent.getParcelableExtra(KEY_FILE_KEY)
@@ -306,7 +423,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
return LoadDatabaseRunnable(
this,
- database,
+ mDatabase,
databaseUri,
masterPassword,
keyFileUri,
@@ -338,7 +455,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
) {
val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null
AssignPasswordInDatabaseRunnable(this,
- Database.getInstance(),
+ mDatabase,
databaseUri,
intent.getBooleanExtra(MASTER_PASSWORD_CHECKED_KEY, false),
intent.getStringExtra(MASTER_PASSWORD_KEY),
@@ -365,7 +482,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val parentId: NodeId<*>? = intent.getParcelableExtra(PARENT_ID_KEY)
val newGroup: Group? = intent.getParcelableExtra(GROUP_KEY)
@@ -373,9 +489,9 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|| newGroup == null)
return null
- database.getGroupById(parentId)?.let { parent ->
+ mDatabase.getGroupById(parentId)?.let { parent ->
AddGroupRunnable(this,
- database,
+ mDatabase,
newGroup,
parent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -391,7 +507,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(GROUP_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val groupId: NodeId<*>? = intent.getParcelableExtra(GROUP_ID_KEY)
val newGroup: Group? = intent.getParcelableExtra(GROUP_KEY)
@@ -399,9 +514,9 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|| newGroup == null)
return null
- database.getGroupById(groupId)?.let { oldGroup ->
+ mDatabase.getGroupById(groupId)?.let { oldGroup ->
UpdateGroupRunnable(this,
- database,
+ mDatabase,
oldGroup,
newGroup,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -417,7 +532,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val parentId: NodeId<*>? = intent.getParcelableExtra(PARENT_ID_KEY)
val newEntry: Entry? = intent.getParcelableExtra(ENTRY_KEY)
@@ -425,9 +539,9 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|| newEntry == null)
return null
- database.getGroupById(parentId)?.let { parent ->
+ mDatabase.getGroupById(parentId)?.let { parent ->
AddEntryRunnable(this,
- database,
+ mDatabase,
newEntry,
parent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -443,7 +557,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(ENTRY_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val entryId: NodeId? = intent.getParcelableExtra(ENTRY_ID_KEY)
val newEntry: Entry? = intent.getParcelableExtra(ENTRY_KEY)
@@ -451,9 +564,9 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
|| newEntry == null)
return null
- database.getEntryById(entryId)?.let { oldEntry ->
+ mDatabase.getEntryById(entryId)?.let { oldEntry ->
UpdateEntryRunnable(this,
- database,
+ mDatabase,
oldEntry,
newEntry,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -470,13 +583,12 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val parentId: NodeId<*> = intent.getParcelableExtra(PARENT_ID_KEY) ?: return null
- database.getGroupById(parentId)?.let { newParent ->
+ mDatabase.getGroupById(parentId)?.let { newParent ->
CopyNodesRunnable(this,
- database,
- getListNodesFromBundle(database, intent.extras!!),
+ mDatabase,
+ getListNodesFromBundle(mDatabase, intent.extras!!),
newParent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
AfterActionNodesRunnable())
@@ -492,13 +604,12 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val parentId: NodeId<*> = intent.getParcelableExtra(PARENT_ID_KEY) ?: return null
- database.getGroupById(parentId)?.let { newParent ->
+ mDatabase.getGroupById(parentId)?.let { newParent ->
MoveNodesRunnable(this,
- database,
- getListNodesFromBundle(database, intent.extras!!),
+ mDatabase,
+ getListNodesFromBundle(mDatabase, intent.extras!!),
newParent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
AfterActionNodesRunnable())
@@ -513,10 +624,9 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(ENTRIES_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
DeleteNodesRunnable(this,
- database,
- getListNodesFromBundle(database, intent.extras!!),
+ mDatabase,
+ getListNodesFromBundle(mDatabase, intent.extras!!),
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
AfterActionNodesRunnable())
} else {
@@ -529,12 +639,11 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val entryId: NodeId = intent.getParcelableExtra(ENTRY_ID_KEY) ?: return null
- database.getEntryById(entryId)?.let { mainEntry ->
+ mDatabase.getEntryById(entryId)?.let { mainEntry ->
RestoreEntryHistoryDatabaseRunnable(this,
- database,
+ mDatabase,
mainEntry,
intent.getIntExtra(ENTRY_HISTORY_POSITION_KEY, -1),
intent.getBooleanExtra(SAVE_DATABASE_KEY, false))
@@ -549,12 +658,11 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
- val database = Database.getInstance()
val entryId: NodeId = intent.getParcelableExtra(ENTRY_ID_KEY) ?: return null
- database.getEntryById(entryId)?.let { mainEntry ->
+ mDatabase.getEntryById(entryId)?.let { mainEntry ->
DeleteEntryHistoryDatabaseRunnable(this,
- database,
+ mDatabase,
mainEntry,
intent.getIntExtra(ENTRY_HISTORY_POSITION_KEY, -1),
intent.getBooleanExtra(SAVE_DATABASE_KEY, false))
@@ -577,7 +685,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
return null
return UpdateCompressionBinariesDatabaseRunnable(this,
- Database.getInstance(),
+ mDatabase,
oldElement,
newElement,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
@@ -594,7 +702,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
private fun buildDatabaseUpdateElementActionTask(intent: Intent): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
return SaveDatabaseRunnable(this,
- Database.getInstance(),
+ mDatabase,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
).apply {
mAfterSaveDatabase = { result ->
@@ -612,7 +720,7 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
private fun buildDatabaseSave(intent: Intent): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
SaveDatabaseRunnable(this,
- Database.getInstance(),
+ mDatabase,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false))
} else {
null
@@ -623,10 +731,6 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
private val TAG = DatabaseTaskNotificationService::class.java.name
- const val DATABASE_TASK_TITLE_KEY = "DATABASE_TASK_TITLE_KEY"
- const val DATABASE_TASK_MESSAGE_KEY = "DATABASE_TASK_MESSAGE_KEY"
- const val DATABASE_TASK_WARNING_KEY = "DATABASE_TASK_WARNING_KEY"
-
const val ACTION_DATABASE_CREATE_TASK = "ACTION_DATABASE_CREATE_TASK"
const val ACTION_DATABASE_LOAD_TASK = "ACTION_DATABASE_LOAD_TASK"
const val ACTION_DATABASE_ASSIGN_PASSWORD_TASK = "ACTION_DATABASE_ASSIGN_PASSWORD_TASK"
@@ -652,6 +756,11 @@ class DatabaseTaskNotificationService : NotificationService(), ProgressTaskUpdat
const val ACTION_DATABASE_UPDATE_PARALLELISM_TASK = "ACTION_DATABASE_UPDATE_PARALLELISM_TASK"
const val ACTION_DATABASE_UPDATE_ITERATIONS_TASK = "ACTION_DATABASE_UPDATE_ITERATIONS_TASK"
const val ACTION_DATABASE_SAVE = "ACTION_DATABASE_SAVE"
+ const val ACTION_DATABASE_CLOSE = "ACTION_DATABASE_CLOSE"
+
+ const val DATABASE_TASK_TITLE_KEY = "DATABASE_TASK_TITLE_KEY"
+ const val DATABASE_TASK_MESSAGE_KEY = "DATABASE_TASK_MESSAGE_KEY"
+ const val DATABASE_TASK_WARNING_KEY = "DATABASE_TASK_WARNING_KEY"
const val DATABASE_URI_KEY = "DATABASE_URI_KEY"
const val MASTER_PASSWORD_CHECKED_KEY = "MASTER_PASSWORD_CHECKED_KEY"
diff --git a/app/src/main/java/com/kunzisoft/keepass/notifications/LockNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/notifications/LockNotificationService.kt
index 2bb4889ec..9b73d8f93 100644
--- a/app/src/main/java/com/kunzisoft/keepass/notifications/LockNotificationService.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/notifications/LockNotificationService.kt
@@ -20,6 +20,7 @@
package com.kunzisoft.keepass.notifications
import android.content.Intent
+import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.LockReceiver
import com.kunzisoft.keepass.utils.registerLockReceiver
import com.kunzisoft.keepass.utils.unregisterLockReceiver