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