diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/parser/AutofillParserImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/parser/AutofillParserImpl.kt index 65b2bf5bbc..a35b1b9959 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/parser/AutofillParserImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/parser/AutofillParserImpl.kt @@ -254,7 +254,9 @@ private fun AssistStructure.ViewNode.traverse( // Set up mutable lists for collecting valid AutofillViews and ignorable view ids. val mutableAutofillViewList: MutableList = mutableListOf() val mutableIgnoreAutofillIdList: MutableList = mutableListOf() - var idPackage: String? = this.idPackage + // OS sometimes defaults node.idPackage to "android", which is not a valid + // package name so it is ignored to prevent auto-filling unknown applications. + var storedIdPackage: String? = this.idPackage?.takeUnless { it.isBlank() || it == "android" } // Try converting this `ViewNode` into an `AutofillView`. If a valid instance is returned, add // it to the list. Otherwise, ignore the `AutofillId` associated with this `ViewNode`. @@ -272,12 +274,8 @@ private fun AssistStructure.ViewNode.traverse( viewNodeTraversalData.ignoreAutofillIds.forEach(mutableIgnoreAutofillIdList::add) // Get the first non-null idPackage. - if (idPackage.isNullOrBlank() && - // OS sometimes defaults node.idPackage to "android", which is not a valid - // package name so it is ignored to prevent auto-filling unknown applications. - viewNodeTraversalData.idPackage?.equals("android") == false - ) { - idPackage = viewNodeTraversalData.idPackage + if (storedIdPackage == null) { + storedIdPackage = viewNodeTraversalData.idPackage } } } @@ -286,7 +284,7 @@ private fun AssistStructure.ViewNode.traverse( // descendant's. return ViewNodeTraversalData( autofillViews = mutableAutofillViewList, - idPackage = idPackage, + idPackage = storedIdPackage, ignoreAutofillIds = mutableIgnoreAutofillIdList, ) } diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/ViewNodeExtensions.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/ViewNodeExtensions.kt index 2a02fb0ea8..5d80e86fc8 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/ViewNodeExtensions.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/autofill/util/ViewNodeExtensions.kt @@ -51,35 +51,28 @@ private val AssistStructure.ViewNode.isInputField: Boolean */ fun AssistStructure.ViewNode.toAutofillView( parentWebsite: String?, -): AutofillView? = - this - .autofillId - // We only care about nodes with a valid `AutofillId`. - ?.let { nonNullAutofillId -> - if (supportedAutofillHint != null || this.isInputField) { - val autofillOptions = this - .autofillOptions - .orEmpty() - .map { it.toString() } - - val autofillViewData = AutofillView.Data( - autofillId = nonNullAutofillId, - autofillOptions = autofillOptions, - autofillType = this.autofillType, - isFocused = this.isFocused, - textValue = this.autofillValue?.extractTextValue(), - hasPasswordTerms = this.hasPasswordTerms(), - website = this.website ?: parentWebsite, - ) - buildAutofillView( - autofillOptions = autofillOptions, - autofillViewData = autofillViewData, - autofillHint = supportedAutofillHint, - ) - } else { - null - } - } +): AutofillView? { + val nonNullAutofillId = this.autofillId ?: return null + if (this.supportedAutofillHint == null && !this.isInputField) return null + val autofillOptions = this + .autofillOptions + .orEmpty() + .map { it.toString() } + val autofillViewData = AutofillView.Data( + autofillId = nonNullAutofillId, + autofillOptions = autofillOptions, + autofillType = this.autofillType, + isFocused = this.isFocused, + textValue = this.autofillValue?.extractTextValue(), + hasPasswordTerms = this.hasPasswordTerms(), + website = this.website ?: parentWebsite, + ) + return buildAutofillView( + autofillOptions = autofillOptions, + autofillViewData = autofillViewData, + autofillHint = this.supportedAutofillHint, + ) +} /** * The first supported autofill hint for this view node, or null if none are found.