diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt index 78b957c67..28a498e89 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt @@ -129,26 +129,19 @@ object AutofillHelper { // get year (year in database entry is stored as String in the format YY) val year = entryInfo.expiryTime.getYearInt() - struct.ccExpDateId?.let { + struct.creditCardExpirationDateId?.let { if (struct.isWebView) { // set date string as defined in https://html.spec.whatwg.org - val dateString = "$year\u002D$month" - builder.setValue(it, AutofillValue.forText(dateString)) + builder.setValue(it, AutofillValue.forText("$year\u002D$month")) } else { - val calendar = Calendar.getInstance() - calendar.clear() - calendar[Calendar.YEAR] = year - // Month value is 0-based. e.g., 0 for January - calendar[Calendar.MONTH] = month - 1 - val date = calendar.timeInMillis - builder.setValue(it, AutofillValue.forDate(date)) + builder.setValue(it, AutofillValue.forDate(entryInfo.expiryTime.date.time)) } } - struct.ccExpDateMonthId?.let { + struct.creditCardExpirationMonthId?.let { if (struct.isWebView) { builder.setValue(it, AutofillValue.forText(month.toString())) } else { - if (struct.ccExpMonthOptions != null) { + if (struct.creditCardExpirationMonthOptions != null) { // index starts at 0 builder.setValue(it, AutofillValue.forList(month - 1)) } else { @@ -156,10 +149,10 @@ object AutofillHelper { } } } - struct.ccExpDateYearId?.let { + struct.creditCardExpirationYearId?.let { var autofillValue: AutofillValue? = null - struct.ccExpYearOptions?.let { options -> + struct.creditCardExpirationYearOptions?.let { options -> var yearIndex = options.indexOf(year.toString().substring(0, 2)) if (yearIndex == -1) { @@ -178,17 +171,17 @@ object AutofillHelper { } for (field in entryInfo.customFields) { if (field.name == TemplateField.LABEL_HOLDER) { - struct.ccNameId?.let { ccNameId -> + struct.creditCardHolderId?.let { ccNameId -> builder.setValue(ccNameId, AutofillValue.forText(field.protectedValue.stringValue)) } } if (field.name == TemplateField.LABEL_NUMBER) { - struct.ccnId?.let { ccnId -> + struct.creditCardNumberId?.let { ccnId -> builder.setValue(ccnId, AutofillValue.forText(field.protectedValue.stringValue)) } } if (field.name == TemplateField.LABEL_CVV) { - struct.cvvId?.let { cvvId -> + struct.cardVerificationValueId?.let { cvvId -> builder.setValue(cvvId, AutofillValue.forText(field.protectedValue.stringValue)) } } diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt index 139234946..495b2524f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt @@ -110,15 +110,6 @@ class KeeAutofillService : AutofillService() { } } } -// TODO does it make sense to disable autofill here? how long? -// else { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { -// val builder = FillResponse.Builder() -// // disable for a while (duration in ms) -// builder.disableAutofill(5*60*1000) -// callback.onSuccess(builder.build()) -// } -// } } } } @@ -191,16 +182,16 @@ class KeeAutofillService : AutofillService() { } // or a credit card form if (requiredIds.isEmpty()) { - parseResult.ccnId?.let { numberId -> + parseResult.creditCardNumberId?.let { numberId -> types = types or SaveInfo.SAVE_DATA_TYPE_CREDIT_CARD requiredIds.add(numberId) Log.d(TAG, "Asking to save credit card number") } - parseResult.ccExpDateId?.let { id -> optionalIds.add(id) } - parseResult.ccExpDateYearId?.let { id -> optionalIds.add(id) } - parseResult.ccExpDateMonthId?.let { id -> optionalIds.add(id) } - parseResult.ccNameId?.let { id -> optionalIds.add(id) } - parseResult.cvvId?.let { id -> optionalIds.add(id) } + parseResult.creditCardExpirationDateId?.let { id -> optionalIds.add(id) } + parseResult.creditCardExpirationYearId?.let { id -> optionalIds.add(id) } + parseResult.creditCardExpirationMonthId?.let { id -> optionalIds.add(id) } + parseResult.creditCardHolderId?.let { id -> optionalIds.add(id) } + parseResult.cardVerificationValueId?.let { id -> optionalIds.add(id) } } if (requiredIds.isNotEmpty()) { val builder = SaveInfo.Builder(types, requiredIds.toTypedArray()) @@ -260,14 +251,14 @@ class KeeAutofillService : AutofillService() { Log.d(TAG, "autofill onSaveRequest password") - if (parseResult.ccExpirationValue == null) { - if (parseResult.ccExpDateMonthValue != 0 && parseResult.ccExpDateYearValue != 0) { - parseResult.ccExpirationValue = parseResult.ccExpDateMonthValue.toString().padStart(2, '0') + parseResult.ccExpDateYearValue.toString() + if (parseResult.creditCardExpirationValue == null) { + if (parseResult.creditCardExpirationMonthValue != 0 && parseResult.creditCardExpirationYearValue != 0) { + parseResult.creditCardExpirationValue = parseResult.creditCardExpirationMonthValue.toString().padStart(2, '0') + parseResult.creditCardExpirationYearValue.toString() } } - val creditCard = CreditCard(parseResult.ccName, parseResult.ccNumber, - parseResult.ccExpirationValue, parseResult.cvv) + val creditCard = CreditCard(parseResult.creditCardHolder, parseResult.creditCardNumber, + parseResult.creditCardExpirationValue, parseResult.cardVerificationValue) // Show UI to save data val registerInfo = RegisterInfo( diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/StructureParser.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/StructureParser.kt index 1f2241586..33b6693ee 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/StructureParser.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/StructureParser.kt @@ -64,7 +64,7 @@ class StructureParser(private val structure: AssistStructure) { } } - return if (result?.passwordId != null || result?.ccnId != null) + return if (result?.passwordId != null || result?.creditCardNumberId != null) result else null @@ -144,30 +144,30 @@ class StructureParser(private val structure: AssistStructure) { } it.contains("cc-name", true) -> { Log.d(TAG, "Autofill credit card name hint") - result?.ccNameId = autofillId - result?.ccName = node.autofillValue?.textValue?.toString() + result?.creditCardHolderId = autofillId + result?.creditCardHolder = node.autofillValue?.textValue?.toString() } it.contains(View.AUTOFILL_HINT_CREDIT_CARD_NUMBER, true) || it.contains("cc-number", true) -> { Log.d(TAG, "Autofill credit card number hint") - result?.ccnId = autofillId - result?.ccNumber = node.autofillValue?.textValue?.toString() + result?.creditCardNumberId = autofillId + result?.creditCardNumber = node.autofillValue?.textValue?.toString() } // expect date string as defined in https://html.spec.whatwg.org, e.g. 2014-12 it.contains("cc-exp", true) -> { Log.d(TAG, "Autofill credit card expiration date hint") - result?.ccExpDateId = autofillId + result?.creditCardExpirationDateId = autofillId node.autofillValue?.let { value -> if (value.isText && value.textValue.length == 7) { value.textValue.let { date -> - result?.ccExpirationValue = date.substring(5, 7) + date.substring(2, 4) + result?.creditCardExpirationValue = date.substring(5, 7) + date.substring(2, 4) } } } } it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE, true) -> { Log.d(TAG, "Autofill credit card expiration date hint") - result?.ccExpDateId = autofillId + result?.creditCardExpirationDateId = autofillId node.autofillValue?.let { value -> if (value.isDate) { val calendar = Calendar.getInstance() @@ -175,16 +175,16 @@ class StructureParser(private val structure: AssistStructure) { 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?.ccExpirationValue = month + year + result?.creditCardExpirationValue = month + year } } } it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR, true) || it.contains("cc-exp-year", true) -> { Log.d(TAG, "Autofill credit card expiration year hint") - result?.ccExpDateYearId = autofillId + result?.creditCardExpirationYearId = autofillId if (node.autofillOptions != null) { - result?.ccExpYearOptions = node.autofillOptions + result?.creditCardExpirationYearOptions = node.autofillOptions } node.autofillValue?.let { value -> var year = 0 @@ -198,15 +198,15 @@ class StructureParser(private val structure: AssistStructure) { } catch (e: Exception) { year = 0 } - result?.ccExpDateYearValue = year % 100 + result?.creditCardExpirationYearValue = year % 100 } } it.contains(View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH, true) || it.contains("cc-exp-month", true) -> { - Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH hint") - result?.ccExpDateMonthId = autofillId + Log.d(TAG, "Autofill credit card expiration month hint") + result?.creditCardExpirationMonthId = autofillId if (node.autofillOptions != null) { - result?.ccExpMonthOptions = node.autofillOptions + result?.creditCardExpirationMonthOptions = node.autofillOptions } node.autofillValue?.let { value -> var month = 0 @@ -221,14 +221,14 @@ class StructureParser(private val structure: AssistStructure) { // assume list starts with January (index 0) month = value.listValue + 1 } - result?.ccExpDateMonthValue = month + result?.creditCardExpirationMonthValue = month } } it.contains(View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE, true) || it.contains("cc-csc", true) -> { - Log.d(TAG, "AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE hint") - result?.cvvId = autofillId - result?.cvv = node.autofillValue?.textValue?.toString() + Log.d(TAG, "Autofill card security code hint") + result?.cardVerificationValueId = autofillId + result?.cardVerificationValue = node.autofillValue?.textValue?.toString() } // Ignore autocomplete="off" // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion @@ -390,8 +390,8 @@ class StructureParser(private val structure: AssistStructure) { // if the user selects the credit card expiration date from a list of options // all options are stored here - var ccExpMonthOptions: Array? = null - var ccExpYearOptions: Array? = null + var creditCardExpirationMonthOptions: Array? = null + var creditCardExpirationYearOptions: Array? = null var usernameId: AutofillId? = null set(value) { @@ -405,37 +405,37 @@ class StructureParser(private val structure: AssistStructure) { field = value } - var ccNameId: AutofillId? = null + var creditCardHolderId: AutofillId? = null set(value) { if (field == null) field = value } - var ccnId: AutofillId? = null + var creditCardNumberId: AutofillId? = null set(value) { if (field == null) field = value } - var ccExpDateId: AutofillId? = null + var creditCardExpirationDateId: AutofillId? = null set(value) { if (field == null) field = value } - var ccExpDateYearId: AutofillId? = null + var creditCardExpirationYearId: AutofillId? = null set(value) { if (field == null) field = value } - var ccExpDateMonthId: AutofillId? = null + var creditCardExpirationMonthId: AutofillId? = null set(value) { if (field == null) field = value } - var cvvId: AutofillId? = null + var cardVerificationValueId: AutofillId? = null set(value) { if (field == null) field = value @@ -449,13 +449,13 @@ class StructureParser(private val structure: AssistStructure) { passwordId?.let { all.add(it) } - ccNameId?.let { + creditCardHolderId?.let { all.add(it) } - ccnId?.let { + creditCardNumberId?.let { all.add(it) } - cvvId?.let { + cardVerificationValueId?.let { all.add(it) } return all.toTypedArray() @@ -476,41 +476,41 @@ class StructureParser(private val structure: AssistStructure) { field = value } - var ccName: String? = null + var creditCardHolder: String? = null set(value) { if (allowSaveValues) field = value } - var ccNumber: String? = null + var creditCardNumber: String? = null set(value) { if (allowSaveValues) field = value } // format MMYY - var ccExpirationValue: String? = null + var creditCardExpirationValue: String? = null set(value) { if (allowSaveValues) field = value } // for year of CC expiration date: YY - var ccExpDateYearValue = 0 + var creditCardExpirationYearValue = 0 set(value) { if (allowSaveValues) field = value } // for month of CC expiration date: MM - var ccExpDateMonthValue = 0 + var creditCardExpirationMonthValue = 0 set(value) { if (allowSaveValues) field = value } // the security code for the credit card (also called CVV) - var cvv: String? = null + var cardVerificationValue: String? = null set(value) { if (allowSaveValues) field = value