fix: Recognize Brave forms

This commit is contained in:
J-Jamet
2024-04-19 13:41:58 +02:00
parent 27ea357348
commit 40dbbbf0a0

View File

@@ -37,7 +37,6 @@ import kotlin.collections.ArrayList
@RequiresApi(api = Build.VERSION_CODES.O)
class StructureParser(private val structure: AssistStructure) {
private var result: Result? = null
private var usernameNeeded = true
private var usernameIdCandidate: AutofillId? = null
private var usernameValueCandidate: AutofillValue? = null
@@ -163,7 +162,8 @@ class StructureParser(private val structure: AssistStructure) {
result?.passwordId = autofillId
result?.passwordValue = node.autofillValue
Log.d(TAG, "Autofill password hint")
//return true
// Comment "return" to check all the tree
// return true
}
it.equals("cc-name", true) -> {
Log.d(TAG, "Autofill credit card name hint")
@@ -340,11 +340,11 @@ class StructureParser(private val structure: AssistStructure) {
return "0x${"%08x".format(inputType)}"
}
private fun parseNodeByAndroidInput(node: AssistStructure.ViewNode): Boolean {
val autofillId = node.autofillId
val inputType = node.inputType
when (inputType and InputType.TYPE_MASK_CLASS) {
InputType.TYPE_CLASS_TEXT -> {
private fun manageTypeText(
node: AssistStructure.ViewNode,
autofillId: AutofillId?,
inputType: Int
): Boolean {
when {
inputIsVariationType(inputType,
InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS,
@@ -378,7 +378,6 @@ class StructureParser(private val structure: AssistStructure) {
result?.passwordId = autofillId
result?.passwordValue = node.autofillValue
Log.d(TAG, "Autofill visible password android text type (as password): ${showHexInputType(inputType)}")
usernameNeeded = false
}
}
inputIsVariationType(inputType,
@@ -398,13 +397,20 @@ class StructureParser(private val structure: AssistStructure) {
InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE,
InputType.TYPE_TEXT_VARIATION_URI) -> {
// Type not used
Log.d(TAG, "Autofill not used android text type: ${showHexInputType(inputType)}")
}
else -> {
Log.d(TAG, "Autofill unknown android text type: ${showHexInputType(inputType)}")
}
}
return false
}
InputType.TYPE_CLASS_NUMBER -> {
private fun manageTypeNumber(
node: AssistStructure.ViewNode,
autofillId: AutofillId?,
inputType: Int
): Boolean {
when {
inputIsVariationType(inputType,
InputType.TYPE_NUMBER_VARIATION_NORMAL) -> {
@@ -425,6 +431,37 @@ class StructureParser(private val structure: AssistStructure) {
Log.d(TAG, "Autofill unknown android number type: ${showHexInputType(inputType)}")
}
}
return false
}
private fun manageTypeNull(
node: AssistStructure.ViewNode,
autofillId: AutofillId?,
inputType: Int
): Boolean {
if (node.className == "android.widget.EditText") {
Log.d(TAG, "Autofill null android input type class: ${showHexInputType(inputType)}" +
", get the EditText node class name!")
if (result?.passwordId == null) {
usernameIdCandidate = autofillId
usernameValueCandidate = node.autofillValue
}
}
return false
}
private fun parseNodeByAndroidInput(node: AssistStructure.ViewNode): Boolean {
val autofillId = node.autofillId
val inputType = node.inputType
when (inputType and InputType.TYPE_MASK_CLASS) {
InputType.TYPE_CLASS_TEXT -> {
return manageTypeText(node, autofillId, inputType)
}
InputType.TYPE_CLASS_NUMBER -> {
return manageTypeNumber(node, autofillId, inputType)
}
InputType.TYPE_NULL -> {
return manageTypeNull(node, autofillId, inputType)
}
}
return false
@@ -453,21 +490,13 @@ class StructureParser(private val structure: AssistStructure) {
var creditCardExpirationDayOptions: Array<CharSequence>? = null
var usernameId: AutofillId? = null
var passwordId: AutofillId? = null
var creditCardHolderId: AutofillId? = null
var creditCardNumberId: AutofillId? = null
var creditCardExpirationDateId: AutofillId? = null
var creditCardExpirationYearId: AutofillId? = null
var creditCardExpirationMonthId: AutofillId? = null
var creditCardExpirationDayId: AutofillId? = null
var cardVerificationValueId: AutofillId? = null
fun allAutofillIds(): Array<AutofillId> {