improvement: Better chance at suggesting to autofill the OTP fields

This commit is contained in:
Artem Chepurnyi 2024-12-14 15:53:59 +02:00
parent 679c385ef2
commit 5d20685465
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
5 changed files with 53 additions and 14 deletions

View File

@ -208,7 +208,8 @@ class AutofillActivity : BaseActivity(), DIAware {
it.hint == AutofillHint.PASSWORD ||
it.hint == AutofillHint.PHONE_NUMBER ||
it.hint == AutofillHint.EMAIL_ADDRESS ||
it.hint == AutofillHint.USERNAME
it.hint == AutofillHint.USERNAME ||
it.hint == AutofillHint.APP_OTP
} == true
val cardSearch = args.autofillStructure2?.items?.any {
it.hint == AutofillHint.CREDIT_CARD_NUMBER ||

View File

@ -21,6 +21,7 @@ import com.artemchep.keyguard.common.io.launchIn
import com.artemchep.keyguard.common.io.toIO
import com.artemchep.keyguard.common.model.AddCipherOpenedHistoryRequest
import com.artemchep.keyguard.common.model.AddUriCipherRequest
import com.artemchep.keyguard.common.model.AutofillHint
import com.artemchep.keyguard.common.model.DSecret
import com.artemchep.keyguard.common.model.MasterSession
import com.artemchep.keyguard.common.model.TotpToken
@ -95,7 +96,11 @@ class AutofillFakeAuthActivity : AppCompatActivity(), DIAware {
if (result != null) {
// We want to copy to OTP code when you autofill an
// entry, so launch a totp service.
val mayNeedToCopyTotp = args?.structure?.items
?.none { it.hint == AutofillHint.APP_OTP } == true
if (mayNeedToCopyTotp) {
launchCopyTotpService()
}
launchEditService()
launchHistoryService()

View File

@ -76,6 +76,12 @@ class AutofillStructureParser {
"密碼",
)
private val autofillLabel2faTranslations = listOf(
"totp",
"otp",
"2fa",
)
private val autofillLabelEmailTranslations = listOf(
"email",
"e-mail",
@ -758,6 +764,15 @@ class AutofillStructureParser {
reason = "type",
)
"totp",
"twofa",
"2fa",
-> AutofillStructureItemBuilder(
accuracy = AutofillStructureItem.Accuracy.HIGH,
hint = AutofillHint.APP_OTP,
reason = "type",
)
// custom
"expdate" -> AutofillStructureItemBuilder(
@ -789,7 +804,15 @@ class AutofillStructureParser {
"password" in id -> AutofillStructureItemBuilder(
accuracy = AutofillStructureItem.Accuracy.HIGH,
hint = AutofillHint.PASSWORD,
reason = "type",
reason = "id",
)
"totp" in id ||
"twofa" in id ||
"2fa" in id -> AutofillStructureItemBuilder(
accuracy = AutofillStructureItem.Accuracy.HIGH,
hint = AutofillHint.APP_OTP,
reason = "id",
)
else -> null
@ -827,6 +850,13 @@ class AutofillStructureParser {
reason = "label:$hint",
)
autofillLabel2faTranslations.any { it in hint } ->
AutofillStructureItemBuilder(
accuracy = AutofillStructureItem.Accuracy.MEDIUM,
hint = AutofillHint.APP_OTP,
reason = "label:$hint",
)
autofillLabelCreditCardNumberTranslations.any { it.matches(hint) } ->
AutofillStructureItemBuilder(
accuracy = AutofillStructureItem.Accuracy.MEDIUM,
@ -909,6 +939,8 @@ class AutofillStructureParser {
accuracy = AutofillStructureItem.Accuracy.LOWEST,
hint = AutofillHint.USERNAME,
)
extractOfType(node.idType.orEmpty()).let(out::addAll)
extractOfId(node.idEntry.orEmpty()).let(out::addAll)
}
inputIsVariationType(

View File

@ -523,10 +523,6 @@ class KeyguardAutofillService : AutofillService(), DIAware {
title = title,
text = text,
)
suspend fun createDatasetBuilder(): Dataset.Builder {
val builder = Dataset.Builder(views)
builder.setId(secret.id)
val fields = run {
val hints = struct.items
.asSequence()
@ -537,6 +533,10 @@ class KeyguardAutofillService : AutofillService(), DIAware {
getTotpCode = getTotpCode,
).bind()
}
suspend fun createDatasetBuilder(): Dataset.Builder {
val builder = Dataset.Builder(views)
builder.setId(secret.id)
struct.items.forEach { structItem ->
val value = fields[structItem.hint]
builder.trySetValue(

View File

@ -198,7 +198,8 @@ class GetSuggestionsImpl(
AutofillHint.EMAIL_ADDRESS in target.hints ||
AutofillHint.PHONE_NUMBER in target.hints ||
AutofillHint.USERNAME in target.hints ||
AutofillHint.PASSWORD in target.hints
AutofillHint.PASSWORD in target.hints ||
AutofillHint.APP_OTP in target.hints
) {
run {
val equivalentDomains = equivalentDomainsHolder