mirror of
https://github.com/bitwarden/android.git
synced 2026-05-31 17:56:51 -05:00
BIT-2180: Check htmlInfo for username field (#1318)
This commit is contained in:
committed by
Álison Fernandes
parent
5a6e3254ea
commit
b8fdadcedb
@@ -41,14 +41,20 @@ class SaveInfoBuilderImpl(
|
||||
return if (autofillPartition is AutofillPartition.Login && isInCompatMode) {
|
||||
null
|
||||
} else {
|
||||
val saveInfoBuilder = SaveInfo
|
||||
SaveInfo
|
||||
.Builder(
|
||||
autofillPartition.saveType,
|
||||
autofillPartition.requiredSaveIds.toTypedArray(),
|
||||
)
|
||||
.setOptionalIds(autofillPartition.optionalSaveIds.toTypedArray())
|
||||
if (isInCompatMode) saveInfoBuilder.setFlags(SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE)
|
||||
saveInfoBuilder.build()
|
||||
.apply {
|
||||
// setOptionalIds will throw an IllegalArgumentException if the array is empty
|
||||
autofillPartition
|
||||
.optionalSaveIds
|
||||
.takeUnless { it.isEmpty() }
|
||||
?.let { setOptionalIds(it.toTypedArray()) }
|
||||
if (isInCompatMode) setFlags(SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE)
|
||||
}
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,28 @@ fun HtmlInfo?.isPasswordField(): Boolean =
|
||||
}
|
||||
?: false
|
||||
|
||||
/**
|
||||
* Whether this [HtmlInfo] represents a username field.
|
||||
*
|
||||
* This function is untestable as [HtmlInfo] contains [android.util.Pair] which requires
|
||||
* instrumentation testing.
|
||||
*/
|
||||
@OmitFromCoverage
|
||||
fun HtmlInfo?.isUsernameField(): Boolean =
|
||||
this
|
||||
?.let { htmlInfo ->
|
||||
if (htmlInfo.isInputField) {
|
||||
htmlInfo
|
||||
.attributes
|
||||
?.any {
|
||||
it.first == "type" && it.second == "email"
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
?: false
|
||||
|
||||
/**
|
||||
* Whether this [HtmlInfo] represents an input field.
|
||||
*/
|
||||
|
||||
@@ -183,7 +183,8 @@ fun AssistStructure.ViewNode.isUsernameField(
|
||||
supportedHint == View.AUTOFILL_HINT_EMAIL_ADDRESS ||
|
||||
inputType.isUsernameInputType ||
|
||||
idEntry?.containsAnyTerms(SUPPORTED_RAW_USERNAME_HINTS) == true ||
|
||||
hint?.containsAnyTerms(SUPPORTED_RAW_USERNAME_HINTS) == true
|
||||
hint?.containsAnyTerms(SUPPORTED_RAW_USERNAME_HINTS) == true ||
|
||||
htmlInfo.isUsernameField()
|
||||
|
||||
/**
|
||||
* The website that this [AssistStructure.ViewNode] is a part of representing.
|
||||
|
||||
Reference in New Issue
Block a user