diff --git a/app/build.gradle b/app/build.gradle index 1205daf05..f0aa06a94 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,6 +21,13 @@ android { buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}" manifestPlaceholders = [ googleAndroidBackupAPIKey:"unused" ] + + kapt { + arguments { + arg("room.incremental", "true") + arg("room.schemaLocation", "$projectDir/schemas".toString()) + } + } } buildTypes { diff --git a/database/schemas/com.kunzisoft.keepass.app.database.AppDatabase/1.json b/app/schemas/com.kunzisoft.keepass.app.database.AppDatabase/1.json similarity index 100% rename from database/schemas/com.kunzisoft.keepass.app.database.AppDatabase/1.json rename to app/schemas/com.kunzisoft.keepass.app.database.AppDatabase/1.json diff --git a/database/schemas/com.kunzisoft.keepass.app.database.AppDatabase/2.json b/app/schemas/com.kunzisoft.keepass.app.database.AppDatabase/2.json similarity index 100% rename from database/schemas/com.kunzisoft.keepass.app.database.AppDatabase/2.json rename to app/schemas/com.kunzisoft.keepass.app.database.AppDatabase/2.json diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt index 44e0dda98..5afc1b5f5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/AutofillLauncherActivity.kt @@ -37,10 +37,11 @@ import com.kunzisoft.keepass.autofill.AutofillHelper import com.kunzisoft.keepass.autofill.CompatInlineSuggestionsRequest import com.kunzisoft.keepass.autofill.KeeAutofillService import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.model.RegisterInfo import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.settings.PreferencesUtil +import com.kunzisoft.keepass.utils.WebDomain @RequiresApi(api = Build.VERSION_CODES.O) class AutofillLauncherActivity : DatabaseModeActivity() { @@ -73,7 +74,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() { } // Build search param bundle.getParcelable(KEY_SEARCH_INFO)?.let { searchInfo -> - SearchInfo.getConcreteWebDomain( + WebDomain.getConcreteWebDomain( this, searchInfo.webDomain ) { concreteWebDomain -> @@ -101,7 +102,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() { // To register info val registerInfo = intent.getParcelableExtra(KEY_REGISTER_INFO) val searchInfo = SearchInfo(registerInfo?.searchInfo) - SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain -> + WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain -> searchInfo.webDomain = concreteWebDomain launchRegistration(database, searchInfo, registerInfo) } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt index 9433054e8..b60da17e6 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntrySelectionLauncherActivity.kt @@ -27,10 +27,11 @@ import android.widget.Toast import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.magikeyboard.MagikeyboardService import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.otp.OtpEntryFields +import com.kunzisoft.keepass.utils.WebDomain /** * Activity to search or select entry in database, @@ -104,7 +105,7 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() { this.otpString = otpString } - SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain -> + WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain -> searchInfo.webDomain = concreteWebDomain launch(database, searchInfo) } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt index b658afdcd..04c125168 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.kt @@ -64,7 +64,7 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.NodeIdUUID import com.kunzisoft.keepass.database.element.node.Type -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.database.search.SearchParameters import com.kunzisoft.keepass.education.GroupActivityEducation import com.kunzisoft.keepass.magikeyboard.MagikeyboardService diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/MainCredentialActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/MainCredentialActivity.kt index 980731521..371a321ea 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/MainCredentialActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/MainCredentialActivity.kt @@ -59,7 +59,6 @@ import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException import com.kunzisoft.keepass.database.exception.FileNotFoundDatabaseException -import com.kunzisoft.keepass.database.exception.getLocalizedMessage import com.kunzisoft.keepass.education.PasswordActivityEducation import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.model.* diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt index f73fb595a..650a7b94a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryFragment.kt @@ -17,7 +17,7 @@ import com.kunzisoft.keepass.adapters.EntryAttachmentsItemsAdapter import com.kunzisoft.keepass.database.element.Attachment import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.getLocalizedName +import com.kunzisoft.keepass.database.helper.getLocalizedName import com.kunzisoft.keepass.model.EntryAttachmentState import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.StreamDirection diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/BreadcrumbAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/BreadcrumbAdapter.kt index b3073a9c0..f87576716 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/BreadcrumbAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/BreadcrumbAdapter.kt @@ -112,7 +112,11 @@ class BreadcrumbAdapter(val context: Context) holder.groupNumbersView?.apply { if (mShowNumberEntries) { - group.refreshNumberOfChildEntries(Group.ChildFilter.getDefaults(context)) + group.refreshNumberOfChildEntries( + Group.ChildFilter.getDefaults( + PreferencesUtil.showExpiredEntries(context) + ) + ) text = group.numberOfChildEntries.toString() visibility = View.VISIBLE } else { diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryAttachmentsItemsAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryAttachmentsItemsAdapter.kt index 2798df815..feba0f798 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/EntryAttachmentsItemsAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/EntryAttachmentsItemsAdapter.kt @@ -33,7 +33,8 @@ import androidx.recyclerview.widget.RecyclerView import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.ImageViewerActivity import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm +import com.kunzisoft.keepass.database.helper.getLocalizedName import com.kunzisoft.keepass.model.AttachmentState import com.kunzisoft.keepass.model.EntryAttachmentState import com.kunzisoft.keepass.model.StreamDirection @@ -130,7 +131,7 @@ class EntryAttachmentsItemsAdapter(context: Context) holder.binaryFileSize.text = Formatter.formatFileSize(context, size) holder.binaryFileCompression.apply { if (entryAttachmentState.attachment.binaryData.isCompressed) { - text = NamedCompressionAlgorithm.GZip.getName(context.resources) + text = CompressionAlgorithm.GZIP.getLocalizedName(context.resources) visibility = View.VISIBLE } else { text = "" diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt index 628d9bc34..0a76b6d8b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt @@ -42,7 +42,7 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.NodeVersionedInterface import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.getLocalizedName +import com.kunzisoft.keepass.database.helper.getLocalizedName import com.kunzisoft.keepass.otp.OtpElement import com.kunzisoft.keepass.otp.OtpType import com.kunzisoft.keepass.settings.PreferencesUtil @@ -153,7 +153,9 @@ class NodesAdapter (private val context: Context, this.mShowOTP = PreferencesUtil.showOTPToken(context) this.mShowUUID = PreferencesUtil.showUUID(context) - this.mEntryFilters = Group.ChildFilter.getDefaults(context) + this.mEntryFilters = Group.ChildFilter.getDefaults( + PreferencesUtil.showExpiredEntries(context) + ) // Reinit textSize for all view type mCalculateViewTypeTextSize.forEachIndexed { index, _ -> mCalculateViewTypeTextSize[index] = true } diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt index 7c210fbf5..54d056711 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt @@ -11,7 +11,7 @@ import android.widget.TextView import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.template.Template import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.getLocalizedName +import com.kunzisoft.keepass.database.helper.getLocalizedName import com.kunzisoft.keepass.icons.IconDrawableFactory diff --git a/database/src/main/java/com/kunzisoft/keepass/app/database/AppDatabase.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/AppDatabase.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/app/database/AppDatabase.kt rename to app/src/main/java/com/kunzisoft/keepass/app/database/AppDatabase.kt diff --git a/app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseAction.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseAction.kt index 430caeca5..6b1d385b3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseAction.kt +++ b/app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseAction.kt @@ -30,6 +30,7 @@ import android.util.Log import com.kunzisoft.keepass.model.CipherEncryptDatabase import com.kunzisoft.keepass.services.AdvancedUnlockNotificationService import com.kunzisoft.keepass.settings.PreferencesUtil +import com.kunzisoft.keepass.utils.IOActionTask import com.kunzisoft.keepass.utils.SingletonHolderParameter import java.util.LinkedList diff --git a/database/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseDao.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseDao.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseDao.kt rename to app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseDao.kt diff --git a/database/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseEntity.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseEntity.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseEntity.kt rename to app/src/main/java/com/kunzisoft/keepass/app/database/CipherDatabaseEntity.kt diff --git a/app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryAction.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryAction.kt index 39536221a..85babb678 100644 --- a/app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryAction.kt +++ b/app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryAction.kt @@ -25,6 +25,7 @@ import android.util.Log import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.model.DatabaseFile import com.kunzisoft.keepass.settings.PreferencesUtil +import com.kunzisoft.keepass.utils.IOActionTask import com.kunzisoft.keepass.utils.SingletonHolderParameter import com.kunzisoft.keepass.utils.UriUtilDatabase import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo diff --git a/database/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryDao.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryDao.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryDao.kt rename to app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryDao.kt diff --git a/database/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryEntity.kt b/app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryEntity.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryEntity.kt rename to app/src/main/java/com/kunzisoft/keepass/app/database/FileDatabaseHistoryEntity.kt diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt index 6462833ce..a8aa049ed 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt @@ -37,12 +37,13 @@ import com.kunzisoft.keepass.R import com.kunzisoft.keepass.activities.AutofillLauncherActivity import com.kunzisoft.keepass.database.action.DatabaseTaskProvider import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.model.CreditCard import com.kunzisoft.keepass.model.RegisterInfo import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.settings.AutofillSettingsActivity import com.kunzisoft.keepass.settings.PreferencesUtil +import com.kunzisoft.keepass.utils.WebDomain import org.joda.time.DateTime import java.util.concurrent.atomic.AtomicBoolean @@ -104,7 +105,7 @@ class KeeAutofillService : AutofillService() { webDomain = parseResult.webDomain webScheme = parseResult.webScheme } - SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { webDomainWithoutSubDomain -> + WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { webDomainWithoutSubDomain -> searchInfo.webDomain = webDomainWithoutSubDomain val inlineSuggestionsRequest = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && autofillInlineSuggestionsEnabled) { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/AssignMainCredentialInDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/AssignMainCredentialInDatabaseRunnable.kt index d61d83d69..e22875312 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/AssignMainCredentialInDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AssignMainCredentialInDatabaseRunnable.kt @@ -24,16 +24,16 @@ import android.net.Uri import com.kunzisoft.keepass.app.database.CipherDatabaseAction import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.database.element.MainCredential +import com.kunzisoft.keepass.hardware.HardwareKey open class AssignMainCredentialInDatabaseRunnable ( context: Context, database: Database, protected val mDatabaseUri: Uri, mainCredential: MainCredential, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : SaveDatabaseRunnable(context, database, true, mainCredential, challengeResponseRetriever) { + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : SaveDatabaseRunnable(context, database, true, mainCredential, challengeResponseRetriever) { private var mBackupKey: ByteArray? = null diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDatabaseRunnable.kt index 7707559da..2dccbaed3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDatabaseRunnable.kt @@ -24,20 +24,21 @@ import android.net.Uri import android.util.Log import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.database.element.MainCredential +import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.settings.PreferencesUtil -class CreateDatabaseRunnable(context: Context, - private val mDatabase: Database, - databaseUri: Uri, - private val databaseName: String, - private val rootName: String, - private val templateGroupName: String?, - val mainCredential: MainCredential, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, - private val createDatabaseResult: ((Result) -> Unit)?) - : AssignMainCredentialInDatabaseRunnable(context, mDatabase, databaseUri, mainCredential, challengeResponseRetriever) { +class CreateDatabaseRunnable( + context: Context, + private val mDatabase: Database, + databaseUri: Uri, + private val databaseName: String, + private val rootName: String, + private val templateGroupName: String?, + val mainCredential: MainCredential, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, + private val createDatabaseResult: ((Result) -> Unit)? +) : AssignMainCredentialInDatabaseRunnable(context, mDatabase, databaseUri, mainCredential, challengeResponseRetriever) { override fun onStartRun() { try { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt index 4390681fa..4111c3325 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/DatabaseTaskProvider.kt @@ -38,7 +38,7 @@ import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Group import com.kunzisoft.keepass.database.element.MainCredential -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.Type @@ -584,8 +584,8 @@ class DatabaseTaskProvider(private var context: Context, , ACTION_DATABASE_UPDATE_COLOR_TASK) } - fun startDatabaseSaveCompression(oldCompression: NamedCompressionAlgorithm, - newCompression: NamedCompressionAlgorithm, + fun startDatabaseSaveCompression(oldCompression: CompressionAlgorithm, + newCompression: CompressionAlgorithm, save: Boolean) { start(Bundle().apply { putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldCompression) diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/MergeDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/MergeDatabaseRunnable.kt similarity index 88% rename from database/src/main/java/com/kunzisoft/keepass/database/action/MergeDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/MergeDatabaseRunnable.kt index a0a905d16..6a4cbdc9e 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/MergeDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/MergeDatabaseRunnable.kt @@ -26,8 +26,7 @@ import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.element.binary.BinaryData import com.kunzisoft.keepass.database.exception.DatabaseException import com.kunzisoft.keepass.hardware.HardwareKey -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil -import com.kunzisoft.keepass.tasks.ActionRunnable +import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.tasks.ProgressTaskUpdater class MergeDatabaseRunnable( @@ -39,8 +38,8 @@ class MergeDatabaseRunnable( saveDatabase: Boolean, challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, private val progressTaskUpdater: ProgressTaskUpdater?, - private val mLoadDatabaseResult: ((Result) -> Unit)?) - : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { + private val mLoadDatabaseResult: ((Result) -> Unit)? +) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { override fun onStartRun() { database.wasReloaded = true @@ -65,7 +64,7 @@ class MergeDatabaseRunnable( if (result.isSuccess) { // Register the current time to init the lock timer - DatabasePreferencesUtil.saveCurrentTime(context) + PreferencesUtil.saveCurrentTime(context) } super.onActionRun() } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/ReloadDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/ReloadDatabaseRunnable.kt similarity index 92% rename from database/src/main/java/com/kunzisoft/keepass/database/action/ReloadDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/ReloadDatabaseRunnable.kt index 6203a5aec..de8da32af 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/ReloadDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/ReloadDatabaseRunnable.kt @@ -23,7 +23,7 @@ import android.content.Context import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.binary.BinaryData import com.kunzisoft.keepass.database.exception.DatabaseException -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil +import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.tasks.ProgressTaskUpdater import com.kunzisoft.keepass.utils.UriUtilDatabase @@ -32,7 +32,7 @@ class ReloadDatabaseRunnable( private val context: Context, private val mDatabase: Database, private val progressTaskUpdater: ProgressTaskUpdater?, - private val mLoadDatabaseResult: ((Result) -> Unit)?, + private val mLoadDatabaseResult: ((Result) -> Unit)? ) : ActionRunnable() { override fun onStartRun() { @@ -55,7 +55,7 @@ class ReloadDatabaseRunnable( if (result.isSuccess) { // Register the current time to init the lock timer - DatabasePreferencesUtil.saveCurrentTime(context) + PreferencesUtil.saveCurrentTime(context) } else { mDatabase.clearAndClose(context) } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/RemoveUnlinkedDataDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/RemoveUnlinkedDataDatabaseRunnable.kt similarity index 92% rename from database/src/main/java/com/kunzisoft/keepass/database/action/RemoveUnlinkedDataDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/RemoveUnlinkedDataDatabaseRunnable.kt index 3cc5bdb43..ae35e61aa 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/RemoveUnlinkedDataDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/RemoveUnlinkedDataDatabaseRunnable.kt @@ -27,8 +27,8 @@ class RemoveUnlinkedDataDatabaseRunnable ( context: Context, database: Database, saveDatabase: Boolean, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { override fun onActionRun() { try { diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/SaveDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDatabaseRunnable.kt similarity index 78% rename from database/src/main/java/com/kunzisoft/keepass/database/action/SaveDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/SaveDatabaseRunnable.kt index c6ae0264a..c5496881b 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/SaveDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDatabaseRunnable.kt @@ -22,18 +22,19 @@ package com.kunzisoft.keepass.database.action import android.content.Context import android.net.Uri import com.kunzisoft.keepass.database.element.Database +import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.exception.DatabaseException import com.kunzisoft.keepass.hardware.HardwareKey -import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.tasks.ActionRunnable -open class SaveDatabaseRunnable(protected var context: Context, - protected var database: Database, - private var saveDatabase: Boolean, - private var mainCredential: MainCredential?, // If null, uses composite Key - private var challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, - private var databaseCopyUri: Uri? = null) - : ActionRunnable() { +open class SaveDatabaseRunnable( + protected var context: Context, + protected var database: Database, + private var saveDatabase: Boolean, + private var mainCredential: MainCredential?, // If null, uses composite Key + private var challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, + private var databaseCopyUri: Uri? = null +) : ActionRunnable() { var mAfterSaveDatabase: ((Result) -> Unit)? = null diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/UpdateCompressionBinariesDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateCompressionBinariesDatabaseRunnable.kt similarity index 95% rename from database/src/main/java/com/kunzisoft/keepass/database/action/UpdateCompressionBinariesDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/UpdateCompressionBinariesDatabaseRunnable.kt index 0c36983d7..9de1bad5d 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/UpdateCompressionBinariesDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateCompressionBinariesDatabaseRunnable.kt @@ -30,8 +30,8 @@ class UpdateCompressionBinariesDatabaseRunnable ( private val oldCompressionAlgorithm: CompressionAlgorithm, private val newCompressionAlgorithm: CompressionAlgorithm, saveDatabase: Boolean, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { override fun onStartRun() { // Set new compression diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/history/DeleteEntryHistoryDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/history/DeleteEntryHistoryDatabaseRunnable.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/database/action/history/DeleteEntryHistoryDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/history/DeleteEntryHistoryDatabaseRunnable.kt diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/history/RestoreEntryHistoryDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/history/RestoreEntryHistoryDatabaseRunnable.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/database/action/history/RestoreEntryHistoryDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/history/RestoreEntryHistoryDatabaseRunnable.kt diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/ActionNodeDatabaseRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/ActionNodeDatabaseRunnable.kt similarity index 83% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/ActionNodeDatabaseRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/ActionNodeDatabaseRunnable.kt index 717c62b6e..08aee425c 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/ActionNodeDatabaseRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/ActionNodeDatabaseRunnable.kt @@ -25,12 +25,12 @@ import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.hardware.HardwareKey abstract class ActionNodeDatabaseRunnable( - context: Context, - database: Database, - private val afterActionNodesFinish: AfterActionNodesFinish?, - save: Boolean, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : SaveDatabaseRunnable(context, database, save, null, challengeResponseRetriever) { + context: Context, + database: Database, + private val afterActionNodesFinish: AfterActionNodesFinish?, + save: Boolean, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : SaveDatabaseRunnable(context, database, save, null, challengeResponseRetriever) { /** * Function do to a node action diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/AddEntryRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/AddEntryRunnable.kt similarity index 81% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/AddEntryRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/AddEntryRunnable.kt index 1178051cc..2ca5e2f22 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/AddEntryRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/AddEntryRunnable.kt @@ -27,14 +27,14 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.hardware.HardwareKey class AddEntryRunnable constructor( - context: Context, - database: Database, - private val mNewEntry: Entry, - private val mParent: Group, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish?, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { + context: Context, + database: Database, + private val mNewEntry: Entry, + private val mParent: Group, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish?, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { override fun nodeAction() { mNewEntry.touch(modified = true, touchParents = true) diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/AddGroupRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/AddGroupRunnable.kt similarity index 80% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/AddGroupRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/AddGroupRunnable.kt index 12607f9eb..5ebdfe2fd 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/AddGroupRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/AddGroupRunnable.kt @@ -26,14 +26,14 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.hardware.HardwareKey class AddGroupRunnable constructor( - context: Context, - database: Database, - private val mNewGroup: Group, - private val mParent: Group, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish?, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { + context: Context, + database: Database, + private val mNewGroup: Group, + private val mParent: Group, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish?, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { override fun nodeAction() { mNewGroup.touch(modified = true, touchParents = true) diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/AfterActionNodesFinish.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/AfterActionNodesFinish.kt similarity index 100% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/AfterActionNodesFinish.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/AfterActionNodesFinish.kt diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/CopyNodesRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/CopyNodesRunnable.kt similarity index 88% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/CopyNodesRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/CopyNodesRunnable.kt index 792643a67..8053c7d59 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/CopyNodesRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/CopyNodesRunnable.kt @@ -31,14 +31,14 @@ import com.kunzisoft.keepass.database.exception.CopyGroupDatabaseException import com.kunzisoft.keepass.hardware.HardwareKey class CopyNodesRunnable constructor( - context: Context, - database: Database, - private val mNodesToCopy: List, - private val mNewParent: Group, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish?, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { + context: Context, + database: Database, + private val mNodesToCopy: List, + private val mNewParent: Group, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish?, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { private var mEntriesCopied = ArrayList() diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/DeleteNodesRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/DeleteNodesRunnable.kt similarity index 89% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/DeleteNodesRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/DeleteNodesRunnable.kt index dd5d126e5..e6b0a97f1 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/DeleteNodesRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/DeleteNodesRunnable.kt @@ -27,14 +27,15 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.hardware.HardwareKey -class DeleteNodesRunnable(context: Context, - database: Database, - private val mNodesToDelete: List, - private val recyclerBinTitle: String, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { +class DeleteNodesRunnable( + context: Context, + database: Database, + private val mNodesToDelete: List, + private val recyclerBinTitle: String, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { private var mOldParent: Group? = null private var mCanRecycle: Boolean = false diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/MoveNodesRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/MoveNodesRunnable.kt similarity index 91% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/MoveNodesRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/MoveNodesRunnable.kt index 2e2991e15..ae615bc0b 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/MoveNodesRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/MoveNodesRunnable.kt @@ -31,14 +31,14 @@ import com.kunzisoft.keepass.database.exception.MoveGroupDatabaseException import com.kunzisoft.keepass.hardware.HardwareKey class MoveNodesRunnable constructor( - context: Context, - database: Database, - private val mNodesToMove: List, - private val mNewParent: Group, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish?, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { + context: Context, + database: Database, + private val mNodesToMove: List, + private val mNewParent: Group, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish?, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { private var mOldParent: Group? = null diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateEntryRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateEntryRunnable.kt similarity index 88% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateEntryRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateEntryRunnable.kt index 41f7bafe4..c81d8f7fa 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateEntryRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateEntryRunnable.kt @@ -27,14 +27,14 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.hardware.HardwareKey class UpdateEntryRunnable constructor( - context: Context, - database: Database, - private val mOldEntry: Entry, - private val mNewEntry: Entry, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish?, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { + context: Context, + database: Database, + private val mOldEntry: Entry, + private val mNewEntry: Entry, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish?, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { override fun nodeAction() { if (mOldEntry.nodeId == mNewEntry.nodeId) { diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateGroupRunnable.kt b/app/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateGroupRunnable.kt similarity index 84% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateGroupRunnable.kt rename to app/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateGroupRunnable.kt index 53de6a6aa..f6b134e5f 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateGroupRunnable.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/node/UpdateGroupRunnable.kt @@ -26,14 +26,14 @@ import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.hardware.HardwareKey class UpdateGroupRunnable constructor( - context: Context, - database: Database, - private val mOldGroup: Group, - private val mNewGroup: Group, - save: Boolean, - afterActionNodesFinish: AfterActionNodesFinish?, - challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) - : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { + context: Context, + database: Database, + private val mOldGroup: Group, + private val mNewGroup: Group, + save: Boolean, + afterActionNodesFinish: AfterActionNodesFinish?, + challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray +) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { override fun nodeAction() { if (mOldGroup.nodeId == mNewGroup.nodeId) { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/database/NamedCompressionAlgorithm.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/database/NamedCompressionAlgorithm.kt deleted file mode 100644 index 2370e8142..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/database/NamedCompressionAlgorithm.kt +++ /dev/null @@ -1,74 +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.database.element.database - -import android.content.res.Resources -import android.os.Parcel -import android.os.Parcelable -import com.kunzisoft.keepass.R -import com.kunzisoft.keepass.utils.ObjectNameResource -import com.kunzisoft.keepass.utils.readEnum -import com.kunzisoft.keepass.utils.writeEnum - - -// Note: We can get away with using int's to store unsigned 32-bit ints -// since we won't do arithmetic on these values (also unlikely to -// reach negative ids). -enum class NamedCompressionAlgorithm : ObjectNameResource, Parcelable { - - None, - GZip; - - override fun writeToParcel(dest: Parcel, flags: Int) { - dest.writeEnum(this) - } - - override fun describeContents(): Int { - return 0 - } - - override fun getName(resources: Resources): String { - return when (this) { - None -> resources.getString(R.string.compression_none) - GZip -> resources.getString(R.string.compression_gzip) - } - } - - companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(parcel: Parcel): NamedCompressionAlgorithm { - return parcel.readEnum() ?: None - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - } -} - -fun CompressionAlgorithm.toNamedCompressionAlgorithm() = when(this) { - CompressionAlgorithm.None -> NamedCompressionAlgorithm.None - CompressionAlgorithm.GZip -> NamedCompressionAlgorithm.GZip -} - - -fun NamedCompressionAlgorithm.toCompressionAlgorithm() = when(this) { - NamedCompressionAlgorithm.None -> CompressionAlgorithm.None - NamedCompressionAlgorithm.GZip -> CompressionAlgorithm.GZip -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/exception/LocalizedDatabaseException.kt b/app/src/main/java/com/kunzisoft/keepass/database/exception/LocalizedDatabaseException.kt deleted file mode 100644 index fb53782d3..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/exception/LocalizedDatabaseException.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2021 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.database.exception - -import android.content.res.Resources -import com.kunzisoft.keepass.R - -fun DatabaseException.getLocalizedMessage(resources: Resources): String = parameters?.let { - when (this) { - is FileNotFoundDatabaseException -> resources.getString(R.string.file_not_found_content) - is CorruptedDatabaseException -> resources.getString(R.string.corrupted_file) - is InvalidAlgorithmDatabaseException -> resources.getString(R.string.invalid_algorithm) - is UnknownDatabaseLocationException -> resources.getString(R.string.error_location_unknown) - is HardwareKeyDatabaseException -> resources.getString(R.string.error_hardware_key_unsupported) - is EmptyKeyDatabaseException -> resources.getString(R.string.error_empty_key) - is SignatureDatabaseException -> resources.getString(R.string.invalid_db_sig) - is VersionDatabaseException -> resources.getString(R.string.unsupported_db_version) - is InvalidCredentialsDatabaseException -> resources.getString(R.string.invalid_credentials) - is KDFMemoryDatabaseException -> resources.getString(R.string.error_load_database_KDF_memory) - is NoMemoryDatabaseException -> resources.getString(R.string.error_out_of_memory) - is DuplicateUuidDatabaseException -> resources.getString(R.string.invalid_db_same_uuid) - is XMLMalformedDatabaseException -> resources.getString(R.string.error_XML_malformed) - is MergeDatabaseKDBException -> resources.getString(R.string.error_unable_merge_database_kdb) - is MoveEntryDatabaseException -> resources.getString(R.string.error_move_entry_here) - is MoveGroupDatabaseException -> resources.getString(R.string.error_move_group_here) - is CopyEntryDatabaseException -> resources.getString(R.string.error_copy_entry_here) - is CopyGroupDatabaseException -> resources.getString(R.string.error_copy_group_here) - is DatabaseInputException -> resources.getString(R.string.error_load_database) - is DatabaseOutputException -> resources.getString(R.string.error_save_database) - else -> (mThrowable as? DatabaseException)?.getLocalizedMessage(resources) - } -} ?: resources.getString(R.string.error_load_database) - diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateFieldKt.kt b/app/src/main/java/com/kunzisoft/keepass/database/helper/LocalizedHelper.kt similarity index 58% rename from app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateFieldKt.kt rename to app/src/main/java/com/kunzisoft/keepass/database/helper/LocalizedHelper.kt index f915c2fea..9b5c0c00b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/template/TemplateFieldKt.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/helper/LocalizedHelper.kt @@ -16,11 +16,48 @@ * You should have received a copy of the GNU General Public License * along with KeePassDX. If not, see . */ -package com.kunzisoft.keepass.database.element.template +package com.kunzisoft.keepass.database.helper import android.content.Context +import android.content.res.Resources import com.kunzisoft.keepass.R +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm +import com.kunzisoft.keepass.database.element.template.TemplateEngine +import com.kunzisoft.keepass.database.element.template.TemplateField +import com.kunzisoft.keepass.database.exception.* +fun DatabaseException.getLocalizedMessage(resources: Resources): String = parameters?.let { + when (this) { + is FileNotFoundDatabaseException -> resources.getString(R.string.file_not_found_content) + is CorruptedDatabaseException -> resources.getString(R.string.corrupted_file) + is InvalidAlgorithmDatabaseException -> resources.getString(R.string.invalid_algorithm) + is UnknownDatabaseLocationException -> resources.getString(R.string.error_location_unknown) + is HardwareKeyDatabaseException -> resources.getString(R.string.error_hardware_key_unsupported) + is EmptyKeyDatabaseException -> resources.getString(R.string.error_empty_key) + is SignatureDatabaseException -> resources.getString(R.string.invalid_db_sig) + is VersionDatabaseException -> resources.getString(R.string.unsupported_db_version) + is InvalidCredentialsDatabaseException -> resources.getString(R.string.invalid_credentials) + is KDFMemoryDatabaseException -> resources.getString(R.string.error_load_database_KDF_memory) + is NoMemoryDatabaseException -> resources.getString(R.string.error_out_of_memory) + is DuplicateUuidDatabaseException -> resources.getString(R.string.invalid_db_same_uuid) + is XMLMalformedDatabaseException -> resources.getString(R.string.error_XML_malformed) + is MergeDatabaseKDBException -> resources.getString(R.string.error_unable_merge_database_kdb) + is MoveEntryDatabaseException -> resources.getString(R.string.error_move_entry_here) + is MoveGroupDatabaseException -> resources.getString(R.string.error_move_group_here) + is CopyEntryDatabaseException -> resources.getString(R.string.error_copy_entry_here) + is CopyGroupDatabaseException -> resources.getString(R.string.error_copy_group_here) + is DatabaseInputException -> resources.getString(R.string.error_load_database) + is DatabaseOutputException -> resources.getString(R.string.error_save_database) + else -> (mThrowable as? DatabaseException)?.getLocalizedMessage(resources) + } +} ?: resources.getString(R.string.error_load_database) + +fun CompressionAlgorithm.getLocalizedName(resources: Resources): String { + return when (this) { + CompressionAlgorithm.NONE -> resources.getString(R.string.compression_none) + CompressionAlgorithm.GZIP -> resources.getString(R.string.compression_gzip) + } +} fun TemplateField.isStandardPasswordName(context: Context, name: String): Boolean { return name.equals(LABEL_PASSWORD, true) @@ -29,7 +66,8 @@ fun TemplateField.isStandardPasswordName(context: Context, name: String): Boolea fun TemplateField.getLocalizedName(context: Context?, name: String): String { if (context == null - || TemplateEngine.containsTemplateDecorator(name)) + || TemplateEngine.containsTemplateDecorator(name) + ) return name return when { @@ -73,3 +111,5 @@ fun TemplateField.getLocalizedName(context: Context?, name: String): String { else -> name } } + + diff --git a/app/src/main/java/com/kunzisoft/keepass/database/helper/SearchHelper.kt b/app/src/main/java/com/kunzisoft/keepass/database/helper/SearchHelper.kt new file mode 100644 index 000000000..cf7b963c0 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/helper/SearchHelper.kt @@ -0,0 +1,77 @@ +/* + * 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.database.helper + +import android.content.Context +import com.kunzisoft.keepass.database.element.Database +import com.kunzisoft.keepass.model.EntryInfo +import com.kunzisoft.keepass.model.SearchInfo +import com.kunzisoft.keepass.timeout.TimeoutHelper + +object SearchHelper { + + const val MAX_SEARCH_ENTRY = 1000 + + /** + * Method to show the number of search results with max results + */ + fun showNumberOfSearchResults(number: Int): String { + return if (number >= MAX_SEARCH_ENTRY) { + (MAX_SEARCH_ENTRY -1).toString() + "+" + } else { + number.toString() + } + } + + /** + * Utility method to perform actions if item is found or not after an auto search in [database] + */ + fun checkAutoSearchInfo(context: Context, + database: Database?, + searchInfo: SearchInfo?, + onItemsFound: (openedDatabase: Database, + items: List) -> Unit, + onItemNotFound: (openedDatabase: Database) -> Unit, + onDatabaseClosed: () -> Unit) { + if (database == null || !database.loaded) { + onDatabaseClosed.invoke() + } else if (TimeoutHelper.checkTime(context)) { + var searchWithoutUI = false + if (searchInfo != null + && !searchInfo.manualSelection + && !searchInfo.containsOnlyNullValues()) { + // If search provide results + database.createVirtualGroupFromSearchInfo( + searchInfo.toString(), + MAX_SEARCH_ENTRY + )?.let { searchGroup -> + if (searchGroup.numberOfChildEntries > 0) { + searchWithoutUI = true + onItemsFound.invoke(database, + searchGroup.getChildEntriesInfo(database)) + } + } + } + if (!searchWithoutUI) { + onItemNotFound.invoke(database) + } + } + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/icons/IconPackChooser.kt b/app/src/main/java/com/kunzisoft/keepass/icons/IconPackChooser.kt index 7f7b5eef3..ee0521575 100644 --- a/app/src/main/java/com/kunzisoft/keepass/icons/IconPackChooser.kt +++ b/app/src/main/java/com/kunzisoft/keepass/icons/IconPackChooser.kt @@ -23,8 +23,7 @@ import android.content.Context import android.util.Log import com.kunzisoft.keepass.BuildConfig import com.kunzisoft.keepass.R -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil -import java.util.ArrayList +import com.kunzisoft.keepass.settings.PreferencesUtil /** * Utility class to built and select an IconPack dynamically by libraries importation @@ -114,7 +113,7 @@ object IconPackChooser : InterfaceIconPackChooser { override fun getSelectedIconPack(context: Context): IconPack? { build(context) if (iconPackSelected == null) { - setSelectedIconPack(DatabasePreferencesUtil.getIconPackSelectedId(context)) + setSelectedIconPack(PreferencesUtil.getIconPackSelectedId(context)) } return iconPackSelected } diff --git a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt index f50d6ef69..2cdbd3559 100644 --- a/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/magikeyboard/MagikeyboardService.kt @@ -47,7 +47,7 @@ import com.kunzisoft.keepass.database.action.DatabaseTaskProvider import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Field import com.kunzisoft.keepass.database.element.node.NodeIdUUID -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD diff --git a/app/src/main/java/com/kunzisoft/keepass/password/PasswordEntropy.kt b/app/src/main/java/com/kunzisoft/keepass/password/PasswordEntropy.kt index bccfbe24f..912808019 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordEntropy.kt +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordEntropy.kt @@ -22,7 +22,7 @@ package com.kunzisoft.keepass.password import android.content.res.Resources import android.graphics.Color import com.kunzisoft.keepass.R -import com.kunzisoft.keepass.app.database.IOActionTask +import com.kunzisoft.keepass.utils.IOActionTask import kotlinx.coroutines.* import me.gosimple.nbvcxz.Nbvcxz import me.gosimple.nbvcxz.resources.Configuration diff --git a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt index 0e0651f12..64651999a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/services/DatabaseTaskNotificationService.kt @@ -39,8 +39,7 @@ import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Group import com.kunzisoft.keepass.database.element.MainCredential -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm -import com.kunzisoft.keepass.database.element.database.toCompressionAlgorithm +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.Type @@ -78,9 +77,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress private var mDatabaseInfoListeners = mutableListOf() private var mActionTaskBinder = ActionTaskBinder() private var mActionTaskListeners = mutableListOf() - - // Channel to connect asynchronously a listener or a response - private var mRequestChallengeListenerChannel: Channel? = null + // Channel to connect asynchronously a response private var mResponseChallengeChannel: Channel? = null private var mActionRunning = 0 @@ -829,7 +826,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress && intent.hasExtra(MAIN_CREDENTIAL_KEY) ) { val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null - AssignMainCredentialInDatabaseRunnable(this, + com.kunzisoft.keepass.database.action.AssignMainCredentialInDatabaseRunnable( + this, database, databaseUri, intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential() @@ -1116,8 +1114,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress && intent.hasExtra(SAVE_DATABASE_KEY) ) { - val oldElement: NamedCompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY) - val newElement: NamedCompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY) + val oldElement: CompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY) + val newElement: CompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY) if (oldElement == null || newElement == null @@ -1126,8 +1124,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress return UpdateCompressionBinariesDatabaseRunnable(this, database, - oldElement.toCompressionAlgorithm(), - newElement.toCompressionAlgorithm(), + oldElement, + newElement, !database.isReadOnly && intent.getBooleanExtra(SAVE_DATABASE_KEY, false) ) { hardwareKey, seed -> retrieveResponseFromChallenge(hardwareKey, seed) diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/NestedDatabaseSettingsFragment.kt b/app/src/main/java/com/kunzisoft/keepass/settings/NestedDatabaseSettingsFragment.kt index d8186b168..a45d37cad 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/NestedDatabaseSettingsFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/NestedDatabaseSettingsFragment.kt @@ -37,10 +37,8 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Group -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm -import com.kunzisoft.keepass.database.element.database.toCompressionAlgorithm -import com.kunzisoft.keepass.database.element.database.toNamedCompressionAlgorithm -import com.kunzisoft.keepass.database.element.template.TemplateEngine +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm +import com.kunzisoft.keepass.database.helper.* import com.kunzisoft.keepass.services.DatabaseTaskNotificationService import com.kunzisoft.keepass.settings.preference.* import com.kunzisoft.keepass.settings.preferencedialogfragment.* @@ -200,8 +198,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev // Database compression dbDataCompressionPref = findPreference(getString(R.string.database_data_compression_key)) if (database.allowDataCompression) { - dbDataCompressionPref?.summary = (database.compressionAlgorithm?.toNamedCompressionAlgorithm() - ?: NamedCompressionAlgorithm.None).getName(resources) + dbDataCompressionPref?.summary = (database.compressionAlgorithm + ?: CompressionAlgorithm.NONE).getLocalizedName(resources) } else { dbCompressionPrefCategory?.isVisible = false } @@ -435,16 +433,16 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev dbCustomColorPref?.summary = defaultColorToShow } DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> { - val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as NamedCompressionAlgorithm - val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as NamedCompressionAlgorithm + val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as CompressionAlgorithm + val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as CompressionAlgorithm val algorithmToShow = if (result.isSuccess) { newCompression } else { - mDatabase?.compressionAlgorithm = oldCompression.toCompressionAlgorithm() + mDatabase?.compressionAlgorithm = oldCompression oldCompression } - dbDataCompressionPref?.summary = algorithmToShow.getName(resources) + dbDataCompressionPref?.summary = algorithmToShow.getLocalizedName(resources) } DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_RECYCLE_BIN_TASK -> { val oldRecycleBin = data.getParcelable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt index a5c80a4d3..211b81b1d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt @@ -35,15 +35,9 @@ import com.kunzisoft.keepass.database.search.SearchParameters import com.kunzisoft.keepass.education.Education import com.kunzisoft.keepass.magikeyboard.MagikeyboardService import com.kunzisoft.keepass.password.PassphraseGenerator -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil.APP_TIMEOUT_KEY -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil.HIDE_EXPIRED_ENTRIES_KEY -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil.SETTING_ICON_PACK_CHOOSE_KEY -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil.SUBDOMAIN_SEARCH_KEY -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil.TIMEOUT_BACKUP_KEY -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil.TIMEOUT_DEFAULT import com.kunzisoft.keepass.timeout.TimeoutHelper import com.kunzisoft.keepass.utils.UriUtil -import java.util.Properties +import java.util.* object PreferencesUtil { @@ -67,8 +61,7 @@ object PreferencesUtil { fun saveNodeSort(context: Context, sortNodeEnum: SortNodeEnum, - sortNodeParameters: SortNodeEnum.SortNodeParameters - ) { + sortNodeParameters: SortNodeEnum.SortNodeParameters) { val prefs = PreferenceManager.getDefaultSharedPreferences(context) prefs?.edit()?.apply { putString(context.getString(R.string.sort_node_key), sortNodeEnum.name) @@ -82,25 +75,25 @@ object PreferencesUtil { fun rememberDatabaseLocations(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.remember_database_locations_key), - context.resources.getBoolean(R.bool.remember_database_locations_default)) + context.resources.getBoolean(R.bool.remember_database_locations_default)) } fun showRecentFiles(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.show_recent_files_key), - context.resources.getBoolean(R.bool.show_recent_files_default)) + context.resources.getBoolean(R.bool.show_recent_files_default)) } fun hideBrokenLocations(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.hide_broken_locations_key), - context.resources.getBoolean(R.bool.hide_broken_locations_default)) + context.resources.getBoolean(R.bool.hide_broken_locations_default)) } fun rememberKeyFileLocations(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.remember_keyfile_locations_key), - context.resources.getBoolean(R.bool.remember_keyfile_locations_default)) + context.resources.getBoolean(R.bool.remember_keyfile_locations_default)) } fun rememberHardwareKey(context: Context): Boolean { @@ -112,7 +105,13 @@ object PreferencesUtil { fun automaticallyFocusSearch(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.auto_focus_search_key), - context.resources.getBoolean(R.bool.auto_focus_search_default)) + context.resources.getBoolean(R.bool.auto_focus_search_default)) + } + + fun searchSubdomains(context: Context): Boolean { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return prefs.getBoolean(context.getString(R.string.subdomain_search_key), + context.resources.getBoolean(R.bool.subdomain_search_default)) } fun showEntryColors(context: Context): Boolean { @@ -136,13 +135,13 @@ object PreferencesUtil { fun showUsernamesListEntries(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.list_entries_show_username_key), - context.resources.getBoolean(R.bool.list_entries_show_username_default)) + context.resources.getBoolean(R.bool.list_entries_show_username_default)) } fun showNumberEntries(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.list_groups_show_number_entries_key), - context.resources.getBoolean(R.bool.list_groups_show_number_entries_default)) + context.resources.getBoolean(R.bool.list_groups_show_number_entries_default)) } fun showOTPToken(context: Context): Boolean { @@ -157,11 +156,17 @@ object PreferencesUtil { context.resources.getBoolean(R.bool.show_uuid_default)) } + fun showExpiredEntries(context: Context): Boolean { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return ! prefs.getBoolean(context.getString(R.string.hide_expired_entries_key), + context.resources.getBoolean(R.bool.hide_expired_entries_default)) + } + fun getStyle(context: Context): String { val defaultStyleString = Stylish.defaultStyle(context) val styleString = PreferenceManager.getDefaultSharedPreferences(context) - .getString(context.getString(R.string.setting_style_key), defaultStyleString) - ?: defaultStyleString + .getString(context.getString(R.string.setting_style_key), defaultStyleString) + ?: defaultStyleString // Return the system style return Stylish.retrieveEquivalentSystemStyle(context, styleString) } @@ -176,16 +181,16 @@ object PreferencesUtil { // Store light style to show selection in array list tempThemeString = Stylish.retrieveEquivalentLightStyle(context, tempThemeString) PreferenceManager.getDefaultSharedPreferences(context) - .edit() - .putString(context.getString(R.string.setting_style_key), tempThemeString) - .apply() + .edit() + .putString(context.getString(R.string.setting_style_key), tempThemeString) + .apply() Stylish.load(context) } fun getStyleBrightness(context: Context): String? { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getString(context.getString(R.string.setting_style_brightness_key), - context.getString(R.string.list_style_brightness_follow_system)) + context.getString(R.string.list_style_brightness_follow_system)) } /** @@ -194,7 +199,8 @@ object PreferencesUtil { fun getListTextSize(context: Context): Float { val index = try { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - val listSizeString = prefs.getString(context.getString(R.string.list_size_key), context.getString(R.string.list_size_string_medium)) + val listSizeString = prefs.getString(context.getString(R.string.list_size_key), + context.getString(R.string.list_size_string_medium)) context.resources.getStringArray(R.array.list_size_string_values).indexOf(listSizeString) } catch (e: Exception) { 1 @@ -207,7 +213,8 @@ object PreferencesUtil { fun getDefaultPasswordLength(context: Context): Int { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getInt(context.getString(R.string.password_generator_length_key), context.resources.getInteger(R.integer.password_generator_length_default)) + return prefs.getInt(context.getString(R.string.password_generator_length_key), + context.resources.getInteger(R.integer.password_generator_length_default)) } fun setDefaultPasswordLength(context: Context, passwordLength: Int) { @@ -239,7 +246,8 @@ object PreferencesUtil { fun getDefaultPasswordConsiderChars(context: Context): String { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString(context.getString(R.string.password_generator_consider_chars_key), context.getString(R.string.password_generator_consider_chars_default)) ?: "" + return prefs.getString(context.getString(R.string.password_generator_consider_chars_key), + context.getString(R.string.password_generator_consider_chars_default)) ?: "" } fun setDefaultPasswordConsiderChars(context: Context, considerChars: String) { @@ -254,7 +262,8 @@ object PreferencesUtil { fun getDefaultPasswordIgnoreChars(context: Context): String { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString(context.getString(R.string.password_generator_ignore_chars_key), context.getString(R.string.password_generator_ignore_chars_default)) ?: "" + return prefs.getString(context.getString(R.string.password_generator_ignore_chars_key), + context.getString(R.string.password_generator_ignore_chars_default)) ?: "" } fun setDefaultPasswordIgnoreChars(context: Context, ignoreChars: String) { @@ -269,7 +278,8 @@ object PreferencesUtil { fun getDefaultPassphraseWordCount(context: Context): Int { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getInt(context.getString(R.string.passphrase_generator_word_count_key), context.resources.getInteger(R.integer.passphrase_generator_word_count_default)) + return prefs.getInt(context.getString(R.string.passphrase_generator_word_count_key), + context.resources.getInteger(R.integer.passphrase_generator_word_count_default)) } fun setDefaultPassphraseWordCount(context: Context, passphraseWordCount: Int) { @@ -284,11 +294,11 @@ object PreferencesUtil { fun getDefaultPassphraseWordCase(context: Context): PassphraseGenerator.WordCase { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return PassphraseGenerator.WordCase.getByOrdinal( - prefs.getInt(context + return PassphraseGenerator.WordCase + .getByOrdinal(prefs.getInt(context .getString(R.string.passphrase_generator_word_case_key), 0) - ) + ) } fun setDefaultPassphraseWordCase(context: Context, wordCase: PassphraseGenerator.WordCase) { @@ -396,7 +406,7 @@ object PreferencesUtil { fun isClipboardNotificationsEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.clipboard_notifications_key), - context.resources.getBoolean(R.bool.clipboard_notifications_default)) + context.resources.getBoolean(R.bool.clipboard_notifications_default)) } /** @@ -404,44 +414,75 @@ object PreferencesUtil { */ fun saveCurrentTime(context: Context) { PreferenceManager.getDefaultSharedPreferences(context).edit().apply { - putLong(TIMEOUT_BACKUP_KEY, System.currentTimeMillis()) + putLong(context.getString(R.string.timeout_backup_key), System.currentTimeMillis()) apply() } } + /** + * Time previously saved in milliseconds (commonly used to compare with current time and check timeout) + */ + fun getTimeSaved(context: Context): Long { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return prefs.getLong(context.getString(R.string.timeout_backup_key), + TimeoutHelper.NEVER) + } + + /** + * App timeout selected in milliseconds + */ + fun getAppTimeout(context: Context): Long { + return try { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + (prefs.getString(context.getString(R.string.app_timeout_key), + context.getString(R.string.timeout_default)) ?: "300000").toLong() + } catch (e: NumberFormatException) { + TimeoutHelper.DEFAULT_TIMEOUT + } + } + fun getClipboardTimeout(context: Context): Long { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString(context.getString(R.string.clipboard_timeout_key), TIMEOUT_DEFAULT)?.toLong() ?: TimeoutHelper.DEFAULT_TIMEOUT + return prefs.getString(context.getString(R.string.clipboard_timeout_key), + context.getString(R.string.clipboard_timeout_default))?.toLong() + ?: TimeoutHelper.DEFAULT_TIMEOUT } fun getAdvancedUnlockTimeout(context: Context): Long { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString(context.getString(R.string.temp_advanced_unlock_timeout_key), context.getString(R.string.temp_advanced_unlock_timeout_default))?.toLong() ?: TimeoutHelper.DEFAULT_TIMEOUT + return prefs.getString(context.getString(R.string.temp_advanced_unlock_timeout_key), + context.getString(R.string.temp_advanced_unlock_timeout_default))?.toLong() + ?: TimeoutHelper.DEFAULT_TIMEOUT } fun isLockDatabaseWhenScreenShutOffEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getBoolean(context.getString(R.string.lock_database_screen_off_key), context.resources.getBoolean(R.bool.lock_database_screen_off_default)) + return prefs.getBoolean(context.getString(R.string.lock_database_screen_off_key), + context.resources.getBoolean(R.bool.lock_database_screen_off_default)) } fun isLockDatabaseWhenBackButtonOnRootClicked(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getBoolean(context.getString(R.string.lock_database_back_root_key), context.resources.getBoolean(R.bool.lock_database_back_root_default)) + return prefs.getBoolean(context.getString(R.string.lock_database_back_root_key), + context.resources.getBoolean(R.bool.lock_database_back_root_default)) } fun showLockDatabaseButton(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getBoolean(context.getString(R.string.lock_database_show_button_key), context.resources.getBoolean(R.bool.lock_database_show_button_default)) + return prefs.getBoolean(context.getString(R.string.lock_database_show_button_key), + context.resources.getBoolean(R.bool.lock_database_show_button_default)) } fun isAutoSaveDatabaseEnabled(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getBoolean(context.getString(R.string.enable_auto_save_database_key), context.resources.getBoolean(R.bool.enable_auto_save_database_default)) + return prefs.getBoolean(context.getString(R.string.enable_auto_save_database_key), + context.resources.getBoolean(R.bool.enable_auto_save_database_default)) } fun isKeepScreenOnEnabled(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getBoolean(context.getString(R.string.enable_keep_screen_on_key), context.resources.getBoolean(R.bool.enable_keep_screen_on_default)) + return prefs.getBoolean(context.getString(R.string.enable_keep_screen_on_key), + context.resources.getBoolean(R.bool.enable_keep_screen_on_default)) } fun isScreenshotModeEnabled(context: Context): Boolean { @@ -457,39 +498,39 @@ object PreferencesUtil { fun isBiometricUnlockEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.biometric_unlock_enable_key), - context.resources.getBoolean(R.bool.biometric_unlock_enable_default)) + context.resources.getBoolean(R.bool.biometric_unlock_enable_default)) && (if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { - AdvancedUnlockManager.biometricUnlockSupported(context) - } else { - false - }) + AdvancedUnlockManager.biometricUnlockSupported(context) + } else { + false + }) } fun isDeviceCredentialUnlockEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) // Priority to biometric unlock return prefs.getBoolean(context.getString(R.string.device_credential_unlock_enable_key), - context.resources.getBoolean(R.bool.device_credential_unlock_enable_default)) + context.resources.getBoolean(R.bool.device_credential_unlock_enable_default)) && !isBiometricUnlockEnable(context) } fun isTempAdvancedUnlockEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.temp_advanced_unlock_enable_key), - context.resources.getBoolean(R.bool.temp_advanced_unlock_enable_default)) + context.resources.getBoolean(R.bool.temp_advanced_unlock_enable_default)) } fun isAdvancedUnlockPromptAutoOpenEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.biometric_auto_open_prompt_key), - context.resources.getBoolean(R.bool.biometric_auto_open_prompt_default)) + context.resources.getBoolean(R.bool.biometric_auto_open_prompt_default)) } fun getListSort(context: Context): SortNodeEnum { try { val prefs = PreferenceManager.getDefaultSharedPreferences(context) prefs.getString(context.getString(R.string.sort_node_key), - SortNodeEnum.DB.name)?.let { + SortNodeEnum.DB.name)?.let { return SortNodeEnum.valueOf(it) } } catch (e: Exception) {} @@ -499,87 +540,94 @@ object PreferencesUtil { fun getGroupsBeforeSort(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.sort_group_before_key), - context.resources.getBoolean(R.bool.sort_group_before_default)) + context.resources.getBoolean(R.bool.sort_group_before_default)) } fun getAscendingSort(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.sort_ascending_key), - context.resources.getBoolean(R.bool.sort_ascending_default)) + context.resources.getBoolean(R.bool.sort_ascending_default)) } fun getRecycleBinBottomSort(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.sort_recycle_bin_bottom_key), - context.resources.getBoolean(R.bool.sort_recycle_bin_bottom_default)) + context.resources.getBoolean(R.bool.sort_recycle_bin_bottom_default)) } fun fieldFontIsInVisibility(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.monospace_font_fields_enable_key), - context.resources.getBoolean(R.bool.monospace_font_fields_enable_default)) + context.resources.getBoolean(R.bool.monospace_font_fields_enable_default)) } fun isFirstTimeAskAllowCopyProtectedFields(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.allow_copy_password_first_time_key), - context.resources.getBoolean(R.bool.allow_copy_password_first_time_default)) + context.resources.getBoolean(R.bool.allow_copy_password_first_time_default)) } fun allowCopyProtectedFields(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.allow_copy_password_key), - context.resources.getBoolean(R.bool.allow_copy_password_default)) + context.resources.getBoolean(R.bool.allow_copy_password_default)) } fun isClearClipboardNotificationEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.clear_clipboard_notification_key), - context.resources.getBoolean(R.bool.clear_clipboard_notification_default)) + context.resources.getBoolean(R.bool.clear_clipboard_notification_default)) } fun isClearKeyboardNotificationEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_notification_entry_clear_close_key), - context.resources.getBoolean(R.bool.keyboard_notification_entry_clear_close_default)) + context.resources.getBoolean(R.bool.keyboard_notification_entry_clear_close_default)) } fun setAllowCopyPasswordAndProtectedFields(context: Context, allowCopy: Boolean) { val prefs = PreferenceManager.getDefaultSharedPreferences(context) prefs.edit() - .putBoolean(context.getString(R.string.allow_copy_password_first_time_key), false) - .putBoolean(context.getString(R.string.allow_copy_password_key), allowCopy) - .apply() + .putBoolean(context.getString(R.string.allow_copy_password_first_time_key), false) + .putBoolean(context.getString(R.string.allow_copy_password_key), allowCopy) + .apply() + } + + fun getIconPackSelectedId(context: Context): String? { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return prefs.getString( + context.getString(R.string.setting_icon_pack_choose_key), + context.getString(R.string.setting_icon_pack_choose_default)) } fun emptyPasswordAllowed(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.allow_no_password_key), - context.resources.getBoolean(R.bool.allow_no_password_default)) + context.resources.getBoolean(R.bool.allow_no_password_default)) } fun enableReadOnlyDatabase(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.enable_read_only_key), - context.resources.getBoolean(R.bool.enable_read_only_default)) + context.resources.getBoolean(R.bool.enable_read_only_default)) } fun deletePasswordAfterConnexionAttempt(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.delete_entered_password_key), - context.resources.getBoolean(R.bool.delete_entered_password_default)) + context.resources.getBoolean(R.bool.delete_entered_password_default)) } fun isKeyboardNotificationEntryEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_notification_entry_key), - context.resources.getBoolean(R.bool.keyboard_notification_entry_default)) + context.resources.getBoolean(R.bool.keyboard_notification_entry_default)) } fun isKeyboardEntrySelectionEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_selection_entry_key), - context.resources.getBoolean(R.bool.keyboard_selection_entry_default)) + context.resources.getBoolean(R.bool.keyboard_selection_entry_default)) } fun isKeyboardSaveSearchInfoEnable(context: Context): Boolean { @@ -587,79 +635,79 @@ object PreferencesUtil { return false val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_save_search_info_key), - context.resources.getBoolean(R.bool.keyboard_save_search_info_default)) + context.resources.getBoolean(R.bool.keyboard_save_search_info_default)) } fun isAutoGoActionEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_auto_go_action_key), - context.resources.getBoolean(R.bool.keyboard_auto_go_action_default)) + context.resources.getBoolean(R.bool.keyboard_auto_go_action_default)) } fun isKeyboardVibrationEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_key_vibrate_key), - context.resources.getBoolean(R.bool.keyboard_key_vibrate_default)) + context.resources.getBoolean(R.bool.keyboard_key_vibrate_default)) } fun isKeyboardSoundEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_key_sound_key), - context.resources.getBoolean(R.bool.keyboard_key_sound_default)) + context.resources.getBoolean(R.bool.keyboard_key_sound_default)) } fun isKeyboardPreviousDatabaseCredentialsEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_previous_database_credentials_key), - context.resources.getBoolean(R.bool.keyboard_previous_database_credentials_default)) + context.resources.getBoolean(R.bool.keyboard_previous_database_credentials_default)) } fun isKeyboardPreviousSearchEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_previous_search_key), - context.resources.getBoolean(R.bool.keyboard_previous_search_default)) + context.resources.getBoolean(R.bool.keyboard_previous_search_default)) } fun isKeyboardPreviousFillInEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_previous_fill_in_key), - context.resources.getBoolean(R.bool.keyboard_previous_fill_in_default)) + context.resources.getBoolean(R.bool.keyboard_previous_fill_in_default)) } fun isKeyboardPreviousLockEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.keyboard_previous_lock_key), - context.resources.getBoolean(R.bool.keyboard_previous_lock_default)) + context.resources.getBoolean(R.bool.keyboard_previous_lock_default)) } fun isAutofillCloseDatabaseEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_close_database_key), - context.resources.getBoolean(R.bool.autofill_close_database_default)) + context.resources.getBoolean(R.bool.autofill_close_database_default)) } fun isAutofillInlineSuggestionsEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_inline_suggestions_key), - context.resources.getBoolean(R.bool.autofill_inline_suggestions_default)) + context.resources.getBoolean(R.bool.autofill_inline_suggestions_default)) } fun isAutofillManualSelectionEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_manual_selection_key), - context.resources.getBoolean(R.bool.autofill_manual_selection_default)) + context.resources.getBoolean(R.bool.autofill_manual_selection_default)) } fun isAutofillSaveSearchInfoEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_save_search_info_key), - context.resources.getBoolean(R.bool.autofill_save_search_info_default)) + context.resources.getBoolean(R.bool.autofill_save_search_info_default)) } fun askToSaveAutofillData(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_ask_to_save_data_key), - context.resources.getBoolean(R.bool.autofill_ask_to_save_data_default)) + context.resources.getBoolean(R.bool.autofill_ask_to_save_data_default)) } /** @@ -667,23 +715,23 @@ object PreferencesUtil { */ fun getDefaultApplicationIdBlocklist(resources: Resources?): Set { return resources?.getStringArray(R.array.autofill_application_id_blocklist_default) - ?.toMutableSet()?.apply { - add(BuildConfig.APPLICATION_ID) - } ?: emptySet() + ?.toMutableSet()?.apply { + add(BuildConfig.APPLICATION_ID) + } ?: emptySet() } fun applicationIdBlocklist(context: Context): Set { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getStringSet(context.getString(R.string.autofill_application_id_blocklist_key), - getDefaultApplicationIdBlocklist(context.resources)) - ?: emptySet() + getDefaultApplicationIdBlocklist(context.resources)) + ?: emptySet() } fun webDomainBlocklist(context: Context): Set { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getStringSet(context.getString(R.string.autofill_web_domain_blocklist_key), - context.resources.getStringArray(R.array.autofill_web_domain_blocklist_default).toMutableSet()) - ?: emptySet() + context.resources.getStringArray(R.array.autofill_web_domain_blocklist_default).toMutableSet()) + ?: emptySet() } fun addApplicationIdToBlocklist(context: Context, applicationId: String) { @@ -691,8 +739,8 @@ object PreferencesUtil { val setItems: MutableSet = applicationIdBlocklist(context).toMutableSet() setItems.add(applicationId) prefs.edit() - .putStringSet(context.getString(R.string.autofill_application_id_blocklist_key), setItems) - .apply() + .putStringSet(context.getString(R.string.autofill_application_id_blocklist_key), setItems) + .apply() } fun addWebDomainToBlocklist(context: Context, webDomain: String) { @@ -700,14 +748,13 @@ object PreferencesUtil { val setItems: MutableSet = webDomainBlocklist(context).toMutableSet() setItems.add(webDomain) prefs.edit() - .putStringSet(context.getString(R.string.autofill_web_domain_blocklist_key), setItems) - .apply() + .putStringSet(context.getString(R.string.autofill_web_domain_blocklist_key), setItems) + .apply() } fun getAppProperties(context: Context): Properties { val properties = Properties() - for ((name, value) in PreferenceManager.getDefaultSharedPreferences( - context).all) { + for ((name, value) in PreferenceManager.getDefaultSharedPreferences(context).all) { properties[name] = value.toString() } for ((name, value) in Education.getEducationSharedPreferences(context).all) { @@ -718,9 +765,9 @@ object PreferencesUtil { private fun getStringSetFromProperties(value: String): Set { return value.removePrefix("[") - .removeSuffix("]") - .split(", ") - .toSet() + .removeSuffix("]") + .split(", ") + .toSet() } private fun putPropertiesInPreferences(properties: Properties, @@ -732,7 +779,7 @@ object PreferencesUtil { for ((name, value) in properties) { try { putProperty(this, name as String, value as String) - } catch (e: Exception) { + } catch (e:Exception) { Log.e("PreferencesUtil", "Error when trying to parse app property $name=$value", e) } } @@ -749,8 +796,8 @@ object PreferencesUtil { context.getString(R.string.enable_auto_save_database_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.enable_keep_screen_on_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.auto_focus_search_key) -> editor.putBoolean(name, value.toBoolean()) - SUBDOMAIN_SEARCH_KEY -> editor.putBoolean(name, value.toBoolean()) - APP_TIMEOUT_KEY -> editor.putString(name, value.toLong().toString()) + context.getString(R.string.subdomain_search_key) -> editor.putBoolean(name, value.toBoolean()) + context.getString(R.string.app_timeout_key) -> editor.putString(name, value.toLong().toString()) context.getString(R.string.lock_database_screen_off_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.lock_database_back_root_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.lock_database_show_button_key) -> editor.putBoolean(name, value.toBoolean()) @@ -792,7 +839,7 @@ object PreferencesUtil { context.getString(R.string.setting_style_key) -> setStyle(context, value) context.getString(R.string.setting_style_brightness_key) -> editor.putString(name, value) - SETTING_ICON_PACK_CHOOSE_KEY -> editor.putString(name, value) + context.getString(R.string.setting_icon_pack_choose_key) -> editor.putString(name, value) context.getString(R.string.show_entry_colors_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.hide_password_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.colorize_password_key) -> editor.putBoolean(name, value.toBoolean()) @@ -802,7 +849,7 @@ object PreferencesUtil { context.getString(R.string.show_uuid_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.list_size_key) -> editor.putString(name, value) context.getString(R.string.monospace_font_fields_enable_key) -> editor.putBoolean(name, value.toBoolean()) - HIDE_EXPIRED_ENTRIES_KEY -> editor.putBoolean(name, value.toBoolean()) + context.getString(R.string.hide_expired_entries_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.enable_education_screens_key) -> editor.putBoolean(name, value.toBoolean()) context.getString(R.string.password_generator_length_key) -> editor.putInt(name, value.toInt()) @@ -822,13 +869,8 @@ object PreferencesUtil { } putPropertiesInPreferences(properties, - Education.getEducationSharedPreferences( - context)) { editor, name, value -> - Education.putPropertiesInEducationPreferences( - context, - editor, - name, - value) + Education.getEducationSharedPreferences(context)) { editor, name, value -> + Education.putPropertiesInEducationPreferences(context, editor, name, value) } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseDataCompressionPreferenceDialogFragmentCompat.kt b/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseDataCompressionPreferenceDialogFragmentCompat.kt index eebbfac46..878b95f37 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseDataCompressionPreferenceDialogFragmentCompat.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseDataCompressionPreferenceDialogFragmentCompat.kt @@ -25,18 +25,16 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.Database -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm -import com.kunzisoft.keepass.database.element.database.toCompressionAlgorithm -import com.kunzisoft.keepass.database.element.database.toNamedCompressionAlgorithm +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter class DatabaseDataCompressionPreferenceDialogFragmentCompat : DatabaseSavePreferenceDialogFragmentCompat(), - ListRadioItemAdapter.RadioItemSelectedCallback { + ListRadioItemAdapter.RadioItemSelectedCallback { private var mRecyclerView: RecyclerView? = null - private var mCompressionAdapter: ListRadioItemAdapter? = null - private var compressionSelected: NamedCompressionAlgorithm? = null + private var mCompressionAdapter: ListRadioItemAdapter? = null + private var compressionSelected: CompressionAlgorithm? = null override fun onBindDialogView(view: View) { super.onBindDialogView(view) @@ -47,7 +45,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat mRecyclerView?.layoutManager = LinearLayoutManager(context) activity?.let { activity -> - mCompressionAdapter = ListRadioItemAdapter(activity) + mCompressionAdapter = ListRadioItemAdapter(activity) mCompressionAdapter?.setRadioItemSelectedCallback(this) } } @@ -59,8 +57,8 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat mRecyclerView?.adapter = mCompressionAdapter database?.let { - compressionSelected = it.compressionAlgorithm?.toNamedCompressionAlgorithm() - mCompressionAdapter?.setItems(it.availableCompressionAlgorithms.map { it.toNamedCompressionAlgorithm() }, compressionSelected) + compressionSelected = it.compressionAlgorithm + mCompressionAdapter?.setItems(it.availableCompressionAlgorithms, compressionSelected) } } @@ -71,16 +69,16 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat if (compressionSelected != null) { val newCompression = compressionSelected val oldCompression = database.compressionAlgorithm - database.compressionAlgorithm = newCompression?.toCompressionAlgorithm() + database.compressionAlgorithm = newCompression if (oldCompression != null && newCompression != null) - saveCompression(oldCompression.toNamedCompressionAlgorithm(), newCompression) + saveCompression(oldCompression, newCompression) } } } } - override fun onItemSelected(item: NamedCompressionAlgorithm) { + override fun onItemSelected(item: CompressionAlgorithm) { this.compressionSelected = item } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseSavePreferenceDialogFragmentCompat.kt b/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseSavePreferenceDialogFragmentCompat.kt index ad48fdf14..1159cb5b4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseSavePreferenceDialogFragmentCompat.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferencedialogfragment/DatabaseSavePreferenceDialogFragmentCompat.kt @@ -28,7 +28,7 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Group -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.viewmodels.DatabaseViewModel @@ -90,8 +90,8 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat mDatabaseViewModel.saveColor(oldColorString, newColorString, mDatabaseAutoSaveEnable) } - protected fun saveCompression(oldCompression: NamedCompressionAlgorithm, - newCompression: NamedCompressionAlgorithm + protected fun saveCompression(oldCompression: CompressionAlgorithm, + newCompression: CompressionAlgorithm ) { mDatabaseViewModel.saveCompression(oldCompression, newCompression, mDatabaseAutoSaveEnable) } diff --git a/database/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt b/app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt similarity index 95% rename from database/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt rename to app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt index 7fd0b4fb5..2042e315a 100644 --- a/database/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/timeout/TimeoutHelper.kt @@ -25,7 +25,7 @@ import android.content.Context import android.content.Intent import android.os.Build import android.util.Log -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil +import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.utils.LOCK_ACTION object TimeoutHelper { @@ -59,7 +59,7 @@ object TimeoutHelper { */ private fun startLockTimer(context: Context, databaseLoaded: Boolean) { if (databaseLoaded) { - val timeout = DatabasePreferencesUtil.getAppTimeout(context) + val timeout = PreferencesUtil.getAppTimeout(context) if (timeout != NEVER) { // No timeout don't start timeout service (context.applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager?)?.let { alarmManager -> @@ -111,7 +111,7 @@ object TimeoutHelper { || lastAppTimeoutRecord!! + 2000 <= System.currentTimeMillis()) { Log.d(TAG, "Record app timeout") // Record timeout time in case timeout service is killed - DatabasePreferencesUtil.saveCurrentTime(context) + PreferencesUtil.saveCurrentTime(context) startLockTimer(context, databaseLoaded) lastAppTimeoutRecord = System.currentTimeMillis() } @@ -131,14 +131,14 @@ object TimeoutHelper { val currentTime = System.currentTimeMillis() // Retrieve the timeout programmatically backup - val timeoutBackup = DatabasePreferencesUtil.getTimeSaved(context) + val timeoutBackup = PreferencesUtil.getTimeSaved(context) // The timeout never started if (timeoutBackup == NEVER) { return true } // Retrieve the app timeout in settings - val appTimeout = DatabasePreferencesUtil.getAppTimeout((context)) + val appTimeout = PreferencesUtil.getAppTimeout((context)) // We are set to never timeout if (appTimeout == NEVER) { return true diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt b/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt index c68eeaf1e..9a0a24ca5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt +++ b/app/src/main/java/com/kunzisoft/keepass/utils/BroadcastAction.kt @@ -40,6 +40,7 @@ import com.kunzisoft.keepass.timeout.TimeoutHelper const val DATABASE_START_TASK_ACTION = "com.kunzisoft.keepass.DATABASE_START_TASK_ACTION" const val DATABASE_STOP_TASK_ACTION = "com.kunzisoft.keepass.DATABASE_STOP_TASK_ACTION" +const val LOCK_ACTION = "com.kunzisoft.keepass.LOCK" const val REMOVE_ENTRY_MAGIKEYBOARD_ACTION = "com.kunzisoft.keepass.REMOVE_ENTRY_MAGIKEYBOARD" const val BACK_PREVIOUS_KEYBOARD_ACTION = "com.kunzisoft.keepass.BACK_PREVIOUS_KEYBOARD" diff --git a/database/src/main/java/com/kunzisoft/keepass/app/database/IOActionTask.kt b/app/src/main/java/com/kunzisoft/keepass/utils/IOActionTask.kt similarity index 97% rename from database/src/main/java/com/kunzisoft/keepass/app/database/IOActionTask.kt rename to app/src/main/java/com/kunzisoft/keepass/utils/IOActionTask.kt index d77a7942b..5d4ff9e41 100644 --- a/database/src/main/java/com/kunzisoft/keepass/app/database/IOActionTask.kt +++ b/app/src/main/java/com/kunzisoft/keepass/utils/IOActionTask.kt @@ -17,7 +17,7 @@ * along with KeePassDX. If not, see . * */ -package com.kunzisoft.keepass.app.database +package com.kunzisoft.keepass.utils import kotlinx.coroutines.* diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/WebDomain.kt b/app/src/main/java/com/kunzisoft/keepass/utils/WebDomain.kt new file mode 100644 index 000000000..429405ee0 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/utils/WebDomain.kt @@ -0,0 +1,35 @@ +package com.kunzisoft.keepass.utils + +import android.content.Context +import com.kunzisoft.keepass.model.SearchInfo +import com.kunzisoft.keepass.settings.PreferencesUtil +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import mozilla.components.lib.publicsuffixlist.PublicSuffixList + +object WebDomain { + + /** + * Get the concrete web domain AKA without sub domain if needed + */ + fun getConcreteWebDomain(context: Context, + webDomain: String?, + concreteWebDomain: (String?) -> Unit) { + CoroutineScope(Dispatchers.Main).launch { + if (webDomain != null) { + // Warning, web domain can contains IP, don't crop in this case + if (PreferencesUtil.searchSubdomains(context) + || Regex(SearchInfo.WEB_IP_REGEX).matches(webDomain)) { + concreteWebDomain.invoke(webDomain) + } else { + val publicSuffixList = PublicSuffixList(context) + concreteWebDomain.invoke(publicSuffixList + .getPublicSuffixPlusOne(webDomain).await()) + } + } else { + concreteWebDomain.invoke(null) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kunzisoft/keepass/view/SearchFiltersView.kt b/app/src/main/java/com/kunzisoft/keepass/view/SearchFiltersView.kt index 6cceef3c2..434e4e715 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/SearchFiltersView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/SearchFiltersView.kt @@ -11,7 +11,7 @@ import android.widget.LinearLayout import android.widget.TextView import androidx.core.view.isVisible import com.kunzisoft.keepass.R -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.database.search.SearchParameters import com.kunzisoft.keepass.settings.PreferencesUtil diff --git a/app/src/main/java/com/kunzisoft/keepass/view/TemplateEditView.kt b/app/src/main/java/com/kunzisoft/keepass/view/TemplateEditView.kt index add65a3ae..31b8f9af3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/TemplateEditView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/TemplateEditView.kt @@ -16,7 +16,7 @@ import com.kunzisoft.keepass.database.element.security.ProtectedString import com.kunzisoft.keepass.database.element.template.TemplateAttribute import com.kunzisoft.keepass.database.element.template.TemplateAttributeAction import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.getLocalizedName +import com.kunzisoft.keepass.database.helper.getLocalizedName import com.kunzisoft.keepass.otp.OtpEntryFields import org.joda.time.DateTime diff --git a/app/src/main/java/com/kunzisoft/keepass/view/TemplateView.kt b/app/src/main/java/com/kunzisoft/keepass/view/TemplateView.kt index 54b2602fb..e0bd7f811 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/TemplateView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/TemplateView.kt @@ -9,7 +9,7 @@ import com.kunzisoft.keepass.database.element.Field import com.kunzisoft.keepass.database.element.security.ProtectedString import com.kunzisoft.keepass.database.element.template.TemplateAttribute import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.getLocalizedName +import com.kunzisoft.keepass.database.helper.getLocalizedName import com.kunzisoft.keepass.model.OtpModel import com.kunzisoft.keepass.otp.OtpElement import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD diff --git a/app/src/main/java/com/kunzisoft/keepass/view/TextEditFieldView.kt b/app/src/main/java/com/kunzisoft/keepass/view/TextEditFieldView.kt index 22fce4855..e426dc3b8 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/TextEditFieldView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/TextEditFieldView.kt @@ -21,7 +21,7 @@ import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputLayout import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.isStandardPasswordName +import com.kunzisoft.keepass.database.helper.isStandardPasswordName import com.kunzisoft.keepass.password.PasswordGenerator import com.kunzisoft.keepass.settings.PreferencesUtil diff --git a/app/src/main/java/com/kunzisoft/keepass/view/TextFieldView.kt b/app/src/main/java/com/kunzisoft/keepass/view/TextFieldView.kt index 5799edccc..8ce46bfba 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/TextFieldView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/TextFieldView.kt @@ -39,7 +39,7 @@ import androidx.core.view.ViewCompat import androidx.core.view.isVisible import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.template.TemplateField -import com.kunzisoft.keepass.database.element.template.isStandardPasswordName +import com.kunzisoft.keepass.database.helper.isStandardPasswordName import com.kunzisoft.keepass.model.EntryInfo.Companion.APPLICATION_ID_FIELD_NAME import com.kunzisoft.keepass.password.PasswordGenerator import com.kunzisoft.keepass.settings.PreferencesUtil diff --git a/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt b/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt index e5e6fc52e..8c9b021d3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt @@ -49,7 +49,7 @@ import androidx.core.view.updatePadding import com.google.android.material.appbar.CollapsingToolbarLayout import com.google.android.material.snackbar.Snackbar import com.kunzisoft.keepass.R -import com.kunzisoft.keepass.database.exception.getLocalizedMessage +import com.kunzisoft.keepass.database.helper.getLocalizedMessage import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.tasks.ActionRunnable diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFileViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFileViewModel.kt index ffc8f8d8d..ddf1356f1 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFileViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFileViewModel.kt @@ -6,7 +6,7 @@ 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.utils.IOActionTask import com.kunzisoft.keepass.model.DatabaseFile import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.utils.UriUtil diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFilesViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFilesViewModel.kt index 0fafefbc6..a31f95dfd 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFilesViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseFilesViewModel.kt @@ -6,7 +6,7 @@ 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.utils.IOActionTask import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.model.DatabaseFile import com.kunzisoft.keepass.settings.PreferencesUtil diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseViewModel.kt index 1dbadcc77..db10eb971 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/DatabaseViewModel.kt @@ -7,7 +7,7 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Group -import com.kunzisoft.keepass.database.element.database.NamedCompressionAlgorithm +import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm import com.kunzisoft.keepass.tasks.ActionRunnable class DatabaseViewModel: ViewModel() { @@ -119,8 +119,8 @@ class DatabaseViewModel: ViewModel() { _saveColor.value = SuperString(oldValue, newValue, save) } - fun saveCompression(oldValue: NamedCompressionAlgorithm, - newValue: NamedCompressionAlgorithm, + fun saveCompression(oldValue: CompressionAlgorithm, + newValue: CompressionAlgorithm, save: Boolean) { _saveCompression.value = SuperCompression(oldValue, newValue, save) } @@ -198,8 +198,8 @@ class DatabaseViewModel: ViewModel() { val save: Boolean) data class SuperMerge(val fixDuplicateUuid: Boolean, val save: Boolean) - data class SuperCompression(val oldValue: NamedCompressionAlgorithm, - val newValue: NamedCompressionAlgorithm, + data class SuperCompression(val oldValue: CompressionAlgorithm, + val newValue: CompressionAlgorithm, val save: Boolean) data class SuperEncryption(val oldValue: EncryptionAlgorithm, val newValue: EncryptionAlgorithm, diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryEditViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryEditViewModel.kt index 241dd2dfd..5de95431f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryEditViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryEditViewModel.kt @@ -3,7 +3,7 @@ package com.kunzisoft.keepass.viewmodels import android.net.Uri import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData -import com.kunzisoft.keepass.app.database.IOActionTask +import com.kunzisoft.keepass.utils.IOActionTask import com.kunzisoft.keepass.database.element.* import com.kunzisoft.keepass.database.element.icon.IconImage import com.kunzisoft.keepass.database.element.icon.IconImageStandard diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt index fc371c869..23a11d0e4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/EntryViewModel.kt @@ -22,7 +22,7 @@ package com.kunzisoft.keepass.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.kunzisoft.keepass.app.database.IOActionTask +import com.kunzisoft.keepass.utils.IOActionTask import com.kunzisoft.keepass.database.element.Attachment import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.node.NodeId diff --git a/app/src/main/java/com/kunzisoft/keepass/viewmodels/GroupViewModel.kt b/app/src/main/java/com/kunzisoft/keepass/viewmodels/GroupViewModel.kt index a442929a4..53eafffd7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/viewmodels/GroupViewModel.kt +++ b/app/src/main/java/com/kunzisoft/keepass/viewmodels/GroupViewModel.kt @@ -22,11 +22,11 @@ package com.kunzisoft.keepass.viewmodels import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.kunzisoft.keepass.app.database.IOActionTask +import com.kunzisoft.keepass.utils.IOActionTask import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Group import com.kunzisoft.keepass.database.element.node.NodeId -import com.kunzisoft.keepass.database.search.SearchHelper +import com.kunzisoft.keepass.database.helper.SearchHelper import com.kunzisoft.keepass.database.search.SearchParameters diff --git a/database/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixList.kt b/app/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixList.kt similarity index 100% rename from database/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixList.kt rename to app/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixList.kt diff --git a/database/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt b/app/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt similarity index 100% rename from database/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt rename to app/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListData.kt diff --git a/database/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListLoader.kt b/app/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListLoader.kt similarity index 100% rename from database/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListLoader.kt rename to app/src/main/java/mozilla/components/lib/publicsuffixlist/PublicSuffixListLoader.kt diff --git a/database/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt b/app/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt similarity index 100% rename from database/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt rename to app/src/main/java/mozilla/components/lib/publicsuffixlist/ext/ByteArray.kt diff --git a/database/build.gradle b/database/build.gradle index ea672b2ad..4a0a79d2a 100644 --- a/database/build.gradle +++ b/database/build.gradle @@ -14,13 +14,6 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" - - kapt { - arguments { - arg("room.incremental", "true") - arg("room.schemaLocation", "$projectDir/schemas".toString()) - } - } } buildTypes { @@ -38,8 +31,6 @@ android { } } -def room_version = "2.4.3" - dependencies { implementation "androidx.core:core-ktx:$android_core_version" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' @@ -51,12 +42,5 @@ dependencies { implementation 'commons-io:commons-io:2.8.0' implementation 'commons-codec:commons-codec:1.15' - // Database - implementation "androidx.room:room-runtime:$room_version" - kapt "androidx.room:room-compiler:$room_version" - implementation project(path: ':crypto') - - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/Database.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/Database.kt index b568a7032..05de5a547 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/Database.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/Database.kt @@ -21,12 +21,10 @@ package com.kunzisoft.keepass.database.element import android.content.ContentResolver import android.content.Context -import android.content.res.Resources import android.graphics.Color import android.net.Uri import android.util.Log import com.kunzisoft.androidclearchroma.ChromaUtil -import com.kunzisoft.keepass.database.action.node.NodeHandler import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.element.binary.AttachmentPool @@ -38,6 +36,7 @@ import com.kunzisoft.keepass.database.element.database.DatabaseKDBX import com.kunzisoft.keepass.database.element.icon.IconImageCustom import com.kunzisoft.keepass.database.element.icon.IconImageStandard import com.kunzisoft.keepass.database.element.icon.IconsManager +import com.kunzisoft.keepass.database.element.node.NodeHandler import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.NodeIdInt import com.kunzisoft.keepass.database.element.node.NodeIdUUID @@ -301,7 +300,7 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) { return false // Default compression not necessary if stored in header mDatabaseKDBX?.let { - return it.compressionAlgorithm == CompressionAlgorithm.GZip + return it.compressionAlgorithm == CompressionAlgorithm.GZIP && it.kdbxVersion.isBefore(FILE_VERSION_40) } return false diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt index 4eb601d86..30c1351a6 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/Group.kt @@ -30,7 +30,6 @@ import com.kunzisoft.keepass.database.element.icon.IconImage import com.kunzisoft.keepass.database.element.node.* import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.GroupInfo -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil import java.util.* import kotlin.collections.ArrayList @@ -86,8 +85,8 @@ class Group : Node, GroupVersionedInterface { META_STREAM, EXPIRED; companion object { - fun getDefaults(context: Context): Array { - return if (DatabasePreferencesUtil.showExpiredEntries(context)) { + fun getDefaults(showExpiredEntries: Boolean): Array { + return if (showExpiredEntries) { arrayOf(META_STREAM) } else { arrayOf(META_STREAM, EXPIRED) diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/database/CompressionAlgorithm.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/database/CompressionAlgorithm.kt index b41ad76f5..476371771 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/database/CompressionAlgorithm.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/database/CompressionAlgorithm.kt @@ -19,7 +19,33 @@ */ package com.kunzisoft.keepass.database.element.database -enum class CompressionAlgorithm { - None, - GZip; +import android.os.Parcel +import android.os.Parcelable +import com.kunzisoft.keepass.utils.readEnum +import com.kunzisoft.keepass.utils.writeEnum + +// Note: We can get away with using int's to store unsigned 32-bit ints +// since we won't do arithmetic on these values (also unlikely to +// reach negative ids). +enum class CompressionAlgorithm : Parcelable { + NONE, + GZIP; + + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeEnum(this) + } + + override fun describeContents(): Int { + return 0 + } + + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): CompressionAlgorithm { + return parcel.readEnum() ?: NONE + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt index 0f1d263b7..dba4b93f2 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/database/DatabaseKDBX.kt @@ -20,24 +20,16 @@ package com.kunzisoft.keepass.database.element.database import android.content.ContentResolver -import android.content.res.Resources import android.util.Base64 import android.util.Log import com.kunzisoft.encrypt.HashManager -import com.kunzisoft.keepass.database.R -import com.kunzisoft.keepass.database.action.node.NodeHandler import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm import com.kunzisoft.keepass.database.crypto.VariantDictionary import com.kunzisoft.keepass.database.crypto.kdf.AesKdf import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory import com.kunzisoft.keepass.database.crypto.kdf.KdfParameters -import com.kunzisoft.keepass.database.element.CompositeKey -import com.kunzisoft.keepass.database.element.CustomData -import com.kunzisoft.keepass.database.element.DateInstant -import com.kunzisoft.keepass.database.element.DeletedObject -import com.kunzisoft.keepass.database.element.MainCredential -import com.kunzisoft.keepass.database.element.Tags +import com.kunzisoft.keepass.database.element.* import com.kunzisoft.keepass.database.element.binary.BinaryData import com.kunzisoft.keepass.database.element.database.DatabaseKDB.Companion.BACKUP_FOLDER_TITLE import com.kunzisoft.keepass.database.element.entry.EntryKDBX @@ -45,10 +37,7 @@ import com.kunzisoft.keepass.database.element.entry.FieldReferencesEngine import com.kunzisoft.keepass.database.element.group.GroupKDBX import com.kunzisoft.keepass.database.element.icon.IconImageCustom import com.kunzisoft.keepass.database.element.icon.IconImageStandard -import com.kunzisoft.keepass.database.element.node.NodeId -import com.kunzisoft.keepass.database.element.node.NodeIdUUID -import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface -import com.kunzisoft.keepass.database.element.node.NodeVersioned +import com.kunzisoft.keepass.database.element.node.* import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig import com.kunzisoft.keepass.database.element.template.Template import com.kunzisoft.keepass.database.element.template.TemplateEngineCompatible @@ -63,8 +52,7 @@ import java.io.IOException import java.nio.charset.Charset import java.security.MessageDigest import java.security.NoSuchAlgorithmException -import java.util.Arrays -import java.util.UUID +import java.util.* import javax.crypto.Mac import kotlin.math.min @@ -127,7 +115,7 @@ class DatabaseKDBX : DatabaseVersioned { KdfFactory.argon2idKdf ) - var compressionAlgorithm = CompressionAlgorithm.GZip + var compressionAlgorithm = CompressionAlgorithm.GZIP private val mFieldReferenceEngine = FieldReferencesEngine(this) private val mTemplateEngine = TemplateEngineCompatible(this) @@ -353,8 +341,8 @@ class DatabaseKDBX : DatabaseVersioned { } val availableCompressionAlgorithms: List = listOf( - CompressionAlgorithm.None, - CompressionAlgorithm.GZip + CompressionAlgorithm.NONE, + CompressionAlgorithm.GZIP ) fun changeBinaryCompression( @@ -362,11 +350,11 @@ class DatabaseKDBX : DatabaseVersioned { newCompression: CompressionAlgorithm, ) { when (oldCompression) { - CompressionAlgorithm.None -> { + CompressionAlgorithm.NONE -> { when (newCompression) { - CompressionAlgorithm.None -> { + CompressionAlgorithm.NONE -> { } - CompressionAlgorithm.GZip -> { + CompressionAlgorithm.GZIP -> { // Only in databaseV3.1, in databaseV4 the header is zipped during the save if (kdbxVersion.isBefore(FILE_VERSION_40)) { compressAllBinaries() @@ -374,14 +362,14 @@ class DatabaseKDBX : DatabaseVersioned { } } } - CompressionAlgorithm.GZip -> { + CompressionAlgorithm.GZIP -> { // In databaseV4 the header is zipped during the save, so not necessary here if (kdbxVersion.isBefore(FILE_VERSION_40)) { when (newCompression) { - CompressionAlgorithm.None -> { + CompressionAlgorithm.NONE -> { decompressAllBinaries() } - CompressionAlgorithm.GZip -> { + CompressionAlgorithm.GZIP -> { } } } else { diff --git a/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupVersionedInterface.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupVersionedInterface.kt index 819f81a7b..a5182fa88 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupVersionedInterface.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/group/GroupVersionedInterface.kt @@ -19,7 +19,7 @@ */ package com.kunzisoft.keepass.database.element.group -import com.kunzisoft.keepass.database.action.node.NodeHandler +import com.kunzisoft.keepass.database.element.node.NodeHandler import com.kunzisoft.keepass.database.element.node.NodeVersionedInterface interface GroupVersionedInterface, Entry> : NodeVersionedInterface { diff --git a/database/src/main/java/com/kunzisoft/keepass/database/action/node/NodeHandler.kt b/database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeHandler.kt similarity index 94% rename from database/src/main/java/com/kunzisoft/keepass/database/action/node/NodeHandler.kt rename to database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeHandler.kt index 28b40059c..9e38c6332 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/action/node/NodeHandler.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/element/node/NodeHandler.kt @@ -17,7 +17,7 @@ * along with KeePassDX. If not, see . * */ -package com.kunzisoft.keepass.database.action.node +package com.kunzisoft.keepass.database.element.node /** "Delegate" class for operating on each group when traversing all of diff --git a/database/src/main/java/com/kunzisoft/keepass/database/file/DatabaseHeaderKDBX.kt b/database/src/main/java/com/kunzisoft/keepass/database/file/DatabaseHeaderKDBX.kt index 162deceef..29ecb19ad 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/file/DatabaseHeaderKDBX.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/file/DatabaseHeaderKDBX.kt @@ -145,35 +145,35 @@ class DatabaseHeaderKDBX(private val databaseV4: DatabaseKDBX) : DatabaseHeader( return true if (fieldData != null) - when (fieldID) { - PwDbHeaderV4Fields.CipherID -> setCipher(fieldData) + when (fieldID) { + PwDbHeaderV4Fields.CipherID -> setCipher(fieldData) - PwDbHeaderV4Fields.CompressionFlags -> setCompressionFlags(fieldData) + PwDbHeaderV4Fields.CompressionFlags -> setCompressionFlags(fieldData) - PwDbHeaderV4Fields.MasterSeed -> masterSeed = fieldData + PwDbHeaderV4Fields.MasterSeed -> masterSeed = fieldData - PwDbHeaderV4Fields.TransformSeed -> if (version.isBefore(FILE_VERSION_40)) - transformSeed = fieldData + PwDbHeaderV4Fields.TransformSeed -> if (version.isBefore(FILE_VERSION_40)) + transformSeed = fieldData - PwDbHeaderV4Fields.TransformRounds -> if (version.isBefore(FILE_VERSION_40)) - setTransformRound(fieldData) + PwDbHeaderV4Fields.TransformRounds -> if (version.isBefore(FILE_VERSION_40)) + setTransformRound(fieldData) - PwDbHeaderV4Fields.EncryptionIV -> encryptionIV = fieldData + PwDbHeaderV4Fields.EncryptionIV -> encryptionIV = fieldData - PwDbHeaderV4Fields.InnerRandomstreamKey -> if (version.isBefore(FILE_VERSION_40)) - innerRandomStreamKey = fieldData + PwDbHeaderV4Fields.InnerRandomstreamKey -> if (version.isBefore(FILE_VERSION_40)) + innerRandomStreamKey = fieldData - PwDbHeaderV4Fields.StreamStartBytes -> streamStartBytes = fieldData + PwDbHeaderV4Fields.StreamStartBytes -> streamStartBytes = fieldData - PwDbHeaderV4Fields.InnerRandomStreamID -> if (version.isBefore(FILE_VERSION_40)) - setRandomStreamID(fieldData) + PwDbHeaderV4Fields.InnerRandomStreamID -> if (version.isBefore(FILE_VERSION_40)) + setRandomStreamID(fieldData) - PwDbHeaderV4Fields.KdfParameters -> databaseV4.kdfParameters = KdfParameters.deserialize(fieldData) + PwDbHeaderV4Fields.KdfParameters -> databaseV4.kdfParameters = KdfParameters.deserialize(fieldData) - PwDbHeaderV4Fields.PublicCustomData -> databaseV4.publicCustomData = VariantDictionary.deserialize(fieldData) + PwDbHeaderV4Fields.PublicCustomData -> databaseV4.publicCustomData = VariantDictionary.deserialize(fieldData) - else -> throw IOException("Invalid header type: $fieldID") - } + else -> throw IOException("Invalid header type: $fieldID") + } return false } @@ -256,15 +256,15 @@ class DatabaseHeaderKDBX(private val databaseV4: DatabaseKDBX) : DatabaseHeader( fun getCompressionFromFlag(flag: UnsignedInt): CompressionAlgorithm? { return when (flag.toKotlinInt()) { - 0 -> CompressionAlgorithm.None - 1 -> CompressionAlgorithm.GZip + 0 -> CompressionAlgorithm.NONE + 1 -> CompressionAlgorithm.GZIP else -> null } } fun getFlagFromCompression(compression: CompressionAlgorithm): UnsignedInt { return when (compression) { - CompressionAlgorithm.GZip -> UnsignedInt(1) + CompressionAlgorithm.GZIP -> UnsignedInt(1) else -> UnsignedInt(0) } } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt b/database/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt index cbe66ae14..7d9e1867d 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/file/input/DatabaseInputKDBX.kt @@ -179,7 +179,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX) } val inputStreamXml: InputStream = when (mDatabase.compressionAlgorithm) { - CompressionAlgorithm.GZip -> GZIPInputStream(plainInputStream) + CompressionAlgorithm.GZIP -> GZIPInputStream(plainInputStream) else -> plainInputStream } diff --git a/database/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDBX.kt b/database/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDBX.kt index 94292b8e1..2866ffaca 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDBX.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/file/output/DatabaseOutputKDBX.kt @@ -23,7 +23,6 @@ import android.util.Base64 import android.util.Log import android.util.Xml import com.kunzisoft.encrypt.StreamCipher -import com.kunzisoft.keepass.database.action.node.NodeHandler import com.kunzisoft.keepass.database.crypto.CrsAlgorithm import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory import com.kunzisoft.keepass.database.element.* @@ -34,6 +33,7 @@ import com.kunzisoft.keepass.database.element.database.DatabaseVersioned import com.kunzisoft.keepass.database.element.entry.AutoType import com.kunzisoft.keepass.database.element.entry.EntryKDBX import com.kunzisoft.keepass.database.element.group.GroupKDBX +import com.kunzisoft.keepass.database.element.node.NodeHandler import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig import com.kunzisoft.keepass.database.exception.DatabaseOutputException @@ -85,7 +85,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX) } when(mDatabaseKDBX.compressionAlgorithm) { - CompressionAlgorithm.GZip -> GZIPOutputStream(osPlain) + CompressionAlgorithm.GZIP -> GZIPOutputStream(osPlain) else -> osPlain }.use { xmlOutputStream -> if (!header!!.version.isBefore(FILE_VERSION_40)) { diff --git a/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt b/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt index 25c3847ce..0196f4f0d 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt @@ -19,7 +19,6 @@ */ package com.kunzisoft.keepass.database.merge -import com.kunzisoft.keepass.database.action.node.NodeHandler import com.kunzisoft.keepass.database.element.Attachment import com.kunzisoft.keepass.database.element.CustomData import com.kunzisoft.keepass.database.element.DateInstant @@ -29,6 +28,7 @@ import com.kunzisoft.keepass.database.element.entry.EntryKDB import com.kunzisoft.keepass.database.element.entry.EntryKDBX import com.kunzisoft.keepass.database.element.group.GroupKDB import com.kunzisoft.keepass.database.element.group.GroupKDBX +import com.kunzisoft.keepass.database.element.node.NodeHandler import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.NodeIdInt import com.kunzisoft.keepass.database.element.node.NodeIdUUID diff --git a/database/src/main/java/com/kunzisoft/keepass/database/search/SearchHelper.kt b/database/src/main/java/com/kunzisoft/keepass/database/search/SearchHelper.kt index b56e5b401..01d8b8e52 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/search/SearchHelper.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/search/SearchHelper.kt @@ -19,16 +19,12 @@ */ package com.kunzisoft.keepass.database.search -import android.content.Context -import com.kunzisoft.keepass.database.action.node.NodeHandler import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Group +import com.kunzisoft.keepass.database.element.node.NodeHandler import com.kunzisoft.keepass.database.element.node.NodeId -import com.kunzisoft.keepass.model.EntryInfo -import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_FIELD -import com.kunzisoft.keepass.timeout.TimeoutHelper import com.kunzisoft.keepass.utils.UuidUtil class SearchHelper { @@ -120,53 +116,6 @@ class SearchHelper { } companion object { - const val MAX_SEARCH_ENTRY = 1000 - - /** - * Method to show the number of search results with max results - */ - fun showNumberOfSearchResults(number: Int): String { - return if (number >= MAX_SEARCH_ENTRY) { - (MAX_SEARCH_ENTRY-1).toString() + "+" - } else { - number.toString() - } - } - - /** - * Utility method to perform actions if item is found or not after an auto search in [database] - */ - fun checkAutoSearchInfo(context: Context, - database: Database?, - searchInfo: SearchInfo?, - onItemsFound: (openedDatabase: Database, - items: List) -> Unit, - onItemNotFound: (openedDatabase: Database) -> Unit, - onDatabaseClosed: () -> Unit) { - if (database == null || !database.loaded) { - onDatabaseClosed.invoke() - } else if (TimeoutHelper.checkTime(context)) { - var searchWithoutUI = false - if (searchInfo != null - && !searchInfo.manualSelection - && !searchInfo.containsOnlyNullValues()) { - // If search provide results - database.createVirtualGroupFromSearchInfo( - searchInfo.toString(), - MAX_SEARCH_ENTRY - )?.let { searchGroup -> - if (searchGroup.numberOfChildEntries > 0) { - searchWithoutUI = true - onItemsFound.invoke(database, - searchGroup.getChildEntriesInfo(database)) - } - } - } - if (!searchWithoutUI) { - onItemNotFound.invoke(database) - } - } - } /** * Return true if the search query in search parameters is found in available parameters diff --git a/database/src/main/java/com/kunzisoft/keepass/model/SearchInfo.kt b/database/src/main/java/com/kunzisoft/keepass/model/SearchInfo.kt index 195c2b004..b8d3f63c1 100644 --- a/database/src/main/java/com/kunzisoft/keepass/model/SearchInfo.kt +++ b/database/src/main/java/com/kunzisoft/keepass/model/SearchInfo.kt @@ -1,17 +1,11 @@ package com.kunzisoft.keepass.model -import android.content.Context import android.content.res.Resources import android.net.Uri import android.os.Parcel import android.os.Parcelable import com.kunzisoft.keepass.otp.OtpEntryFields -import com.kunzisoft.keepass.settings.DatabasePreferencesUtil import com.kunzisoft.keepass.utils.ObjectNameResource -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import mozilla.components.lib.publicsuffixlist.PublicSuffixList class SearchInfo : ObjectNameResource, Parcelable { var manualSelection: Boolean = false @@ -131,28 +125,5 @@ class SearchInfo : ObjectNameResource, Parcelable { return arrayOfNulls(size) } } - - /** - * Get the concrete web domain AKA without sub domain if needed - */ - fun getConcreteWebDomain(context: Context, - webDomain: String?, - concreteWebDomain: (String?) -> Unit) { - CoroutineScope(Dispatchers.Main).launch { - if (webDomain != null) { - // Warning, web domain can contains IP, don't crop in this case - if (DatabasePreferencesUtil.searchSubdomains(context) - || Regex(WEB_IP_REGEX).matches(webDomain)) { - concreteWebDomain.invoke(webDomain) - } else { - val publicSuffixList = PublicSuffixList(context) - concreteWebDomain.invoke(publicSuffixList - .getPublicSuffixPlusOne(webDomain).await()) - } - } else { - concreteWebDomain.invoke(null) - } - } - } } } diff --git a/database/src/main/java/com/kunzisoft/keepass/settings/DatabasePreferencesUtil.kt b/database/src/main/java/com/kunzisoft/keepass/settings/DatabasePreferencesUtil.kt deleted file mode 100644 index 63db36053..000000000 --- a/database/src/main/java/com/kunzisoft/keepass/settings/DatabasePreferencesUtil.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.kunzisoft.keepass.settings - -import android.content.Context -import android.preference.PreferenceManager -import com.kunzisoft.keepass.database.R -import com.kunzisoft.keepass.timeout.TimeoutHelper - -object DatabasePreferencesUtil { - - const val HIDE_EXPIRED_ENTRIES_KEY = "hide_expired_entries_key" - private const val HIDE_EXPIRED_ENTRIES_DEFAULT = false - const val SETTING_ICON_PACK_CHOOSE_KEY = "setting_icon_pack_choose_key" - private const val SETTING_ICON_PACK_CHOOSE_DEFAULT = "material" - const val SUBDOMAIN_SEARCH_KEY = "subdomain_search_key" - private const val SUBDOMAIN_SEARCH_DEFAULT = false - const val TIMEOUT_BACKUP_KEY = "timeout_backup_key" - const val APP_TIMEOUT_KEY = "app_timeout_key" - const val TIMEOUT_DEFAULT = "300000" - - fun showExpiredEntries(context: Context): Boolean { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return ! prefs.getBoolean(HIDE_EXPIRED_ENTRIES_KEY, HIDE_EXPIRED_ENTRIES_DEFAULT) - } - - fun getIconPackSelectedId(context: Context): String? { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getString( - SETTING_ICON_PACK_CHOOSE_KEY, - SETTING_ICON_PACK_CHOOSE_DEFAULT) - } - - fun searchSubdomains(context: Context): Boolean { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getBoolean(SUBDOMAIN_SEARCH_KEY, SUBDOMAIN_SEARCH_DEFAULT) - } - - /** - * Save current time, can be retrieve with `getTimeSaved()` - */ - fun saveCurrentTime(context: Context) { - PreferenceManager.getDefaultSharedPreferences(context).edit().apply { - putLong(TIMEOUT_BACKUP_KEY, System.currentTimeMillis()) - apply() - } - } - - /** - * Time previously saved in milliseconds (commonly used to compare with current time and check timeout) - */ - fun getTimeSaved(context: Context): Long { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - return prefs.getLong(TIMEOUT_BACKUP_KEY, - TimeoutHelper.NEVER) - } - - /** - * App timeout selected in milliseconds - */ - fun getAppTimeout(context: Context): Long { - return try { - val prefs = PreferenceManager.getDefaultSharedPreferences(context) - (prefs.getString(APP_TIMEOUT_KEY, TIMEOUT_DEFAULT) ?: TIMEOUT_DEFAULT).toLong() - } catch (e: NumberFormatException) { - TimeoutHelper.DEFAULT_TIMEOUT - } - } -} diff --git a/database/src/main/java/com/kunzisoft/keepass/utils/LOCK_ACTION.kt b/database/src/main/java/com/kunzisoft/keepass/utils/LOCK_ACTION.kt deleted file mode 100644 index cc2db1a85..000000000 --- a/database/src/main/java/com/kunzisoft/keepass/utils/LOCK_ACTION.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.kunzisoft.keepass.utils - -const val LOCK_ACTION = "com.kunzisoft.keepass.LOCK"