Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fallback logic to extract package id from window node #5706

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.duckduckgo.autofill.impl.service
import android.annotation.SuppressLint
import android.app.assist.AssistStructure
import android.app.assist.AssistStructure.ViewNode
import android.app.assist.AssistStructure.WindowNode
import android.view.autofill.AutofillId
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.autofill.impl.service.AutofillFieldType.UNKNOWN
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesBinding
import dagger.SingleInstanceIn
Expand Down Expand Up @@ -72,7 +72,13 @@ class RealAutofillParser @Inject constructor(
val windowNode = structure.getWindowNodeAt(i)
windowNode.rootViewNode?.let { viewNode ->
autofillRootNodes.add(
traverseViewNode(viewNode).convertIntoAutofillNode(),
traverseViewNode(viewNode).convertIntoAutofillNode().let { rootNode ->
if (rootNode.packageId.isNullOrBlank()) {
rootNode.copy(packageId = extractPackageFromTitle(windowNode))
} else {
rootNode
}
},
)
}
}
Expand Down Expand Up @@ -116,6 +122,11 @@ class RealAutofillParser @Inject constructor(
)
}

private fun extractPackageFromTitle(windowNode: WindowNode): String? {
// window node title format looks like: packageId/ActivityName
return windowNode.title.takeUnless { it.isNullOrBlank() }?.split('/')?.firstOrNull()
}

private fun ViewNode.validPackageId(): String? {
return this.idPackage
.takeUnless { it.isNullOrBlank() }
Expand Down
Loading