mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Remove default database parameter when the file is no longer accessible #803
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
KeePassDX(2.9.3)
|
||||
* Unlock database by device credentials (PIN/Password/Pattern) #779 #102
|
||||
* Remove default database parameter when the file is no longer accessible #803
|
||||
|
||||
KeePassDX(2.9.2)
|
||||
* Managing OTP links from QR applications #556
|
||||
|
||||
@@ -237,10 +237,10 @@ class FileDatabaseSelectActivity : SpecialModeActivity(),
|
||||
|
||||
private fun fileNoFoundAction(e: FileNotFoundException) {
|
||||
val error = getString(R.string.file_not_found_content)
|
||||
Log.e(TAG, error, e)
|
||||
coordinatorLayout?.let {
|
||||
Snackbar.make(it, error, Snackbar.LENGTH_LONG).asError().show()
|
||||
}
|
||||
Log.e(TAG, error, e)
|
||||
}
|
||||
|
||||
private fun launchPasswordActivity(databaseUri: Uri, keyFile: Uri?) {
|
||||
|
||||
@@ -56,6 +56,7 @@ import com.kunzisoft.keepass.biometric.BiometricUnlockDatabaseHelper
|
||||
import com.kunzisoft.keepass.database.action.ProgressDatabaseTaskProvider
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.FileNotFoundDatabaseException
|
||||
import com.kunzisoft.keepass.education.PasswordActivityEducation
|
||||
import com.kunzisoft.keepass.model.RegisterInfo
|
||||
import com.kunzisoft.keepass.model.SearchInfo
|
||||
@@ -92,6 +93,7 @@ open class PasswordActivity : SpecialModeActivity() {
|
||||
|
||||
private val databaseFileViewModel: DatabaseFileViewModel by viewModels()
|
||||
|
||||
private var mDefaultDatabase: Boolean = false
|
||||
private var mDatabaseFileUri: Uri? = null
|
||||
private var mDatabaseKeyFileUri: Uri? = null
|
||||
|
||||
@@ -173,6 +175,11 @@ open class PasswordActivity : SpecialModeActivity() {
|
||||
mAllowAutoOpenBiometricPrompt = savedInstanceState.getBoolean(ALLOW_AUTO_OPEN_BIOMETRIC_PROMPT)
|
||||
}
|
||||
|
||||
// Observe if default database
|
||||
databaseFileViewModel.isDefaultDatabase.observe(this) { isDefaultDatabase ->
|
||||
mDefaultDatabase = isDefaultDatabase
|
||||
}
|
||||
|
||||
// Observe database file change
|
||||
databaseFileViewModel.databaseFileLoaded.observe(this, Observer { databaseFile ->
|
||||
// Force read only if the file does not exists
|
||||
@@ -220,8 +227,9 @@ open class PasswordActivity : SpecialModeActivity() {
|
||||
if (resultException != null) {
|
||||
resultError = resultException.getLocalizedMessage(resources)
|
||||
|
||||
when (resultException) {
|
||||
is DuplicateUuidDatabaseException -> {
|
||||
// Relaunch loading if we need to fix UUID
|
||||
if (resultException is DuplicateUuidDatabaseException) {
|
||||
showLoadDatabaseDuplicateUuidMessage {
|
||||
|
||||
var databaseUri: Uri? = null
|
||||
@@ -249,6 +257,13 @@ open class PasswordActivity : SpecialModeActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
is FileNotFoundDatabaseException -> {
|
||||
// Remove this default database inaccessible
|
||||
if (mDefaultDatabase) {
|
||||
databaseFileViewModel.removeDefaultDatabase()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show error message
|
||||
@@ -277,6 +292,9 @@ open class PasswordActivity : SpecialModeActivity() {
|
||||
mDatabaseFileUri = intent?.getParcelableExtra(KEY_FILENAME)
|
||||
mDatabaseKeyFileUri = intent?.getParcelableExtra(KEY_KEYFILE)
|
||||
}
|
||||
mDatabaseFileUri?.let {
|
||||
databaseFileViewModel.checkIfIsDefaultDatabase(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.settings
|
||||
|
||||
import android.app.backup.BackupManager
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
@@ -43,6 +44,7 @@ object PreferencesUtil {
|
||||
}
|
||||
apply()
|
||||
}
|
||||
BackupManager(context).dataChanged()
|
||||
}
|
||||
|
||||
fun getDefaultDatabasePath(context: Context): String? {
|
||||
|
||||
@@ -4,8 +4,12 @@ import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.kunzisoft.keepass.app.App
|
||||
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
|
||||
import com.kunzisoft.keepass.app.database.IOActionTask
|
||||
import com.kunzisoft.keepass.model.DatabaseFile
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
|
||||
class DatabaseFileViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
@@ -15,6 +19,33 @@ class DatabaseFileViewModel(application: Application) : AndroidViewModel(applica
|
||||
mFileDatabaseHistoryAction = FileDatabaseHistoryAction.getInstance(application.applicationContext)
|
||||
}
|
||||
|
||||
val isDefaultDatabase: MutableLiveData<Boolean> by lazy {
|
||||
MutableLiveData<Boolean>()
|
||||
}
|
||||
|
||||
fun checkIfIsDefaultDatabase(databaseUri: Uri) {
|
||||
IOActionTask(
|
||||
{
|
||||
(UriUtil.parse(PreferencesUtil.getDefaultDatabasePath(getApplication<App>().applicationContext))
|
||||
== databaseUri)
|
||||
},
|
||||
{
|
||||
isDefaultDatabase.value = it
|
||||
}
|
||||
).execute()
|
||||
}
|
||||
|
||||
fun removeDefaultDatabase() {
|
||||
IOActionTask(
|
||||
{
|
||||
PreferencesUtil.saveDefaultDatabasePath(getApplication<App>().applicationContext,
|
||||
null)
|
||||
},
|
||||
{
|
||||
}
|
||||
).execute()
|
||||
}
|
||||
|
||||
val databaseFileLoaded: MutableLiveData<DatabaseFile> by lazy {
|
||||
MutableLiveData<DatabaseFile>()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.kunzisoft.keepass.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import android.app.backup.BackupManager
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
@@ -42,11 +41,8 @@ class DatabaseFilesViewModel(application: Application) : AndroidViewModel(applic
|
||||
fun setDefaultDatabase(databaseFile: DatabaseFile?) {
|
||||
IOActionTask(
|
||||
{
|
||||
val context = getApplication<App>().applicationContext
|
||||
UriUtil.parse(PreferencesUtil.getDefaultDatabasePath(context))
|
||||
PreferencesUtil.saveDefaultDatabasePath(context, databaseFile?.databaseUri)
|
||||
val backupManager = BackupManager(context)
|
||||
backupManager.dataChanged()
|
||||
PreferencesUtil.saveDefaultDatabasePath(getApplication<App>().applicationContext,
|
||||
databaseFile?.databaseUri)
|
||||
},
|
||||
{
|
||||
checkDefaultDatabase()
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
* Unlock database by device credentials (PIN/Password/Pattern) #779 #102
|
||||
* Remove default database parameter when the file is no longer accessible #803
|
||||
@@ -1 +1,2 @@
|
||||
* Déverouillage de base de données avec identifiants de l'appareil (PIN/Password/Pattern) #779 #102
|
||||
* Supprimer le parmètre de base de données par défaut quand le fichier n'est plus accessible #803
|
||||
Reference in New Issue
Block a user