Refactoring code, better encapsulation

This commit is contained in:
J-Jamet 2023-05-08 18:49:42 +02:00
parent 48cc8b3f75
commit c8868f31e6
86 changed files with 566 additions and 635 deletions

View file

@ -21,6 +21,13 @@ android {
buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}" buildConfigField "String[]", "ICON_PACKS", "{\"classic\",\"material\"}"
manifestPlaceholders = [ googleAndroidBackupAPIKey:"unused" ] manifestPlaceholders = [ googleAndroidBackupAPIKey:"unused" ]
kapt {
arguments {
arg("room.incremental", "true")
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}
} }
buildTypes { buildTypes {

View file

@ -37,10 +37,11 @@ import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.autofill.CompatInlineSuggestionsRequest import com.kunzisoft.keepass.autofill.CompatInlineSuggestionsRequest
import com.kunzisoft.keepass.autofill.KeeAutofillService import com.kunzisoft.keepass.autofill.KeeAutofillService
import com.kunzisoft.keepass.database.element.Database 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.RegisterInfo
import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.WebDomain
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
class AutofillLauncherActivity : DatabaseModeActivity() { class AutofillLauncherActivity : DatabaseModeActivity() {
@ -73,7 +74,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
} }
// Build search param // Build search param
bundle.getParcelable<SearchInfo>(KEY_SEARCH_INFO)?.let { searchInfo -> bundle.getParcelable<SearchInfo>(KEY_SEARCH_INFO)?.let { searchInfo ->
SearchInfo.getConcreteWebDomain( WebDomain.getConcreteWebDomain(
this, this,
searchInfo.webDomain searchInfo.webDomain
) { concreteWebDomain -> ) { concreteWebDomain ->
@ -101,7 +102,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
// To register info // To register info
val registerInfo = intent.getParcelableExtra<RegisterInfo>(KEY_REGISTER_INFO) val registerInfo = intent.getParcelableExtra<RegisterInfo>(KEY_REGISTER_INFO)
val searchInfo = SearchInfo(registerInfo?.searchInfo) val searchInfo = SearchInfo(registerInfo?.searchInfo)
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain -> WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain searchInfo.webDomain = concreteWebDomain
launchRegistration(database, searchInfo, registerInfo) launchRegistration(database, searchInfo, registerInfo)
} }

View file

@ -27,10 +27,11 @@ import android.widget.Toast
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity import com.kunzisoft.keepass.activities.legacy.DatabaseModeActivity
import com.kunzisoft.keepass.database.element.Database 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.magikeyboard.MagikeyboardService
import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.otp.OtpEntryFields import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.utils.WebDomain
/** /**
* Activity to search or select entry in database, * Activity to search or select entry in database,
@ -104,7 +105,7 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
this.otpString = otpString this.otpString = otpString
} }
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain -> WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain searchInfo.webDomain = concreteWebDomain
launch(database, searchInfo) launch(database, searchInfo)
} }

View file

@ -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.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdUUID import com.kunzisoft.keepass.database.element.node.NodeIdUUID
import com.kunzisoft.keepass.database.element.node.Type 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.database.search.SearchParameters
import com.kunzisoft.keepass.education.GroupActivityEducation import com.kunzisoft.keepass.education.GroupActivityEducation
import com.kunzisoft.keepass.magikeyboard.MagikeyboardService import com.kunzisoft.keepass.magikeyboard.MagikeyboardService

View file

@ -59,7 +59,6 @@ import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
import com.kunzisoft.keepass.database.exception.FileNotFoundDatabaseException import com.kunzisoft.keepass.database.exception.FileNotFoundDatabaseException
import com.kunzisoft.keepass.database.exception.getLocalizedMessage
import com.kunzisoft.keepass.education.PasswordActivityEducation import com.kunzisoft.keepass.education.PasswordActivityEducation
import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.model.* import com.kunzisoft.keepass.model.*

View file

@ -17,7 +17,7 @@ import com.kunzisoft.keepass.adapters.EntryAttachmentsItemsAdapter
import com.kunzisoft.keepass.database.element.Attachment import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.template.TemplateField 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.EntryAttachmentState
import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.StreamDirection import com.kunzisoft.keepass.model.StreamDirection

View file

@ -112,7 +112,11 @@ class BreadcrumbAdapter(val context: Context)
holder.groupNumbersView?.apply { holder.groupNumbersView?.apply {
if (mShowNumberEntries) { if (mShowNumberEntries) {
group.refreshNumberOfChildEntries(Group.ChildFilter.getDefaults(context)) group.refreshNumberOfChildEntries(
Group.ChildFilter.getDefaults(
PreferencesUtil.showExpiredEntries(context)
)
)
text = group.numberOfChildEntries.toString() text = group.numberOfChildEntries.toString()
visibility = View.VISIBLE visibility = View.VISIBLE
} else { } else {

View file

@ -33,7 +33,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.ImageViewerActivity import com.kunzisoft.keepass.activities.ImageViewerActivity
import com.kunzisoft.keepass.database.element.Database 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.AttachmentState
import com.kunzisoft.keepass.model.EntryAttachmentState import com.kunzisoft.keepass.model.EntryAttachmentState
import com.kunzisoft.keepass.model.StreamDirection import com.kunzisoft.keepass.model.StreamDirection
@ -130,7 +131,7 @@ class EntryAttachmentsItemsAdapter(context: Context)
holder.binaryFileSize.text = Formatter.formatFileSize(context, size) holder.binaryFileSize.text = Formatter.formatFileSize(context, size)
holder.binaryFileCompression.apply { holder.binaryFileCompression.apply {
if (entryAttachmentState.attachment.binaryData.isCompressed) { if (entryAttachmentState.attachment.binaryData.isCompressed) {
text = NamedCompressionAlgorithm.GZip.getName(context.resources) text = CompressionAlgorithm.GZIP.getLocalizedName(context.resources)
visibility = View.VISIBLE visibility = View.VISIBLE
} else { } else {
text = "" text = ""

View file

@ -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.NodeVersionedInterface
import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.database.element.template.TemplateField 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.OtpElement
import com.kunzisoft.keepass.otp.OtpType import com.kunzisoft.keepass.otp.OtpType
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
@ -153,7 +153,9 @@ class NodesAdapter (private val context: Context,
this.mShowOTP = PreferencesUtil.showOTPToken(context) this.mShowOTP = PreferencesUtil.showOTPToken(context)
this.mShowUUID = PreferencesUtil.showUUID(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 // Reinit textSize for all view type
mCalculateViewTypeTextSize.forEachIndexed { index, _ -> mCalculateViewTypeTextSize[index] = true } mCalculateViewTypeTextSize.forEachIndexed { index, _ -> mCalculateViewTypeTextSize[index] = true }

View file

@ -11,7 +11,7 @@ import android.widget.TextView
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.template.Template import com.kunzisoft.keepass.database.element.template.Template
import com.kunzisoft.keepass.database.element.template.TemplateField 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 import com.kunzisoft.keepass.icons.IconDrawableFactory

View file

@ -30,6 +30,7 @@ import android.util.Log
import com.kunzisoft.keepass.model.CipherEncryptDatabase import com.kunzisoft.keepass.model.CipherEncryptDatabase
import com.kunzisoft.keepass.services.AdvancedUnlockNotificationService import com.kunzisoft.keepass.services.AdvancedUnlockNotificationService
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.IOActionTask
import com.kunzisoft.keepass.utils.SingletonHolderParameter import com.kunzisoft.keepass.utils.SingletonHolderParameter
import java.util.LinkedList import java.util.LinkedList

View file

@ -25,6 +25,7 @@ import android.util.Log
import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.model.DatabaseFile import com.kunzisoft.keepass.model.DatabaseFile
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.IOActionTask
import com.kunzisoft.keepass.utils.SingletonHolderParameter import com.kunzisoft.keepass.utils.SingletonHolderParameter
import com.kunzisoft.keepass.utils.UriUtilDatabase import com.kunzisoft.keepass.utils.UriUtilDatabase
import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo

View file

@ -37,12 +37,13 @@ import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.AutofillLauncherActivity import com.kunzisoft.keepass.activities.AutofillLauncherActivity
import com.kunzisoft.keepass.database.action.DatabaseTaskProvider import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Database 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.CreditCard
import com.kunzisoft.keepass.model.RegisterInfo import com.kunzisoft.keepass.model.RegisterInfo
import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.settings.AutofillSettingsActivity import com.kunzisoft.keepass.settings.AutofillSettingsActivity
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.WebDomain
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
@ -104,7 +105,7 @@ class KeeAutofillService : AutofillService() {
webDomain = parseResult.webDomain webDomain = parseResult.webDomain
webScheme = parseResult.webScheme webScheme = parseResult.webScheme
} }
SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { webDomainWithoutSubDomain -> WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { webDomainWithoutSubDomain ->
searchInfo.webDomain = webDomainWithoutSubDomain searchInfo.webDomain = webDomainWithoutSubDomain
val inlineSuggestionsRequest = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R val inlineSuggestionsRequest = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& autofillInlineSuggestionsEnabled) { && autofillInlineSuggestionsEnabled) {

View file

@ -24,16 +24,16 @@ import android.net.Uri
import com.kunzisoft.keepass.app.database.CipherDatabaseAction import com.kunzisoft.keepass.app.database.CipherDatabaseAction
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.hardware.HardwareKey
open class AssignMainCredentialInDatabaseRunnable ( open class AssignMainCredentialInDatabaseRunnable (
context: Context, context: Context,
database: Database, database: Database,
protected val mDatabaseUri: Uri, protected val mDatabaseUri: Uri,
mainCredential: MainCredential, mainCredential: MainCredential,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: SaveDatabaseRunnable(context, database, true, mainCredential, challengeResponseRetriever) { ) : SaveDatabaseRunnable(context, database, true, mainCredential, challengeResponseRetriever) {
private var mBackupKey: ByteArray? = null private var mBackupKey: ByteArray? = null

View file

@ -24,11 +24,12 @@ import android.net.Uri
import android.util.Log import android.util.Log
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.database.element.MainCredential import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
class CreateDatabaseRunnable(context: Context, class CreateDatabaseRunnable(
context: Context,
private val mDatabase: Database, private val mDatabase: Database,
databaseUri: Uri, databaseUri: Uri,
private val databaseName: String, private val databaseName: String,
@ -36,8 +37,8 @@ class CreateDatabaseRunnable(context: Context,
private val templateGroupName: String?, private val templateGroupName: String?,
val mainCredential: MainCredential, val mainCredential: MainCredential,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
private val createDatabaseResult: ((Result) -> Unit)?) private val createDatabaseResult: ((Result) -> Unit)?
: AssignMainCredentialInDatabaseRunnable(context, mDatabase, databaseUri, mainCredential, challengeResponseRetriever) { ) : AssignMainCredentialInDatabaseRunnable(context, mDatabase, databaseUri, mainCredential, challengeResponseRetriever) {
override fun onStartRun() { override fun onStartRun() {
try { try {

View file

@ -38,7 +38,7 @@ import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.MainCredential 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.Node
import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.database.element.node.Type
@ -584,8 +584,8 @@ class DatabaseTaskProvider(private var context: Context,
, ACTION_DATABASE_UPDATE_COLOR_TASK) , ACTION_DATABASE_UPDATE_COLOR_TASK)
} }
fun startDatabaseSaveCompression(oldCompression: NamedCompressionAlgorithm, fun startDatabaseSaveCompression(oldCompression: CompressionAlgorithm,
newCompression: NamedCompressionAlgorithm, newCompression: CompressionAlgorithm,
save: Boolean) { save: Boolean) {
start(Bundle().apply { start(Bundle().apply {
putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldCompression) putSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY, oldCompression)

View file

@ -26,8 +26,7 @@ import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.database.element.binary.BinaryData import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.exception.DatabaseException import com.kunzisoft.keepass.database.exception.DatabaseException
import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.hardware.HardwareKey
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.tasks.ProgressTaskUpdater
class MergeDatabaseRunnable( class MergeDatabaseRunnable(
@ -39,8 +38,8 @@ class MergeDatabaseRunnable(
saveDatabase: Boolean, saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
private val progressTaskUpdater: ProgressTaskUpdater?, private val progressTaskUpdater: ProgressTaskUpdater?,
private val mLoadDatabaseResult: ((Result) -> Unit)?) private val mLoadDatabaseResult: ((Result) -> Unit)?
: SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { ) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onStartRun() { override fun onStartRun() {
database.wasReloaded = true database.wasReloaded = true
@ -65,7 +64,7 @@ class MergeDatabaseRunnable(
if (result.isSuccess) { if (result.isSuccess) {
// Register the current time to init the lock timer // Register the current time to init the lock timer
DatabasePreferencesUtil.saveCurrentTime(context) PreferencesUtil.saveCurrentTime(context)
} }
super.onActionRun() super.onActionRun()
} }

View file

@ -23,7 +23,7 @@ import android.content.Context
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.binary.BinaryData import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.database.exception.DatabaseException 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.ActionRunnable
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
import com.kunzisoft.keepass.utils.UriUtilDatabase import com.kunzisoft.keepass.utils.UriUtilDatabase
@ -32,7 +32,7 @@ class ReloadDatabaseRunnable(
private val context: Context, private val context: Context,
private val mDatabase: Database, private val mDatabase: Database,
private val progressTaskUpdater: ProgressTaskUpdater?, private val progressTaskUpdater: ProgressTaskUpdater?,
private val mLoadDatabaseResult: ((Result) -> Unit)?, private val mLoadDatabaseResult: ((Result) -> Unit)?
) : ActionRunnable() { ) : ActionRunnable() {
override fun onStartRun() { override fun onStartRun() {
@ -55,7 +55,7 @@ class ReloadDatabaseRunnable(
if (result.isSuccess) { if (result.isSuccess) {
// Register the current time to init the lock timer // Register the current time to init the lock timer
DatabasePreferencesUtil.saveCurrentTime(context) PreferencesUtil.saveCurrentTime(context)
} else { } else {
mDatabase.clearAndClose(context) mDatabase.clearAndClose(context)
} }

View file

@ -27,8 +27,8 @@ class RemoveUnlinkedDataDatabaseRunnable (
context: Context, context: Context,
database: Database, database: Database,
saveDatabase: Boolean, saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { ) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onActionRun() { override fun onActionRun() {
try { try {

View file

@ -22,18 +22,19 @@ package com.kunzisoft.keepass.database.action
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import com.kunzisoft.keepass.database.element.Database 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.database.exception.DatabaseException
import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.database.element.MainCredential
import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.tasks.ActionRunnable
open class SaveDatabaseRunnable(protected var context: Context, open class SaveDatabaseRunnable(
protected var context: Context,
protected var database: Database, protected var database: Database,
private var saveDatabase: Boolean, private var saveDatabase: Boolean,
private var mainCredential: MainCredential?, // If null, uses composite Key private var mainCredential: MainCredential?, // If null, uses composite Key
private var challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray, private var challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray,
private var databaseCopyUri: Uri? = null) private var databaseCopyUri: Uri? = null
: ActionRunnable() { ) : ActionRunnable() {
var mAfterSaveDatabase: ((Result) -> Unit)? = null var mAfterSaveDatabase: ((Result) -> Unit)? = null

View file

@ -30,8 +30,8 @@ class UpdateCompressionBinariesDatabaseRunnable (
private val oldCompressionAlgorithm: CompressionAlgorithm, private val oldCompressionAlgorithm: CompressionAlgorithm,
private val newCompressionAlgorithm: CompressionAlgorithm, private val newCompressionAlgorithm: CompressionAlgorithm,
saveDatabase: Boolean, saveDatabase: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) { ) : SaveDatabaseRunnable(context, database, saveDatabase, null, challengeResponseRetriever) {
override fun onStartRun() { override fun onStartRun() {
// Set new compression // Set new compression

View file

@ -29,8 +29,8 @@ abstract class ActionNodeDatabaseRunnable(
database: Database, database: Database,
private val afterActionNodesFinish: AfterActionNodesFinish?, private val afterActionNodesFinish: AfterActionNodesFinish?,
save: Boolean, save: Boolean,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: SaveDatabaseRunnable(context, database, save, null, challengeResponseRetriever) { ) : SaveDatabaseRunnable(context, database, save, null, challengeResponseRetriever) {
/** /**
* Function do to a node action * Function do to a node action

View file

@ -33,8 +33,8 @@ class AddEntryRunnable constructor(
private val mParent: Group, private val mParent: Group,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish?, afterActionNodesFinish: AfterActionNodesFinish?,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
override fun nodeAction() { override fun nodeAction() {
mNewEntry.touch(modified = true, touchParents = true) mNewEntry.touch(modified = true, touchParents = true)

View file

@ -32,8 +32,8 @@ class AddGroupRunnable constructor(
private val mParent: Group, private val mParent: Group,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish?, afterActionNodesFinish: AfterActionNodesFinish?,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
override fun nodeAction() { override fun nodeAction() {
mNewGroup.touch(modified = true, touchParents = true) mNewGroup.touch(modified = true, touchParents = true)

View file

@ -37,8 +37,8 @@ class CopyNodesRunnable constructor(
private val mNewParent: Group, private val mNewParent: Group,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish?, afterActionNodesFinish: AfterActionNodesFinish?,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
private var mEntriesCopied = ArrayList<Entry>() private var mEntriesCopied = ArrayList<Entry>()

View file

@ -27,14 +27,15 @@ import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.hardware.HardwareKey import com.kunzisoft.keepass.hardware.HardwareKey
class DeleteNodesRunnable(context: Context, class DeleteNodesRunnable(
context: Context,
database: Database, database: Database,
private val mNodesToDelete: List<Node>, private val mNodesToDelete: List<Node>,
private val recyclerBinTitle: String, private val recyclerBinTitle: String,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish, afterActionNodesFinish: AfterActionNodesFinish,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
private var mOldParent: Group? = null private var mOldParent: Group? = null
private var mCanRecycle: Boolean = false private var mCanRecycle: Boolean = false

View file

@ -37,8 +37,8 @@ class MoveNodesRunnable constructor(
private val mNewParent: Group, private val mNewParent: Group,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish?, afterActionNodesFinish: AfterActionNodesFinish?,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
private var mOldParent: Group? = null private var mOldParent: Group? = null

View file

@ -33,8 +33,8 @@ class UpdateEntryRunnable constructor(
private val mNewEntry: Entry, private val mNewEntry: Entry,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish?, afterActionNodesFinish: AfterActionNodesFinish?,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
override fun nodeAction() { override fun nodeAction() {
if (mOldEntry.nodeId == mNewEntry.nodeId) { if (mOldEntry.nodeId == mNewEntry.nodeId) {

View file

@ -32,8 +32,8 @@ class UpdateGroupRunnable constructor(
private val mNewGroup: Group, private val mNewGroup: Group,
save: Boolean, save: Boolean,
afterActionNodesFinish: AfterActionNodesFinish?, afterActionNodesFinish: AfterActionNodesFinish?,
challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray) challengeResponseRetriever: (HardwareKey, ByteArray?) -> ByteArray
: ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) { ) : ActionNodeDatabaseRunnable(context, database, afterActionNodesFinish, save, challengeResponseRetriever) {
override fun nodeAction() { override fun nodeAction() {
if (mOldGroup.nodeId == mNewGroup.nodeId) { if (mOldGroup.nodeId == mNewGroup.nodeId) {

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<NamedCompressionAlgorithm> {
override fun createFromParcel(parcel: Parcel): NamedCompressionAlgorithm {
return parcel.readEnum<NamedCompressionAlgorithm>() ?: None
}
override fun newArray(size: Int): Array<NamedCompressionAlgorithm?> {
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
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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)

View file

@ -16,11 +16,48 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>. * along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.kunzisoft.keepass.database.element.template package com.kunzisoft.keepass.database.helper
import android.content.Context import android.content.Context
import android.content.res.Resources
import com.kunzisoft.keepass.R 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 { fun TemplateField.isStandardPasswordName(context: Context, name: String): Boolean {
return name.equals(LABEL_PASSWORD, true) 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 { fun TemplateField.getLocalizedName(context: Context?, name: String): String {
if (context == null if (context == null
|| TemplateEngine.containsTemplateDecorator(name)) || TemplateEngine.containsTemplateDecorator(name)
)
return name return name
return when { return when {
@ -73,3 +111,5 @@ fun TemplateField.getLocalizedName(context: Context?, name: String): String {
else -> name else -> name
} }
} }

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<EntryInfo>) -> 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)
}
}
}
}

View file

@ -23,8 +23,7 @@ import android.content.Context
import android.util.Log import android.util.Log
import com.kunzisoft.keepass.BuildConfig import com.kunzisoft.keepass.BuildConfig
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.settings.DatabasePreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import java.util.ArrayList
/** /**
* Utility class to built and select an IconPack dynamically by libraries importation * 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? { override fun getSelectedIconPack(context: Context): IconPack? {
build(context) build(context)
if (iconPackSelected == null) { if (iconPackSelected == null) {
setSelectedIconPack(DatabasePreferencesUtil.getIconPackSelectedId(context)) setSelectedIconPack(PreferencesUtil.getIconPackSelectedId(context))
} }
return iconPackSelected return iconPackSelected
} }

View file

@ -47,7 +47,7 @@ import com.kunzisoft.keepass.database.action.DatabaseTaskProvider
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Field import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.node.NodeIdUUID 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.EntryInfo
import com.kunzisoft.keepass.model.SearchInfo import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.password
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Color import android.graphics.Color
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.app.database.IOActionTask import com.kunzisoft.keepass.utils.IOActionTask
import kotlinx.coroutines.* import kotlinx.coroutines.*
import me.gosimple.nbvcxz.Nbvcxz import me.gosimple.nbvcxz.Nbvcxz
import me.gosimple.nbvcxz.resources.Configuration import me.gosimple.nbvcxz.resources.Configuration

View file

@ -39,8 +39,7 @@ import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.MainCredential 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.database.toCompressionAlgorithm
import com.kunzisoft.keepass.database.element.node.Node import com.kunzisoft.keepass.database.element.node.Node
import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.Type import com.kunzisoft.keepass.database.element.node.Type
@ -78,9 +77,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
private var mDatabaseInfoListeners = mutableListOf<DatabaseInfoListener>() private var mDatabaseInfoListeners = mutableListOf<DatabaseInfoListener>()
private var mActionTaskBinder = ActionTaskBinder() private var mActionTaskBinder = ActionTaskBinder()
private var mActionTaskListeners = mutableListOf<ActionTaskListener>() private var mActionTaskListeners = mutableListOf<ActionTaskListener>()
// Channel to connect asynchronously a response
// Channel to connect asynchronously a listener or a response
private var mRequestChallengeListenerChannel: Channel<RequestChallengeListener>? = null
private var mResponseChallengeChannel: Channel<ByteArray?>? = null private var mResponseChallengeChannel: Channel<ByteArray?>? = null
private var mActionRunning = 0 private var mActionRunning = 0
@ -829,7 +826,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(MAIN_CREDENTIAL_KEY) && intent.hasExtra(MAIN_CREDENTIAL_KEY)
) { ) {
val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null
AssignMainCredentialInDatabaseRunnable(this, com.kunzisoft.keepass.database.action.AssignMainCredentialInDatabaseRunnable(
this,
database, database,
databaseUri, databaseUri,
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential() intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential()
@ -1116,8 +1114,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(SAVE_DATABASE_KEY) && intent.hasExtra(SAVE_DATABASE_KEY)
) { ) {
val oldElement: NamedCompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY) val oldElement: CompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY)
val newElement: NamedCompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY) val newElement: CompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY)
if (oldElement == null if (oldElement == null
|| newElement == null || newElement == null
@ -1126,8 +1124,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return UpdateCompressionBinariesDatabaseRunnable(this, return UpdateCompressionBinariesDatabaseRunnable(this,
database, database,
oldElement.toCompressionAlgorithm(), oldElement,
newElement.toCompressionAlgorithm(), newElement,
!database.isReadOnly && intent.getBooleanExtra(SAVE_DATABASE_KEY, false) !database.isReadOnly && intent.getBooleanExtra(SAVE_DATABASE_KEY, false)
) { hardwareKey, seed -> ) { hardwareKey, seed ->
retrieveResponseFromChallenge(hardwareKey, seed) retrieveResponseFromChallenge(hardwareKey, seed)

View file

@ -37,10 +37,8 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Group 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.database.element.database.toCompressionAlgorithm import com.kunzisoft.keepass.database.helper.*
import com.kunzisoft.keepass.database.element.database.toNamedCompressionAlgorithm
import com.kunzisoft.keepass.database.element.template.TemplateEngine
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
import com.kunzisoft.keepass.settings.preference.* import com.kunzisoft.keepass.settings.preference.*
import com.kunzisoft.keepass.settings.preferencedialogfragment.* import com.kunzisoft.keepass.settings.preferencedialogfragment.*
@ -200,8 +198,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
// Database compression // Database compression
dbDataCompressionPref = findPreference(getString(R.string.database_data_compression_key)) dbDataCompressionPref = findPreference(getString(R.string.database_data_compression_key))
if (database.allowDataCompression) { if (database.allowDataCompression) {
dbDataCompressionPref?.summary = (database.compressionAlgorithm?.toNamedCompressionAlgorithm() dbDataCompressionPref?.summary = (database.compressionAlgorithm
?: NamedCompressionAlgorithm.None).getName(resources) ?: CompressionAlgorithm.NONE).getLocalizedName(resources)
} else { } else {
dbCompressionPrefCategory?.isVisible = false dbCompressionPrefCategory?.isVisible = false
} }
@ -435,16 +433,16 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
dbCustomColorPref?.summary = defaultColorToShow dbCustomColorPref?.summary = defaultColorToShow
} }
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> { DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> {
val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as NamedCompressionAlgorithm val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as CompressionAlgorithm
val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as NamedCompressionAlgorithm val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as CompressionAlgorithm
val algorithmToShow = val algorithmToShow =
if (result.isSuccess) { if (result.isSuccess) {
newCompression newCompression
} else { } else {
mDatabase?.compressionAlgorithm = oldCompression.toCompressionAlgorithm() mDatabase?.compressionAlgorithm = oldCompression
oldCompression oldCompression
} }
dbDataCompressionPref?.summary = algorithmToShow.getName(resources) dbDataCompressionPref?.summary = algorithmToShow.getLocalizedName(resources)
} }
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_RECYCLE_BIN_TASK -> { DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_RECYCLE_BIN_TASK -> {
val oldRecycleBin = data.getParcelable<Group?>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) val oldRecycleBin = data.getParcelable<Group?>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)

View file

@ -35,15 +35,9 @@ import com.kunzisoft.keepass.database.search.SearchParameters
import com.kunzisoft.keepass.education.Education import com.kunzisoft.keepass.education.Education
import com.kunzisoft.keepass.magikeyboard.MagikeyboardService import com.kunzisoft.keepass.magikeyboard.MagikeyboardService
import com.kunzisoft.keepass.password.PassphraseGenerator 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.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.UriUtil import com.kunzisoft.keepass.utils.UriUtil
import java.util.Properties import java.util.*
object PreferencesUtil { object PreferencesUtil {
@ -67,8 +61,7 @@ object PreferencesUtil {
fun saveNodeSort(context: Context, fun saveNodeSort(context: Context,
sortNodeEnum: SortNodeEnum, sortNodeEnum: SortNodeEnum,
sortNodeParameters: SortNodeEnum.SortNodeParameters sortNodeParameters: SortNodeEnum.SortNodeParameters) {
) {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs?.edit()?.apply { prefs?.edit()?.apply {
putString(context.getString(R.string.sort_node_key), sortNodeEnum.name) putString(context.getString(R.string.sort_node_key), sortNodeEnum.name)
@ -115,6 +108,12 @@ object PreferencesUtil {
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 { fun showEntryColors(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.show_entry_colors_key), return prefs.getBoolean(context.getString(R.string.show_entry_colors_key),
@ -157,6 +156,12 @@ object PreferencesUtil {
context.resources.getBoolean(R.bool.show_uuid_default)) 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 { fun getStyle(context: Context): String {
val defaultStyleString = Stylish.defaultStyle(context) val defaultStyleString = Stylish.defaultStyle(context)
val styleString = PreferenceManager.getDefaultSharedPreferences(context) val styleString = PreferenceManager.getDefaultSharedPreferences(context)
@ -194,7 +199,8 @@ object PreferencesUtil {
fun getListTextSize(context: Context): Float { fun getListTextSize(context: Context): Float {
val index = try { val index = try {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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) context.resources.getStringArray(R.array.list_size_string_values).indexOf(listSizeString)
} catch (e: Exception) { } catch (e: Exception) {
1 1
@ -207,7 +213,8 @@ object PreferencesUtil {
fun getDefaultPasswordLength(context: Context): Int { fun getDefaultPasswordLength(context: Context): Int {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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) { fun setDefaultPasswordLength(context: Context, passwordLength: Int) {
@ -239,7 +246,8 @@ object PreferencesUtil {
fun getDefaultPasswordConsiderChars(context: Context): String { fun getDefaultPasswordConsiderChars(context: Context): String {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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) { fun setDefaultPasswordConsiderChars(context: Context, considerChars: String) {
@ -254,7 +262,8 @@ object PreferencesUtil {
fun getDefaultPasswordIgnoreChars(context: Context): String { fun getDefaultPasswordIgnoreChars(context: Context): String {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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) { fun setDefaultPasswordIgnoreChars(context: Context, ignoreChars: String) {
@ -269,7 +278,8 @@ object PreferencesUtil {
fun getDefaultPassphraseWordCount(context: Context): Int { fun getDefaultPassphraseWordCount(context: Context): Int {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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) { fun setDefaultPassphraseWordCount(context: Context, passphraseWordCount: Int) {
@ -284,8 +294,8 @@ object PreferencesUtil {
fun getDefaultPassphraseWordCase(context: Context): PassphraseGenerator.WordCase { fun getDefaultPassphraseWordCase(context: Context): PassphraseGenerator.WordCase {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return PassphraseGenerator.WordCase.getByOrdinal( return PassphraseGenerator.WordCase
prefs.getInt(context .getByOrdinal(prefs.getInt(context
.getString(R.string.passphrase_generator_word_case_key), .getString(R.string.passphrase_generator_word_case_key),
0) 0)
) )
@ -404,44 +414,75 @@ object PreferencesUtil {
*/ */
fun saveCurrentTime(context: Context) { fun saveCurrentTime(context: Context) {
PreferenceManager.getDefaultSharedPreferences(context).edit().apply { PreferenceManager.getDefaultSharedPreferences(context).edit().apply {
putLong(TIMEOUT_BACKUP_KEY, System.currentTimeMillis()) putLong(context.getString(R.string.timeout_backup_key), System.currentTimeMillis())
apply() 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 { fun getClipboardTimeout(context: Context): Long {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun getAdvancedUnlockTimeout(context: Context): Long {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun isLockDatabaseWhenScreenShutOffEnable(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun isLockDatabaseWhenBackButtonOnRootClicked(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun showLockDatabaseButton(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun isAutoSaveDatabaseEnabled(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun isKeepScreenOnEnabled(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) 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 { fun isScreenshotModeEnabled(context: Context): Boolean {
@ -552,6 +593,13 @@ object PreferencesUtil {
.apply() .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 { fun emptyPasswordAllowed(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context) val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.allow_no_password_key), return prefs.getBoolean(context.getString(R.string.allow_no_password_key),
@ -706,8 +754,7 @@ object PreferencesUtil {
fun getAppProperties(context: Context): Properties { fun getAppProperties(context: Context): Properties {
val properties = Properties() val properties = Properties()
for ((name, value) in PreferenceManager.getDefaultSharedPreferences( for ((name, value) in PreferenceManager.getDefaultSharedPreferences(context).all) {
context).all) {
properties[name] = value.toString() properties[name] = value.toString()
} }
for ((name, value) in Education.getEducationSharedPreferences(context).all) { for ((name, value) in Education.getEducationSharedPreferences(context).all) {
@ -732,7 +779,7 @@ object PreferencesUtil {
for ((name, value) in properties) { for ((name, value) in properties) {
try { try {
putProperty(this, name as String, value as String) 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) 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_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.enable_keep_screen_on_key) -> editor.putBoolean(name, value.toBoolean())
context.getString(R.string.auto_focus_search_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()) context.getString(R.string.subdomain_search_key) -> editor.putBoolean(name, value.toBoolean())
APP_TIMEOUT_KEY -> editor.putString(name, value.toLong().toString()) 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_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_back_root_key) -> editor.putBoolean(name, value.toBoolean())
context.getString(R.string.lock_database_show_button_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_key) -> setStyle(context, value)
context.getString(R.string.setting_style_brightness_key) -> editor.putString(name, 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.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.hide_password_key) -> editor.putBoolean(name, value.toBoolean())
context.getString(R.string.colorize_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.show_uuid_key) -> editor.putBoolean(name, value.toBoolean())
context.getString(R.string.list_size_key) -> editor.putString(name, value) 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()) 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.enable_education_screens_key) -> editor.putBoolean(name, value.toBoolean())
context.getString(R.string.password_generator_length_key) -> editor.putInt(name, value.toInt()) context.getString(R.string.password_generator_length_key) -> editor.putInt(name, value.toInt())
@ -822,13 +869,8 @@ object PreferencesUtil {
} }
putPropertiesInPreferences(properties, putPropertiesInPreferences(properties,
Education.getEducationSharedPreferences( Education.getEducationSharedPreferences(context)) { editor, name, value ->
context)) { editor, name, value -> Education.putPropertiesInEducationPreferences(context, editor, name, value)
Education.putPropertiesInEducationPreferences(
context,
editor,
name,
value)
} }
} }
} }

View file

@ -25,18 +25,16 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database 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.element.database.toCompressionAlgorithm
import com.kunzisoft.keepass.database.element.database.toNamedCompressionAlgorithm
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
class DatabaseDataCompressionPreferenceDialogFragmentCompat class DatabaseDataCompressionPreferenceDialogFragmentCompat
: DatabaseSavePreferenceDialogFragmentCompat(), : DatabaseSavePreferenceDialogFragmentCompat(),
ListRadioItemAdapter.RadioItemSelectedCallback<NamedCompressionAlgorithm> { ListRadioItemAdapter.RadioItemSelectedCallback<CompressionAlgorithm> {
private var mRecyclerView: RecyclerView? = null private var mRecyclerView: RecyclerView? = null
private var mCompressionAdapter: ListRadioItemAdapter<NamedCompressionAlgorithm>? = null private var mCompressionAdapter: ListRadioItemAdapter<CompressionAlgorithm>? = null
private var compressionSelected: NamedCompressionAlgorithm? = null private var compressionSelected: CompressionAlgorithm? = null
override fun onBindDialogView(view: View) { override fun onBindDialogView(view: View) {
super.onBindDialogView(view) super.onBindDialogView(view)
@ -47,7 +45,7 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
mRecyclerView?.layoutManager = LinearLayoutManager(context) mRecyclerView?.layoutManager = LinearLayoutManager(context)
activity?.let { activity -> activity?.let { activity ->
mCompressionAdapter = ListRadioItemAdapter<NamedCompressionAlgorithm>(activity) mCompressionAdapter = ListRadioItemAdapter<CompressionAlgorithm>(activity)
mCompressionAdapter?.setRadioItemSelectedCallback(this) mCompressionAdapter?.setRadioItemSelectedCallback(this)
} }
} }
@ -59,8 +57,8 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
mRecyclerView?.adapter = mCompressionAdapter mRecyclerView?.adapter = mCompressionAdapter
database?.let { database?.let {
compressionSelected = it.compressionAlgorithm?.toNamedCompressionAlgorithm() compressionSelected = it.compressionAlgorithm
mCompressionAdapter?.setItems(it.availableCompressionAlgorithms.map { it.toNamedCompressionAlgorithm() }, compressionSelected) mCompressionAdapter?.setItems(it.availableCompressionAlgorithms, compressionSelected)
} }
} }
@ -71,16 +69,16 @@ class DatabaseDataCompressionPreferenceDialogFragmentCompat
if (compressionSelected != null) { if (compressionSelected != null) {
val newCompression = compressionSelected val newCompression = compressionSelected
val oldCompression = database.compressionAlgorithm val oldCompression = database.compressionAlgorithm
database.compressionAlgorithm = newCompression?.toCompressionAlgorithm() database.compressionAlgorithm = newCompression
if (oldCompression != null && newCompression != null) 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 this.compressionSelected = item
} }

View file

@ -28,7 +28,7 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Group 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.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.viewmodels.DatabaseViewModel import com.kunzisoft.keepass.viewmodels.DatabaseViewModel
@ -90,8 +90,8 @@ abstract class DatabaseSavePreferenceDialogFragmentCompat
mDatabaseViewModel.saveColor(oldColorString, newColorString, mDatabaseAutoSaveEnable) mDatabaseViewModel.saveColor(oldColorString, newColorString, mDatabaseAutoSaveEnable)
} }
protected fun saveCompression(oldCompression: NamedCompressionAlgorithm, protected fun saveCompression(oldCompression: CompressionAlgorithm,
newCompression: NamedCompressionAlgorithm newCompression: CompressionAlgorithm
) { ) {
mDatabaseViewModel.saveCompression(oldCompression, newCompression, mDatabaseAutoSaveEnable) mDatabaseViewModel.saveCompression(oldCompression, newCompression, mDatabaseAutoSaveEnable)
} }

View file

@ -25,7 +25,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import com.kunzisoft.keepass.settings.DatabasePreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.LOCK_ACTION import com.kunzisoft.keepass.utils.LOCK_ACTION
object TimeoutHelper { object TimeoutHelper {
@ -59,7 +59,7 @@ object TimeoutHelper {
*/ */
private fun startLockTimer(context: Context, databaseLoaded: Boolean) { private fun startLockTimer(context: Context, databaseLoaded: Boolean) {
if (databaseLoaded) { if (databaseLoaded) {
val timeout = DatabasePreferencesUtil.getAppTimeout(context) val timeout = PreferencesUtil.getAppTimeout(context)
if (timeout != NEVER) { if (timeout != NEVER) {
// No timeout don't start timeout service // No timeout don't start timeout service
(context.applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager?)?.let { alarmManager -> (context.applicationContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager?)?.let { alarmManager ->
@ -111,7 +111,7 @@ object TimeoutHelper {
|| lastAppTimeoutRecord!! + 2000 <= System.currentTimeMillis()) { || lastAppTimeoutRecord!! + 2000 <= System.currentTimeMillis()) {
Log.d(TAG, "Record app timeout") Log.d(TAG, "Record app timeout")
// Record timeout time in case timeout service is killed // Record timeout time in case timeout service is killed
DatabasePreferencesUtil.saveCurrentTime(context) PreferencesUtil.saveCurrentTime(context)
startLockTimer(context, databaseLoaded) startLockTimer(context, databaseLoaded)
lastAppTimeoutRecord = System.currentTimeMillis() lastAppTimeoutRecord = System.currentTimeMillis()
} }
@ -131,14 +131,14 @@ object TimeoutHelper {
val currentTime = System.currentTimeMillis() val currentTime = System.currentTimeMillis()
// Retrieve the timeout programmatically backup // Retrieve the timeout programmatically backup
val timeoutBackup = DatabasePreferencesUtil.getTimeSaved(context) val timeoutBackup = PreferencesUtil.getTimeSaved(context)
// The timeout never started // The timeout never started
if (timeoutBackup == NEVER) { if (timeoutBackup == NEVER) {
return true return true
} }
// Retrieve the app timeout in settings // Retrieve the app timeout in settings
val appTimeout = DatabasePreferencesUtil.getAppTimeout((context)) val appTimeout = PreferencesUtil.getAppTimeout((context))
// We are set to never timeout // We are set to never timeout
if (appTimeout == NEVER) { if (appTimeout == NEVER) {
return true return true

View file

@ -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_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 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 REMOVE_ENTRY_MAGIKEYBOARD_ACTION = "com.kunzisoft.keepass.REMOVE_ENTRY_MAGIKEYBOARD"
const val BACK_PREVIOUS_KEYBOARD_ACTION = "com.kunzisoft.keepass.BACK_PREVIOUS_KEYBOARD" const val BACK_PREVIOUS_KEYBOARD_ACTION = "com.kunzisoft.keepass.BACK_PREVIOUS_KEYBOARD"

View file

@ -17,7 +17,7 @@
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>. * along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.kunzisoft.keepass.app.database package com.kunzisoft.keepass.utils
import kotlinx.coroutines.* import kotlinx.coroutines.*

View file

@ -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)
}
}
}
}

View file

@ -11,7 +11,7 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.kunzisoft.keepass.R 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.database.search.SearchParameters
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil

View file

@ -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.TemplateAttribute
import com.kunzisoft.keepass.database.element.template.TemplateAttributeAction import com.kunzisoft.keepass.database.element.template.TemplateAttributeAction
import com.kunzisoft.keepass.database.element.template.TemplateField 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 com.kunzisoft.keepass.otp.OtpEntryFields
import org.joda.time.DateTime import org.joda.time.DateTime

View file

@ -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.security.ProtectedString
import com.kunzisoft.keepass.database.element.template.TemplateAttribute import com.kunzisoft.keepass.database.element.template.TemplateAttribute
import com.kunzisoft.keepass.database.element.template.TemplateField 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.model.OtpModel
import com.kunzisoft.keepass.otp.OtpElement import com.kunzisoft.keepass.otp.OtpElement
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD

View file

@ -21,7 +21,7 @@ import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.template.TemplateField 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.password.PasswordGenerator
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil

View file

@ -39,7 +39,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.template.TemplateField 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.model.EntryInfo.Companion.APPLICATION_ID_FIELD_NAME
import com.kunzisoft.keepass.password.PasswordGenerator import com.kunzisoft.keepass.password.PasswordGenerator
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil

View file

@ -49,7 +49,7 @@ import androidx.core.view.updatePadding
import com.google.android.material.appbar.CollapsingToolbarLayout import com.google.android.material.appbar.CollapsingToolbarLayout
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.kunzisoft.keepass.R 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.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable import com.kunzisoft.keepass.tasks.ActionRunnable

View file

@ -6,7 +6,7 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.kunzisoft.keepass.app.App import com.kunzisoft.keepass.app.App
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction 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.model.DatabaseFile
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.UriUtil import com.kunzisoft.keepass.utils.UriUtil

View file

@ -6,7 +6,7 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.kunzisoft.keepass.app.App import com.kunzisoft.keepass.app.App
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction 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.hardware.HardwareKey
import com.kunzisoft.keepass.model.DatabaseFile import com.kunzisoft.keepass.model.DatabaseFile
import com.kunzisoft.keepass.settings.PreferencesUtil import com.kunzisoft.keepass.settings.PreferencesUtil

View file

@ -7,7 +7,7 @@ import com.kunzisoft.keepass.database.crypto.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.Group 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 import com.kunzisoft.keepass.tasks.ActionRunnable
class DatabaseViewModel: ViewModel() { class DatabaseViewModel: ViewModel() {
@ -119,8 +119,8 @@ class DatabaseViewModel: ViewModel() {
_saveColor.value = SuperString(oldValue, newValue, save) _saveColor.value = SuperString(oldValue, newValue, save)
} }
fun saveCompression(oldValue: NamedCompressionAlgorithm, fun saveCompression(oldValue: CompressionAlgorithm,
newValue: NamedCompressionAlgorithm, newValue: CompressionAlgorithm,
save: Boolean) { save: Boolean) {
_saveCompression.value = SuperCompression(oldValue, newValue, save) _saveCompression.value = SuperCompression(oldValue, newValue, save)
} }
@ -198,8 +198,8 @@ class DatabaseViewModel: ViewModel() {
val save: Boolean) val save: Boolean)
data class SuperMerge(val fixDuplicateUuid: Boolean, data class SuperMerge(val fixDuplicateUuid: Boolean,
val save: Boolean) val save: Boolean)
data class SuperCompression(val oldValue: NamedCompressionAlgorithm, data class SuperCompression(val oldValue: CompressionAlgorithm,
val newValue: NamedCompressionAlgorithm, val newValue: CompressionAlgorithm,
val save: Boolean) val save: Boolean)
data class SuperEncryption(val oldValue: EncryptionAlgorithm, data class SuperEncryption(val oldValue: EncryptionAlgorithm,
val newValue: EncryptionAlgorithm, val newValue: EncryptionAlgorithm,

View file

@ -3,7 +3,7 @@ package com.kunzisoft.keepass.viewmodels
import android.net.Uri import android.net.Uri
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData 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.*
import com.kunzisoft.keepass.database.element.icon.IconImage import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageStandard import com.kunzisoft.keepass.database.element.icon.IconImageStandard

View file

@ -22,7 +22,7 @@ package com.kunzisoft.keepass.viewmodels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel 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.Attachment
import com.kunzisoft.keepass.database.element.Database import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.NodeId

View file

@ -22,11 +22,11 @@ package com.kunzisoft.keepass.viewmodels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel 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.Database
import com.kunzisoft.keepass.database.element.Group import com.kunzisoft.keepass.database.element.Group
import com.kunzisoft.keepass.database.element.node.NodeId 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 import com.kunzisoft.keepass.database.search.SearchParameters

View file

@ -14,13 +14,6 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro" consumerProguardFiles "consumer-rules.pro"
kapt {
arguments {
arg("room.incremental", "true")
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}
} }
buildTypes { buildTypes {
@ -38,8 +31,6 @@ android {
} }
} }
def room_version = "2.4.3"
dependencies { dependencies {
implementation "androidx.core:core-ktx:$android_core_version" implementation "androidx.core:core-ktx:$android_core_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' 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-io:commons-io:2.8.0'
implementation 'commons-codec:commons-codec:1.15' 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') implementation project(path: ':crypto')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
} }

View file

@ -21,12 +21,10 @@ package com.kunzisoft.keepass.database.element
import android.content.ContentResolver import android.content.ContentResolver
import android.content.Context import android.content.Context
import android.content.res.Resources
import android.graphics.Color import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.util.Log import android.util.Log
import com.kunzisoft.androidclearchroma.ChromaUtil 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.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.element.binary.AttachmentPool 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.IconImageCustom
import com.kunzisoft.keepass.database.element.icon.IconImageStandard import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.database.element.icon.IconsManager 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.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdInt import com.kunzisoft.keepass.database.element.node.NodeIdInt
import com.kunzisoft.keepass.database.element.node.NodeIdUUID import com.kunzisoft.keepass.database.element.node.NodeIdUUID
@ -301,7 +300,7 @@ class Database(private val iconPackChooser: InterfaceIconPackChooser) {
return false return false
// Default compression not necessary if stored in header // Default compression not necessary if stored in header
mDatabaseKDBX?.let { mDatabaseKDBX?.let {
return it.compressionAlgorithm == CompressionAlgorithm.GZip return it.compressionAlgorithm == CompressionAlgorithm.GZIP
&& it.kdbxVersion.isBefore(FILE_VERSION_40) && it.kdbxVersion.isBefore(FILE_VERSION_40)
} }
return false return false

View file

@ -30,7 +30,6 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.node.* import com.kunzisoft.keepass.database.element.node.*
import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.GroupInfo import com.kunzisoft.keepass.model.GroupInfo
import com.kunzisoft.keepass.settings.DatabasePreferencesUtil
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
@ -86,8 +85,8 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
META_STREAM, EXPIRED; META_STREAM, EXPIRED;
companion object { companion object {
fun getDefaults(context: Context): Array<ChildFilter> { fun getDefaults(showExpiredEntries: Boolean): Array<ChildFilter> {
return if (DatabasePreferencesUtil.showExpiredEntries(context)) { return if (showExpiredEntries) {
arrayOf(META_STREAM) arrayOf(META_STREAM)
} else { } else {
arrayOf(META_STREAM, EXPIRED) arrayOf(META_STREAM, EXPIRED)

View file

@ -19,7 +19,33 @@
*/ */
package com.kunzisoft.keepass.database.element.database package com.kunzisoft.keepass.database.element.database
enum class CompressionAlgorithm { import android.os.Parcel
None, import android.os.Parcelable
GZip; 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<CompressionAlgorithm> {
override fun createFromParcel(parcel: Parcel): CompressionAlgorithm {
return parcel.readEnum<CompressionAlgorithm>() ?: NONE
}
override fun newArray(size: Int): Array<CompressionAlgorithm?> {
return arrayOfNulls(size)
}
}
} }

View file

@ -20,24 +20,16 @@
package com.kunzisoft.keepass.database.element.database package com.kunzisoft.keepass.database.element.database
import android.content.ContentResolver import android.content.ContentResolver
import android.content.res.Resources
import android.util.Base64 import android.util.Base64
import android.util.Log import android.util.Log
import com.kunzisoft.encrypt.HashManager 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.EncryptionAlgorithm
import com.kunzisoft.keepass.database.crypto.VariantDictionary import com.kunzisoft.keepass.database.crypto.VariantDictionary
import com.kunzisoft.keepass.database.crypto.kdf.AesKdf import com.kunzisoft.keepass.database.crypto.kdf.AesKdf
import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine import com.kunzisoft.keepass.database.crypto.kdf.KdfEngine
import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory
import com.kunzisoft.keepass.database.crypto.kdf.KdfParameters import com.kunzisoft.keepass.database.crypto.kdf.KdfParameters
import com.kunzisoft.keepass.database.element.CompositeKey import com.kunzisoft.keepass.database.element.*
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.binary.BinaryData 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.database.DatabaseKDB.Companion.BACKUP_FOLDER_TITLE
import com.kunzisoft.keepass.database.element.entry.EntryKDBX 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.group.GroupKDBX
import com.kunzisoft.keepass.database.element.icon.IconImageCustom import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.database.element.icon.IconImageStandard import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.database.element.node.NodeId import com.kunzisoft.keepass.database.element.node.*
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.security.MemoryProtectionConfig import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig
import com.kunzisoft.keepass.database.element.template.Template import com.kunzisoft.keepass.database.element.template.Template
import com.kunzisoft.keepass.database.element.template.TemplateEngineCompatible import com.kunzisoft.keepass.database.element.template.TemplateEngineCompatible
@ -63,8 +52,7 @@ import java.io.IOException
import java.nio.charset.Charset import java.nio.charset.Charset
import java.security.MessageDigest import java.security.MessageDigest
import java.security.NoSuchAlgorithmException import java.security.NoSuchAlgorithmException
import java.util.Arrays import java.util.*
import java.util.UUID
import javax.crypto.Mac import javax.crypto.Mac
import kotlin.math.min import kotlin.math.min
@ -127,7 +115,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
KdfFactory.argon2idKdf KdfFactory.argon2idKdf
) )
var compressionAlgorithm = CompressionAlgorithm.GZip var compressionAlgorithm = CompressionAlgorithm.GZIP
private val mFieldReferenceEngine = FieldReferencesEngine(this) private val mFieldReferenceEngine = FieldReferencesEngine(this)
private val mTemplateEngine = TemplateEngineCompatible(this) private val mTemplateEngine = TemplateEngineCompatible(this)
@ -353,8 +341,8 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
} }
val availableCompressionAlgorithms: List<CompressionAlgorithm> = listOf( val availableCompressionAlgorithms: List<CompressionAlgorithm> = listOf(
CompressionAlgorithm.None, CompressionAlgorithm.NONE,
CompressionAlgorithm.GZip CompressionAlgorithm.GZIP
) )
fun changeBinaryCompression( fun changeBinaryCompression(
@ -362,11 +350,11 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
newCompression: CompressionAlgorithm, newCompression: CompressionAlgorithm,
) { ) {
when (oldCompression) { when (oldCompression) {
CompressionAlgorithm.None -> { CompressionAlgorithm.NONE -> {
when (newCompression) { when (newCompression) {
CompressionAlgorithm.None -> { CompressionAlgorithm.NONE -> {
} }
CompressionAlgorithm.GZip -> { CompressionAlgorithm.GZIP -> {
// Only in databaseV3.1, in databaseV4 the header is zipped during the save // Only in databaseV3.1, in databaseV4 the header is zipped during the save
if (kdbxVersion.isBefore(FILE_VERSION_40)) { if (kdbxVersion.isBefore(FILE_VERSION_40)) {
compressAllBinaries() compressAllBinaries()
@ -374,14 +362,14 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
} }
} }
} }
CompressionAlgorithm.GZip -> { CompressionAlgorithm.GZIP -> {
// In databaseV4 the header is zipped during the save, so not necessary here // In databaseV4 the header is zipped during the save, so not necessary here
if (kdbxVersion.isBefore(FILE_VERSION_40)) { if (kdbxVersion.isBefore(FILE_VERSION_40)) {
when (newCompression) { when (newCompression) {
CompressionAlgorithm.None -> { CompressionAlgorithm.NONE -> {
decompressAllBinaries() decompressAllBinaries()
} }
CompressionAlgorithm.GZip -> { CompressionAlgorithm.GZIP -> {
} }
} }
} else { } else {

View file

@ -19,7 +19,7 @@
*/ */
package com.kunzisoft.keepass.database.element.group 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 import com.kunzisoft.keepass.database.element.node.NodeVersionedInterface
interface GroupVersionedInterface<Group: GroupVersionedInterface<Group, Entry>, Entry> : NodeVersionedInterface<Group> { interface GroupVersionedInterface<Group: GroupVersionedInterface<Group, Entry>, Entry> : NodeVersionedInterface<Group> {

View file

@ -17,7 +17,7 @@
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>. * along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
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 /** "Delegate" class for operating on each group when traversing all of

View file

@ -256,15 +256,15 @@ class DatabaseHeaderKDBX(private val databaseV4: DatabaseKDBX) : DatabaseHeader(
fun getCompressionFromFlag(flag: UnsignedInt): CompressionAlgorithm? { fun getCompressionFromFlag(flag: UnsignedInt): CompressionAlgorithm? {
return when (flag.toKotlinInt()) { return when (flag.toKotlinInt()) {
0 -> CompressionAlgorithm.None 0 -> CompressionAlgorithm.NONE
1 -> CompressionAlgorithm.GZip 1 -> CompressionAlgorithm.GZIP
else -> null else -> null
} }
} }
fun getFlagFromCompression(compression: CompressionAlgorithm): UnsignedInt { fun getFlagFromCompression(compression: CompressionAlgorithm): UnsignedInt {
return when (compression) { return when (compression) {
CompressionAlgorithm.GZip -> UnsignedInt(1) CompressionAlgorithm.GZIP -> UnsignedInt(1)
else -> UnsignedInt(0) else -> UnsignedInt(0)
} }
} }

View file

@ -179,7 +179,7 @@ class DatabaseInputKDBX(database: DatabaseKDBX)
} }
val inputStreamXml: InputStream = when (mDatabase.compressionAlgorithm) { val inputStreamXml: InputStream = when (mDatabase.compressionAlgorithm) {
CompressionAlgorithm.GZip -> GZIPInputStream(plainInputStream) CompressionAlgorithm.GZIP -> GZIPInputStream(plainInputStream)
else -> plainInputStream else -> plainInputStream
} }

View file

@ -23,7 +23,6 @@ import android.util.Base64
import android.util.Log import android.util.Log
import android.util.Xml import android.util.Xml
import com.kunzisoft.encrypt.StreamCipher 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.CrsAlgorithm
import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory import com.kunzisoft.keepass.database.crypto.kdf.KdfFactory
import com.kunzisoft.keepass.database.element.* 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.AutoType
import com.kunzisoft.keepass.database.element.entry.EntryKDBX import com.kunzisoft.keepass.database.element.entry.EntryKDBX
import com.kunzisoft.keepass.database.element.group.GroupKDBX 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.node.NodeKDBXInterface
import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig
import com.kunzisoft.keepass.database.exception.DatabaseOutputException import com.kunzisoft.keepass.database.exception.DatabaseOutputException
@ -85,7 +85,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX)
} }
when(mDatabaseKDBX.compressionAlgorithm) { when(mDatabaseKDBX.compressionAlgorithm) {
CompressionAlgorithm.GZip -> GZIPOutputStream(osPlain) CompressionAlgorithm.GZIP -> GZIPOutputStream(osPlain)
else -> osPlain else -> osPlain
}.use { xmlOutputStream -> }.use { xmlOutputStream ->
if (!header!!.version.isBefore(FILE_VERSION_40)) { if (!header!!.version.isBefore(FILE_VERSION_40)) {

View file

@ -19,7 +19,6 @@
*/ */
package com.kunzisoft.keepass.database.merge 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.Attachment
import com.kunzisoft.keepass.database.element.CustomData import com.kunzisoft.keepass.database.element.CustomData
import com.kunzisoft.keepass.database.element.DateInstant 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.entry.EntryKDBX
import com.kunzisoft.keepass.database.element.group.GroupKDB import com.kunzisoft.keepass.database.element.group.GroupKDB
import com.kunzisoft.keepass.database.element.group.GroupKDBX 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.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdInt import com.kunzisoft.keepass.database.element.node.NodeIdInt
import com.kunzisoft.keepass.database.element.node.NodeIdUUID import com.kunzisoft.keepass.database.element.node.NodeIdUUID

View file

@ -19,16 +19,12 @@
*/ */
package com.kunzisoft.keepass.database.search 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.Database
import com.kunzisoft.keepass.database.element.Entry import com.kunzisoft.keepass.database.element.Entry
import com.kunzisoft.keepass.database.element.Group 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.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.otp.OtpEntryFields.OTP_FIELD
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.UuidUtil import com.kunzisoft.keepass.utils.UuidUtil
class SearchHelper { class SearchHelper {
@ -120,53 +116,6 @@ class SearchHelper {
} }
companion object { 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<EntryInfo>) -> 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 * Return true if the search query in search parameters is found in available parameters

View file

@ -1,17 +1,11 @@
package com.kunzisoft.keepass.model package com.kunzisoft.keepass.model
import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import android.net.Uri import android.net.Uri
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import com.kunzisoft.keepass.otp.OtpEntryFields import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.settings.DatabasePreferencesUtil
import com.kunzisoft.keepass.utils.ObjectNameResource 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 { class SearchInfo : ObjectNameResource, Parcelable {
var manualSelection: Boolean = false var manualSelection: Boolean = false
@ -131,28 +125,5 @@ class SearchInfo : ObjectNameResource, Parcelable {
return arrayOfNulls(size) 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)
}
}
}
} }
} }

View file

@ -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
}
}
}

View file

@ -1,3 +0,0 @@
package com.kunzisoft.keepass.utils
const val LOCK_ACTION = "com.kunzisoft.keepass.LOCK"