mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix registration expiration
This commit is contained in:
@@ -43,6 +43,7 @@ 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 org.joda.time.DateTime
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
|
||||
@@ -250,15 +251,15 @@ class KeeAutofillService : AutofillService() {
|
||||
&& autofillAllowedFor(parseResult.webDomain, webDomainBlocklist)) {
|
||||
Log.d(TAG, "autofill onSaveRequest password")
|
||||
|
||||
|
||||
if (parseResult.creditCardExpirationValue == null) {
|
||||
if (parseResult.creditCardExpirationMonthValue != 0 && parseResult.creditCardExpirationYearValue != 0) {
|
||||
parseResult.creditCardExpirationValue = parseResult.creditCardExpirationMonthValue.toString().padStart(2, '0') + parseResult.creditCardExpirationYearValue.toString()
|
||||
// Build expiration from date or from year and month
|
||||
var expiration: DateTime? = parseResult.creditCardExpirationValue
|
||||
if (parseResult.creditCardExpirationValue == null
|
||||
&& parseResult.creditCardExpirationYearValue != 0
|
||||
&& parseResult.creditCardExpirationMonthValue != 0) {
|
||||
expiration = DateTime()
|
||||
.withYear(parseResult.creditCardExpirationYearValue)
|
||||
.withMonthOfYear(parseResult.creditCardExpirationMonthValue)
|
||||
}
|
||||
}
|
||||
|
||||
val creditCard = CreditCard(parseResult.creditCardHolder, parseResult.creditCardNumber,
|
||||
parseResult.creditCardExpirationValue, parseResult.cardVerificationValue)
|
||||
|
||||
// Show UI to save data
|
||||
val registerInfo = RegisterInfo(
|
||||
@@ -269,7 +270,12 @@ class KeeAutofillService : AutofillService() {
|
||||
},
|
||||
parseResult.usernameValue?.textValue?.toString(),
|
||||
parseResult.passwordValue?.textValue?.toString(),
|
||||
creditCard)
|
||||
CreditCard(
|
||||
parseResult.creditCardHolder,
|
||||
parseResult.creditCardNumber,
|
||||
expiration,
|
||||
parseResult.cardVerificationValue
|
||||
))
|
||||
|
||||
// TODO Callback in each activity #765
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.view.View
|
||||
import android.view.autofill.AutofillId
|
||||
import android.view.autofill.AutofillValue
|
||||
import androidx.annotation.RequiresApi
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@@ -160,7 +161,13 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
node.autofillValue?.let { value ->
|
||||
if (value.isText && value.textValue.length == 7) {
|
||||
value.textValue.let { date ->
|
||||
result?.creditCardExpirationValue = date.substring(5, 7) + date.substring(2, 4)
|
||||
try {
|
||||
result?.creditCardExpirationValue = DateTime()
|
||||
.withYear(date.substring(2, 4).toInt())
|
||||
.withMonthOfYear(date.substring(5, 7).toInt())
|
||||
} catch(e: Exception) {
|
||||
Log.e(TAG, "Unable to retrieve expiration", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,12 +177,7 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
result?.creditCardExpirationDateId = autofillId
|
||||
node.autofillValue?.let { value ->
|
||||
if (value.isDate) {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.clear()
|
||||
calendar.timeInMillis = value.dateValue
|
||||
val year = calendar.get(Calendar.YEAR).toString().substring(2,4)
|
||||
val month = calendar.get(Calendar.MONTH).inc().toString().padStart(2, '0')
|
||||
result?.creditCardExpirationValue = month + year
|
||||
result?.creditCardExpirationValue = DateTime(value.dateValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -489,7 +491,7 @@ class StructureParser(private val structure: AssistStructure) {
|
||||
}
|
||||
|
||||
// format MMYY
|
||||
var creditCardExpirationValue: String? = null
|
||||
var creditCardExpirationValue: DateTime? = null
|
||||
set(value) {
|
||||
if (allowSaveValues)
|
||||
field = value
|
||||
|
||||
@@ -2,23 +2,24 @@ package com.kunzisoft.keepass.model
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import org.joda.time.DateTime
|
||||
|
||||
data class CreditCard(val cardholder: String?,
|
||||
val number: String?,
|
||||
val expiration: String?,
|
||||
val expiration: DateTime?,
|
||||
val cvv: String?) : Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString(),
|
||||
parcel.readString(),
|
||||
parcel.readString(),
|
||||
parcel.readSerializable() as DateTime?,
|
||||
parcel.readString()) {
|
||||
}
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeString(cardholder)
|
||||
parcel.writeString(number)
|
||||
parcel.writeString(expiration)
|
||||
parcel.writeSerializable(expiration)
|
||||
parcel.writeString(cvv)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.os.ParcelUuid
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.Field
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||
@@ -168,7 +169,7 @@ class EntryInfo : NodeInfo {
|
||||
}
|
||||
|
||||
if (database?.allowEntryCustomFields() == true) {
|
||||
val creditCard: CreditCard? = registerInfo.cc
|
||||
val creditCard: CreditCard? = registerInfo.creditCard
|
||||
|
||||
creditCard?.let { cc ->
|
||||
cc.cardholder?.let {
|
||||
@@ -177,7 +178,7 @@ class EntryInfo : NodeInfo {
|
||||
}
|
||||
cc.expiration?.let {
|
||||
expires = true
|
||||
// TODO Expiration expiryTime = it
|
||||
expiryTime = DateInstant(cc.expiration.millis)
|
||||
}
|
||||
cc.number?.let {
|
||||
val v = ProtectedString(false, it)
|
||||
|
||||
@@ -32,13 +32,6 @@ open class NodeInfo() : Parcelable {
|
||||
parcel.writeParcelable(expiryTime, flags)
|
||||
}
|
||||
|
||||
fun getExpiresStringValue(): String {
|
||||
return if (expires)
|
||||
expiryTime.toString()
|
||||
else
|
||||
""
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.os.Parcelable
|
||||
data class RegisterInfo(val searchInfo: SearchInfo,
|
||||
val username: String?,
|
||||
val password: String?,
|
||||
val cc: CreditCard?): Parcelable {
|
||||
val creditCard: CreditCard?): Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readParcelable(SearchInfo::class.java.classLoader) ?: SearchInfo(),
|
||||
@@ -19,7 +19,7 @@ data class RegisterInfo(val searchInfo: SearchInfo,
|
||||
parcel.writeParcelable(searchInfo, flags)
|
||||
parcel.writeString(username)
|
||||
parcel.writeString(password)
|
||||
parcel.writeParcelable(cc, flags)
|
||||
parcel.writeParcelable(creditCard, flags)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
|
||||
Reference in New Issue
Block a user