Fix database loading

This commit is contained in:
J-Jamet
2021-08-04 18:46:56 +02:00
parent 0ced9c8e26
commit e3198031e3
8 changed files with 197 additions and 197 deletions

View File

@@ -47,10 +47,7 @@ class AutofillLauncherActivity : DatabaseActivity() {
override fun onDatabaseRetrieved(database: Database?) {
super.onDatabaseRetrieved(database)
// End activity if database not loaded
if (database?.loaded != true) {
finish()
}
// Retrieve selection mode
EntrySelectionHelper.retrieveSpecialModeFromIntent(intent).let { specialMode ->
when (specialMode) {
@@ -63,22 +60,18 @@ class AutofillLauncherActivity : DatabaseActivity() {
}
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain
database?.let { database ->
launchSelection(database, searchInfo)
}
}
}
SpecialMode.REGISTRATION -> {
// To register info
val registerInfo = intent.getParcelableExtra<RegisterInfo>(KEY_REGISTER_INFO)
val searchInfo = SearchInfo(registerInfo?.searchInfo)
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain
database?.let { database ->
launchRegistration(database, searchInfo, registerInfo)
}
}
}
else -> {
// Not an autofill call
setResult(Activity.RESULT_CANCELED)
@@ -88,7 +81,7 @@ class AutofillLauncherActivity : DatabaseActivity() {
}
}
private fun launchSelection(database: Database,
private fun launchSelection(database: Database?,
searchInfo: SearchInfo) {
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
val autofillComponent = AutofillHelper.retrieveAutofillComponent(intent)
@@ -110,13 +103,15 @@ class AutofillLauncherActivity : DatabaseActivity() {
searchInfo,
{ items ->
// Items found
database?.let {
AutofillHelper.buildResponseAndSetResult(this, database, items)
}
finish()
},
{
// Show the database UI to select the entry
GroupActivity.launchForAutofillResult(this,
database.isReadOnly,
database?.isReadOnly != false,
autofillComponent,
searchInfo,
false)
@@ -131,7 +126,7 @@ class AutofillLauncherActivity : DatabaseActivity() {
}
}
private fun launchRegistration(database: Database,
private fun launchRegistration(database: Database?,
searchInfo: SearchInfo,
registerInfo: RegisterInfo?) {
if (!KeeAutofillService.autofillAllowedFor(searchInfo.applicationId,
@@ -141,7 +136,7 @@ class AutofillLauncherActivity : DatabaseActivity() {
showBlockRestartMessage()
setResult(Activity.RESULT_CANCELED)
} else {
val readOnly = database.isReadOnly
val readOnly = database?.isReadOnly != false
SearchHelper.checkAutoSearchInfo(this,
database,
searchInfo,

View File

@@ -265,7 +265,7 @@ class EntryEditActivity : LockingActivity(),
mEntryEditViewModel.setDatabase(database)
mAllowCustomFields = database?.allowEntryCustomFields() == true
mAllowOTP = database?.allowOTP == true
database?.let {
mEntryId?.let {
mEntryEditViewModel.initializeEntryToUpdate(it, mRegisterInfo, mSearchInfo)
mEntryId = null
@@ -275,6 +275,7 @@ class EntryEditActivity : LockingActivity(),
mParentId = null
}
}
}
override fun onDatabaseActionFinished(
database: Database,

View File

@@ -76,19 +76,13 @@ class EntrySelectionLauncherActivity : DatabaseActivity() {
this.otpString = otpString
}
// End activity if database not loaded
if (database?.loaded != true) {
finish()
}
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain
database?.let { database ->
launch(database, searchInfo)
}
}
}
private fun launch(database: Database,
private fun launch(database: Database?,
searchInfo: SearchInfo) {
if (!searchInfo.containsOnlyNullValues()) {
@@ -96,7 +90,7 @@ class EntrySelectionLauncherActivity : DatabaseActivity() {
val searchShareForMagikeyboard = PreferencesUtil.isKeyboardSearchShareEnable(this)
// If database is open
val readOnly = database.isReadOnly
val readOnly = database?.isReadOnly != false
SearchHelper.checkAutoSearchInfo(this,
database,
searchInfo,

View File

@@ -30,8 +30,7 @@ class MagikeyboardLauncherActivity : DatabaseActivity() {
override fun onDatabaseRetrieved(database: Database?) {
super.onDatabaseRetrieved(database)
database?.let {
val readOnly = database.isReadOnly
val readOnly = database?.isReadOnly != false
SearchHelper.checkAutoSearchInfo(this,
database,
null,
@@ -48,7 +47,6 @@ class MagikeyboardLauncherActivity : DatabaseActivity() {
FileDatabaseSelectActivity.launchForKeyboardSelectionResult(this)
}
)
}
finish()
}
}

View File

@@ -20,8 +20,7 @@
package com.kunzisoft.keepass.database.action
import android.content.*
import android.content.Context.BIND_ABOVE_CLIENT
import android.content.Context.BIND_NOT_FOREGROUND
import android.content.Context.*
import android.net.Uri
import android.os.Bundle
import android.os.IBinder
@@ -219,7 +218,7 @@ class DatabaseTaskProvider(private val activity: FragmentActivity) {
private fun bindService() {
initServiceConnection()
serviceConnection?.let {
activity.bindService(intentDatabaseTask, it, BIND_NOT_FOREGROUND or BIND_ABOVE_CLIENT)
activity.bindService(intentDatabaseTask, it, BIND_AUTO_CREATE or BIND_NOT_FOREGROUND or BIND_ABOVE_CLIENT)
}
}

View File

@@ -92,12 +92,14 @@ class SearchHelper {
* Utility method to perform actions if item is found or not after an auto search in [database]
*/
fun checkAutoSearchInfo(context: Context,
database: Database,
database: Database?,
searchInfo: SearchInfo?,
onItemsFound: (items: List<EntryInfo>) -> Unit,
onItemNotFound: () -> Unit,
onDatabaseClosed: () -> Unit) {
if (database.loaded && TimeoutHelper.checkTime(context)) {
if (database == null || !database.loaded) {
onDatabaseClosed.invoke()
} else if (TimeoutHelper.checkTime(context)) {
var searchWithoutUI = false
if (PreferencesUtil.isAutofillAutoSearchEnable(context)
&& searchInfo != null
@@ -118,8 +120,6 @@ class SearchHelper {
if (!searchWithoutUI) {
onItemNotFound.invoke()
}
} else {
onDatabaseClosed.invoke()
}
}

View File

@@ -54,7 +54,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override val notificationId: Int = 575
private lateinit var mDatabase: Database
private var mDatabase: Database? = null
private val mainScope = CoroutineScope(Dispatchers.Main)
@@ -132,7 +132,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
fun checkDatabaseInfo() {
try {
mDatabase.fileUri?.let {
mDatabase?.fileUri?.let {
val previousDatabaseInfo = mSnapFileDatabaseInfo
val lastFileDatabaseInfo = SnapFileDatabaseInfo.fromFileDatabaseInfo(
FileDatabaseInfo(applicationContext, it))
@@ -173,7 +173,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
fun saveDatabaseInfo() {
try {
mDatabase.fileUri?.let {
mDatabase?.fileUri?.let {
mSnapFileDatabaseInfo = SnapFileDatabaseInfo.fromFileDatabaseInfo(
FileDatabaseInfo(applicationContext, it))
Log.i(TAG, "Database file saved $mSnapFileDatabaseInfo")
@@ -187,9 +187,11 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
* Force to call [ActionTaskListener.onStartAction] if the action is still running
*/
fun checkAction() {
mDatabase?.let { database ->
if (mActionRunning) {
mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onStartAction(mDatabase, mTitleId, mMessageId, mWarningId)
actionTaskListener.onStartAction(database, mTitleId, mMessageId, mWarningId)
}
}
}
}
@@ -202,7 +204,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
mDatabase = Database.getInstance()
val database = Database.getInstance()
mDatabase = database
mDatabaseListeners.forEach { listener ->
listener.onDatabaseRetrieved(mDatabase)
}
@@ -212,26 +215,26 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
val intentAction = intent?.action
if (intentAction == null && !mDatabase.loaded) {
if (intentAction == null && !database.loaded) {
stopSelf()
}
val actionRunnable: ActionRunnable? = when (intentAction) {
ACTION_DATABASE_CREATE_TASK -> buildDatabaseCreateActionTask(intent)
ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent)
ACTION_DATABASE_RELOAD_TASK -> buildDatabaseReloadActionTask()
ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent)
ACTION_DATABASE_CREATE_GROUP_TASK -> buildDatabaseCreateGroupActionTask(intent)
ACTION_DATABASE_UPDATE_GROUP_TASK -> buildDatabaseUpdateGroupActionTask(intent)
ACTION_DATABASE_CREATE_ENTRY_TASK -> buildDatabaseCreateEntryActionTask(intent)
ACTION_DATABASE_UPDATE_ENTRY_TASK -> buildDatabaseUpdateEntryActionTask(intent)
ACTION_DATABASE_COPY_NODES_TASK -> buildDatabaseCopyNodesActionTask(intent)
ACTION_DATABASE_MOVE_NODES_TASK -> buildDatabaseMoveNodesActionTask(intent)
ACTION_DATABASE_DELETE_NODES_TASK -> buildDatabaseDeleteNodesActionTask(intent)
ACTION_DATABASE_RESTORE_ENTRY_HISTORY -> buildDatabaseRestoreEntryHistoryActionTask(intent)
ACTION_DATABASE_DELETE_ENTRY_HISTORY -> buildDatabaseDeleteEntryHistoryActionTask(intent)
ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> buildDatabaseUpdateCompressionActionTask(intent)
ACTION_DATABASE_REMOVE_UNLINKED_DATA_TASK -> buildDatabaseRemoveUnlinkedDataActionTask(intent)
ACTION_DATABASE_CREATE_TASK -> buildDatabaseCreateActionTask(intent, database)
ACTION_DATABASE_LOAD_TASK -> buildDatabaseLoadActionTask(intent, database)
ACTION_DATABASE_RELOAD_TASK -> buildDatabaseReloadActionTask(database)
ACTION_DATABASE_ASSIGN_PASSWORD_TASK -> buildDatabaseAssignPasswordActionTask(intent, database)
ACTION_DATABASE_CREATE_GROUP_TASK -> buildDatabaseCreateGroupActionTask(intent, database)
ACTION_DATABASE_UPDATE_GROUP_TASK -> buildDatabaseUpdateGroupActionTask(intent, database)
ACTION_DATABASE_CREATE_ENTRY_TASK -> buildDatabaseCreateEntryActionTask(intent, database)
ACTION_DATABASE_UPDATE_ENTRY_TASK -> buildDatabaseUpdateEntryActionTask(intent, database)
ACTION_DATABASE_COPY_NODES_TASK -> buildDatabaseCopyNodesActionTask(intent, database)
ACTION_DATABASE_MOVE_NODES_TASK -> buildDatabaseMoveNodesActionTask(intent, database)
ACTION_DATABASE_DELETE_NODES_TASK -> buildDatabaseDeleteNodesActionTask(intent, database)
ACTION_DATABASE_RESTORE_ENTRY_HISTORY -> buildDatabaseRestoreEntryHistoryActionTask(intent, database)
ACTION_DATABASE_DELETE_ENTRY_HISTORY -> buildDatabaseDeleteEntryHistoryActionTask(intent, database)
ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> buildDatabaseUpdateCompressionActionTask(intent, database)
ACTION_DATABASE_REMOVE_UNLINKED_DATA_TASK -> buildDatabaseRemoveUnlinkedDataActionTask(intent, database)
ACTION_DATABASE_UPDATE_NAME_TASK,
ACTION_DATABASE_UPDATE_DESCRIPTION_TASK,
ACTION_DATABASE_UPDATE_DEFAULT_USERNAME_TASK,
@@ -244,8 +247,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
ACTION_DATABASE_UPDATE_KEY_DERIVATION_TASK,
ACTION_DATABASE_UPDATE_MEMORY_USAGE_TASK,
ACTION_DATABASE_UPDATE_PARALLELISM_TASK,
ACTION_DATABASE_UPDATE_ITERATIONS_TASK -> buildDatabaseUpdateElementActionTask(intent)
ACTION_DATABASE_SAVE -> buildDatabaseSave(intent)
ACTION_DATABASE_UPDATE_ITERATIONS_TASK -> buildDatabaseUpdateElementActionTask(intent, database)
ACTION_DATABASE_SAVE -> buildDatabaseSave(intent, database)
else -> null
}
@@ -265,7 +268,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
})
mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onStartAction(mDatabase, mTitleId, mMessageId, mWarningId)
actionTaskListener.onStartAction(database, mTitleId, mMessageId, mWarningId)
}
},
@@ -275,7 +278,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
{ result ->
try {
mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onStopAction(mDatabase, intentAction!!, result)
actionTaskListener.onStopAction(database, intentAction!!, result)
}
} finally {
// Save the database info before performing action
@@ -285,7 +288,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
// Save the database info after performing save action
if (intentAction == ACTION_DATABASE_SAVE
|| intent?.getBooleanExtra(SAVE_DATABASE_KEY, false) == true) {
mDatabase.fileUri?.let {
database.fileUri?.let {
val newSnapFileDatabaseInfo = SnapFileDatabaseInfo.fromFileDatabaseInfo(
FileDatabaseInfo(applicationContext, it))
mLastLocalSaveTime = System.currentTimeMillis()
@@ -295,7 +298,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
removeIntentData(intent)
TimeoutHelper.releaseTemporarilyDisableTimeout()
if (TimeoutHelper.checkTimeAndLockIfTimeout(this@DatabaseTaskNotificationService)) {
if (!mDatabase.loaded) {
if (!database.loaded) {
stopSelf()
} else {
// Restart the service to open lock notification
@@ -386,25 +389,33 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
if (intentAction == null) {
mDatabase?.let { database ->
// Database is normally open
if (mDatabase.loaded) {
if (database.loaded) {
// Build Intents for notification action
val pendingDatabaseIntent = PendingIntent.getActivity(this,
val pendingDatabaseIntent = PendingIntent.getActivity(
this,
0,
Intent(this, GroupActivity::class.java).apply {
ReadOnlyHelper.putReadOnlyInIntent(this, mDatabase.isReadOnly)
ReadOnlyHelper.putReadOnlyInIntent(this, database.isReadOnly)
},
PendingIntent.FLAG_UPDATE_CURRENT)
val pendingDeleteIntent = PendingIntent.getBroadcast(this,
4576, Intent(LOCK_ACTION), 0)
PendingIntent.FLAG_UPDATE_CURRENT
)
val pendingDeleteIntent = PendingIntent.getBroadcast(
this,
4576, Intent(LOCK_ACTION), 0
)
// Add actions in notifications
notificationBuilder.apply {
setContentText(mDatabase.name + " (" + mDatabase.version + ")")
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)
addAction(
R.drawable.ic_lock_white_24dp, getString(R.string.lock),
pendingDeleteIntent
)
}
}
}
}
@@ -464,8 +475,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override fun updateMessage(resId: Int) {
mMessageId = resId
mDatabase?.let { database ->
mActionTaskListeners.forEach { actionTaskListener ->
actionTaskListener.onUpdateAction(mDatabase, mTitleId, mMessageId, mWarningId)
actionTaskListener.onUpdateAction(database, mTitleId, mMessageId, mWarningId)
}
}
}
@@ -479,7 +492,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseCreateActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseCreateActionTask(intent: Intent, database: Database): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
@@ -491,7 +504,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return null
return CreateDatabaseRunnable(this,
mDatabase,
database,
databaseUri,
getString(R.string.database_default_name),
getString(R.string.database),
@@ -508,7 +521,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseLoadActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseLoadActionTask(intent: Intent, database: Database): ActionRunnable? {
if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
@@ -526,7 +539,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return LoadDatabaseRunnable(
this,
mDatabase,
database,
databaseUri,
mainCredential,
readOnly,
@@ -547,10 +560,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseReloadActionTask(): ActionRunnable {
private fun buildDatabaseReloadActionTask(database: Database): ActionRunnable {
return ReloadDatabaseRunnable(
this,
mDatabase,
database,
this
) { result ->
// No need to add each info to reload database
@@ -558,13 +571,13 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseAssignPasswordActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseAssignPasswordActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
) {
val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null
AssignPasswordInDatabaseRunnable(this,
mDatabase,
database,
databaseUri,
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential()
)
@@ -583,7 +596,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseCreateGroupActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseCreateGroupActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(GROUP_KEY)
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
@@ -595,9 +608,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|| newGroup == null)
return null
mDatabase.getGroupById(parentId)?.let { parent ->
database.getGroupById(parentId)?.let { parent ->
AddGroupRunnable(this,
mDatabase,
database,
newGroup,
parent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -608,7 +621,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseUpdateGroupActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseUpdateGroupActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(GROUP_ID_KEY)
&& intent.hasExtra(GROUP_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
@@ -620,9 +633,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|| newGroup == null)
return null
mDatabase.getGroupById(groupId)?.let { oldGroup ->
database.getGroupById(groupId)?.let { oldGroup ->
UpdateGroupRunnable(this,
mDatabase,
database,
oldGroup,
newGroup,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -633,7 +646,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseCreateEntryActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseCreateEntryActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(ENTRY_KEY)
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
@@ -645,9 +658,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|| newEntry == null)
return null
mDatabase.getGroupById(parentId)?.let { parent ->
database.getGroupById(parentId)?.let { parent ->
AddEntryRunnable(this,
mDatabase,
database,
newEntry,
parent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -658,7 +671,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseUpdateEntryActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseUpdateEntryActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(ENTRY_ID_KEY)
&& intent.hasExtra(ENTRY_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
@@ -670,9 +683,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
|| newEntry == null)
return null
mDatabase.getEntryById(entryId)?.let { oldEntry ->
database.getEntryById(entryId)?.let { oldEntry ->
UpdateEntryRunnable(this,
mDatabase,
database,
oldEntry,
newEntry,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
@@ -683,7 +696,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseCopyNodesActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseCopyNodesActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY)
&& intent.hasExtra(PARENT_ID_KEY)
@@ -691,10 +704,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
) {
val parentId: NodeId<*> = intent.getParcelableExtra(PARENT_ID_KEY) ?: return null
mDatabase.getGroupById(parentId)?.let { newParent ->
database.getGroupById(parentId)?.let { newParent ->
CopyNodesRunnable(this,
mDatabase,
getListNodesFromBundle(mDatabase, intent.extras!!),
database,
getListNodesFromBundle(database, intent.extras!!),
newParent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
AfterActionNodesRunnable())
@@ -704,7 +717,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseMoveNodesActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseMoveNodesActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY)
&& intent.hasExtra(PARENT_ID_KEY)
@@ -712,10 +725,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
) {
val parentId: NodeId<*> = intent.getParcelableExtra(PARENT_ID_KEY) ?: return null
mDatabase.getGroupById(parentId)?.let { newParent ->
database.getGroupById(parentId)?.let { newParent ->
MoveNodesRunnable(this,
mDatabase,
getListNodesFromBundle(mDatabase, intent.extras!!),
database,
getListNodesFromBundle(database, intent.extras!!),
newParent,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
AfterActionNodesRunnable())
@@ -725,14 +738,14 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseDeleteNodesActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseDeleteNodesActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(GROUPS_ID_KEY)
&& intent.hasExtra(ENTRIES_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
DeleteNodesRunnable(this,
mDatabase,
getListNodesFromBundle(mDatabase, intent.extras!!),
database,
getListNodesFromBundle(database, intent.extras!!),
intent.getBooleanExtra(SAVE_DATABASE_KEY, false),
AfterActionNodesRunnable())
} else {
@@ -740,16 +753,16 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseRestoreEntryHistoryActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseRestoreEntryHistoryActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(ENTRY_ID_KEY)
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val entryId: NodeId<UUID> = intent.getParcelableExtra(ENTRY_ID_KEY) ?: return null
mDatabase.getEntryById(entryId)?.let { mainEntry ->
database.getEntryById(entryId)?.let { mainEntry ->
RestoreEntryHistoryDatabaseRunnable(this,
mDatabase,
database,
mainEntry,
intent.getIntExtra(ENTRY_HISTORY_POSITION_KEY, -1),
intent.getBooleanExtra(SAVE_DATABASE_KEY, false))
@@ -759,16 +772,16 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseDeleteEntryHistoryActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseDeleteEntryHistoryActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(ENTRY_ID_KEY)
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val entryId: NodeId<UUID> = intent.getParcelableExtra(ENTRY_ID_KEY) ?: return null
mDatabase.getEntryById(entryId)?.let { mainEntry ->
database.getEntryById(entryId)?.let { mainEntry ->
DeleteEntryHistoryDatabaseRunnable(this,
mDatabase,
database,
mainEntry,
intent.getIntExtra(ENTRY_HISTORY_POSITION_KEY, -1),
intent.getBooleanExtra(SAVE_DATABASE_KEY, false))
@@ -778,7 +791,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseUpdateCompressionActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseUpdateCompressionActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(OLD_ELEMENT_KEY)
&& intent.hasExtra(NEW_ELEMENT_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)) {
@@ -791,7 +804,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return null
return UpdateCompressionBinariesDatabaseRunnable(this,
mDatabase,
database,
oldElement,
newElement,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
@@ -805,11 +818,11 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseRemoveUnlinkedDataActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseRemoveUnlinkedDataActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
return RemoveUnlinkedDataDatabaseRunnable(this,
mDatabase,
database,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
).apply {
mAfterSaveDatabase = { result ->
@@ -821,10 +834,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
private fun buildDatabaseUpdateElementActionTask(intent: Intent): ActionRunnable? {
private fun buildDatabaseUpdateElementActionTask(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
return SaveDatabaseRunnable(this,
mDatabase,
database,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
).apply {
mAfterSaveDatabase = { result ->
@@ -839,10 +852,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
/**
* Save database without parameter
*/
private fun buildDatabaseSave(intent: Intent): ActionRunnable? {
private fun buildDatabaseSave(intent: Intent, database: Database): ActionRunnable? {
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
SaveDatabaseRunnable(this,
mDatabase,
database,
intent.getBooleanExtra(SAVE_DATABASE_KEY, false))
} else {
null
@@ -851,7 +864,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override fun onDestroy() {
super.onDestroy()
if (mDatabase.loaded)
// TODO remove ?
actionOnLock()
}

View File

@@ -125,7 +125,7 @@ fun Context.unregisterLockReceiver(lockReceiver: LockReceiver?) {
}
}
fun Context.closeDatabase(database: Database) {
fun Context.closeDatabase(database: Database?) {
// Stop the Magikeyboard service
stopService(Intent(this, KeyboardEntryNotificationService::class.java))
MagikIME.removeEntry(this)
@@ -138,5 +138,5 @@ fun Context.closeDatabase(database: Database) {
cancelAll()
}
// Clear data
database.clearAndClose(this)
database?.clearAndClose(this)
}