fix: Multiple launch instance

This commit is contained in:
J-Jamet
2025-10-10 13:52:08 +02:00
parent e6253336bd
commit 65857596a6
6 changed files with 15 additions and 27 deletions

View File

@@ -365,10 +365,6 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
} }
} }
mDatabase?.let { database ->
launchGroupActivityIfLoaded(database)
}
// Show recent files if allowed // Show recent files if allowed
if (PreferencesUtil.showRecentFiles(this@FileDatabaseSelectActivity)) { if (PreferencesUtil.showRecentFiles(this@FileDatabaseSelectActivity)) {
databaseFilesViewModel.loadListOfDatabases() databaseFilesViewModel.loadListOfDatabases()

View File

@@ -93,7 +93,7 @@ abstract class CredentialLauncherViewModel(application: Application): AndroidVie
specialMode: SpecialMode, specialMode: SpecialMode,
database: ContextualDatabase? database: ContextualDatabase?
) { ) {
database?.let { if (database != null && database.loaded) {
onDatabaseRetrieved(database) onDatabaseRetrieved(database)
} }
if (isResultLauncherRegistered.not()) { if (isResultLauncherRegistered.not()) {

View File

@@ -155,7 +155,7 @@ class PasskeyLauncherViewModel(application: Application): CredentialLauncherView
database: ContextualDatabase? database: ContextualDatabase?
) { ) {
// Launch with database when a nodeId is present // Launch with database when a nodeId is present
if (database != null || intent.retrieveNodeId() == null) { if ((database != null && database.loaded) || intent.retrieveNodeId() == null) {
super.launchActionIfNeeded(intent, specialMode, database) super.launchActionIfNeeded(intent, specialMode, database)
} }
} }

View File

@@ -37,7 +37,6 @@ import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.DatabaseChangedDialogFragment
import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Entry
@@ -104,11 +103,6 @@ class DatabaseTaskProvider(
private var serviceConnection: ServiceConnection? = null private var serviceConnection: ServiceConnection? = null
private var intentDatabaseTask: Intent = Intent(
context.applicationContext,
DatabaseTaskNotificationService::class.java
)
fun destroy() { fun destroy() {
this.onDatabaseRetrieved = null this.onDatabaseRetrieved = null
this.databaseTaskBroadcastReceiver = null this.databaseTaskBroadcastReceiver = null
@@ -116,13 +110,6 @@ class DatabaseTaskProvider(
this.serviceConnection = null this.serviceConnection = null
} }
private val mActionDatabaseListener =
object : DatabaseChangedDialogFragment.ActionDatabaseChangedListener {
override fun onDatabaseChangeValidated() {
mBinder?.getService()?.saveDatabaseInfo()
}
}
fun onDatabaseChangeValidated() { fun onDatabaseChangeValidated() {
mBinder?.getService()?.saveDatabaseInfo() mBinder?.getService()?.saveDatabaseInfo()
} }
@@ -139,10 +126,12 @@ class DatabaseTaskProvider(
serviceConnection = object : ServiceConnection { serviceConnection = object : ServiceConnection {
override fun onBindingDied(name: ComponentName?) { override fun onBindingDied(name: ComponentName?) {
actionTaskListener?.onActionStopped() actionTaskListener?.onActionStopped()
onDatabaseRetrieved?.invoke(null)
} }
override fun onNullBinding(name: ComponentName?) { override fun onNullBinding(name: ComponentName?) {
actionTaskListener?.onActionStopped() actionTaskListener?.onActionStopped()
onDatabaseRetrieved?.invoke(null)
} }
override fun onServiceConnected(name: ComponentName?, serviceBinder: IBinder?) { override fun onServiceConnected(name: ComponentName?, serviceBinder: IBinder?) {
@@ -181,13 +170,17 @@ class DatabaseTaskProvider(
service?.removeDatabaseFileInfoListener(infoListener) service?.removeDatabaseFileInfoListener(infoListener)
} }
service?.removeDatabaseListener(databaseListener) service?.removeDatabaseListener(databaseListener)
onDatabaseRetrieved?.invoke(null)
} }
private fun bindService() { private fun bindService() {
initServiceConnection() initServiceConnection()
serviceConnection?.let { serviceConnection?.let {
context.bindService( context.bindService(
intentDatabaseTask, Intent(
context.applicationContext,
DatabaseTaskNotificationService::class.java
),
it, it,
BIND_AUTO_CREATE or BIND_IMPORTANT or BIND_ABOVE_CLIENT BIND_AUTO_CREATE or BIND_IMPORTANT or BIND_ABOVE_CLIENT
) )

View File

@@ -676,6 +676,12 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override fun actionOnLock() { override fun actionOnLock() {
if (!TimeoutHelper.temporarilyDisableLock) { if (!TimeoutHelper.temporarilyDisableLock) {
closeDatabase(mDatabase) closeDatabase(mDatabase)
// Remove the database during the lock
// And notify each subscriber
mDatabase = null
mDatabaseListeners.forEach { listener ->
listener.onDatabaseRetrieved(null)
}
// 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

View File

@@ -20,7 +20,6 @@ import com.kunzisoft.keepass.model.CipherEncryptDatabase
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.utils.getBinaryDir
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import java.util.UUID import java.util.UUID
@@ -154,12 +153,6 @@ class DatabaseViewModel(application: Application): AndroidViewModel(application)
} }
} }
fun closeDatabase() {
database?.clearAndClose(
filesDirectory = getApplication<Application>().getBinaryDir()
)
}
fun onDatabaseChangeValidated() { fun onDatabaseChangeValidated() {
mDatabaseTaskProvider.onDatabaseChangeValidated() mDatabaseTaskProvider.onDatabaseChangeValidated()
} }