mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add priority to OTP button in notification #845
This commit is contained in:
@@ -95,10 +95,6 @@ class EntryInfo : Parcelable {
|
|||||||
return customFields.lastOrNull { it.name == label } != null
|
return customFields.lastOrNull { it.name == label } != null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isAutoGeneratedField(field: Field): Boolean {
|
|
||||||
return field.name == OTP_TOKEN_FIELD
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getGeneratedFieldValue(label: String): String {
|
fun getGeneratedFieldValue(label: String): String {
|
||||||
if (label == OTP_TOKEN_FIELD) {
|
if (label == OTP_TOKEN_FIELD) {
|
||||||
otpModel?.let {
|
otpModel?.let {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.os.Parcel
|
|||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.kunzisoft.keepass.model.EntryInfo
|
import com.kunzisoft.keepass.model.EntryInfo
|
||||||
|
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +55,7 @@ class ClipboardEntryNotificationField : Parcelable {
|
|||||||
NotificationFieldId.UNKNOWN -> ""
|
NotificationFieldId.UNKNOWN -> ""
|
||||||
NotificationFieldId.USERNAME -> entryInfo?.username ?: ""
|
NotificationFieldId.USERNAME -> entryInfo?.username ?: ""
|
||||||
NotificationFieldId.PASSWORD -> entryInfo?.password ?: ""
|
NotificationFieldId.PASSWORD -> entryInfo?.password ?: ""
|
||||||
|
NotificationFieldId.OTP -> entryInfo?.getGeneratedFieldValue(OTP_TOKEN_FIELD) ?: ""
|
||||||
NotificationFieldId.FIELD_A,
|
NotificationFieldId.FIELD_A,
|
||||||
NotificationFieldId.FIELD_B,
|
NotificationFieldId.FIELD_B,
|
||||||
NotificationFieldId.FIELD_C -> entryInfo?.getGeneratedFieldValue(label) ?: ""
|
NotificationFieldId.FIELD_C -> entryInfo?.getGeneratedFieldValue(label) ?: ""
|
||||||
@@ -81,7 +83,7 @@ class ClipboardEntryNotificationField : Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class NotificationFieldId {
|
enum class NotificationFieldId {
|
||||||
UNKNOWN, USERNAME, PASSWORD, FIELD_A, FIELD_B, FIELD_C;
|
UNKNOWN, USERNAME, PASSWORD, OTP, FIELD_A, FIELD_B, FIELD_C;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val anonymousFieldId: Array<NotificationFieldId>
|
val anonymousFieldId: Array<NotificationFieldId>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.content.Intent
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.kunzisoft.keepass.R
|
import com.kunzisoft.keepass.R
|
||||||
import com.kunzisoft.keepass.model.EntryInfo
|
import com.kunzisoft.keepass.model.EntryInfo
|
||||||
|
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||||
import com.kunzisoft.keepass.timeout.ClipboardHelper
|
import com.kunzisoft.keepass.timeout.ClipboardHelper
|
||||||
import com.kunzisoft.keepass.timeout.TimeoutHelper.NEVER
|
import com.kunzisoft.keepass.timeout.TimeoutHelper.NEVER
|
||||||
@@ -250,6 +251,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
|
|||||||
val containsUsernameToCopy = entry.username.isNotEmpty()
|
val containsUsernameToCopy = entry.username.isNotEmpty()
|
||||||
val containsPasswordToCopy = entry.password.isNotEmpty()
|
val containsPasswordToCopy = entry.password.isNotEmpty()
|
||||||
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(context)
|
&& PreferencesUtil.allowCopyPasswordAndProtectedFields(context)
|
||||||
|
val containsOTPToCopy = entry.containsCustomField(OTP_TOKEN_FIELD)
|
||||||
val containsExtraFieldToCopy = entry.customFields.isNotEmpty()
|
val containsExtraFieldToCopy = entry.customFields.isNotEmpty()
|
||||||
&& (entry.containsCustomFieldsNotProtected()
|
&& (entry.containsCustomFieldsNotProtected()
|
||||||
||
|
||
|
||||||
@@ -262,7 +264,10 @@ class ClipboardEntryNotificationService : LockNotificationService() {
|
|||||||
// If notifications enabled in settings
|
// If notifications enabled in settings
|
||||||
// Don't if application timeout
|
// Don't if application timeout
|
||||||
if (PreferencesUtil.isClipboardNotificationsEnable(context)) {
|
if (PreferencesUtil.isClipboardNotificationsEnable(context)) {
|
||||||
if (containsUsernameToCopy || containsPasswordToCopy || containsExtraFieldToCopy) {
|
if (containsUsernameToCopy
|
||||||
|
|| containsPasswordToCopy
|
||||||
|
|| containsOTPToCopy
|
||||||
|
|| containsExtraFieldToCopy) {
|
||||||
|
|
||||||
// username already copied, waiting for user's action before copy password.
|
// username already copied, waiting for user's action before copy password.
|
||||||
intent.action = ACTION_NEW_NOTIFICATION
|
intent.action = ACTION_NEW_NOTIFICATION
|
||||||
@@ -282,14 +287,22 @@ class ClipboardEntryNotificationService : LockNotificationService() {
|
|||||||
ClipboardEntryNotificationField.NotificationFieldId.PASSWORD,
|
ClipboardEntryNotificationField.NotificationFieldId.PASSWORD,
|
||||||
context.getString(R.string.entry_password)))
|
context.getString(R.string.entry_password)))
|
||||||
}
|
}
|
||||||
|
// Add OTP
|
||||||
|
if (containsOTPToCopy) {
|
||||||
|
notificationFields.add(
|
||||||
|
ClipboardEntryNotificationField(
|
||||||
|
ClipboardEntryNotificationField.NotificationFieldId.OTP,
|
||||||
|
OTP_TOKEN_FIELD))
|
||||||
|
}
|
||||||
// Add extra fields
|
// Add extra fields
|
||||||
if (containsExtraFieldToCopy) {
|
if (containsExtraFieldToCopy) {
|
||||||
try {
|
try {
|
||||||
var anonymousFieldNumber = 0
|
var anonymousFieldNumber = 0
|
||||||
entry.customFields.forEach { field ->
|
entry.customFields.forEach { field ->
|
||||||
//If value is not protected or allowed
|
//If value is not protected or allowed
|
||||||
if (!field.protectedValue.isProtected
|
if ((!field.protectedValue.isProtected
|
||||||
|| PreferencesUtil.allowCopyPasswordAndProtectedFields(context)) {
|
|| PreferencesUtil.allowCopyPasswordAndProtectedFields(context))
|
||||||
|
&& field.name != OTP_TOKEN_FIELD) {
|
||||||
notificationFields.add(
|
notificationFields.add(
|
||||||
ClipboardEntryNotificationField(
|
ClipboardEntryNotificationField(
|
||||||
ClipboardEntryNotificationField.NotificationFieldId.anonymousFieldId[anonymousFieldNumber],
|
ClipboardEntryNotificationField.NotificationFieldId.anonymousFieldId[anonymousFieldNumber],
|
||||||
|
|||||||
Reference in New Issue
Block a user