Autofill manual selection for all form fields

This commit is contained in:
Ulrich Dürholz
2021-08-29 11:23:22 +02:00
parent 2595cf87d8
commit b977792168
2 changed files with 14 additions and 49 deletions

View File

@@ -351,28 +351,27 @@ object AutofillHelper {
}
val manualSelectionView = RemoteViews(context.packageName, R.layout.item_autofill_entry)
manualSelectionView.setTextViewText(R.id.autofill_entry_text, context.getString(R.string.autofill_manual_selection_prompt))
// manualSelectionView.setImageViewResource(R.id.autofill_entry_icon, R.mipmap.ic_launcher_round)
val pendingIntent = AutofillLauncherActivity.getPendingIntentForSelection(context,
searchInfo, inlineSuggestionsRequest)
val builder = Dataset.Builder(manualSelectionView)
parseResult.allAutofillIds().let { autofillIds ->
autofillIds.forEach { id ->
val builder = Dataset.Builder(manualSelectionView)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
inlineSuggestionsRequest?.let {
val inlinePresentationSpec = inlineSuggestionsRequest.inlinePresentationSpecs[0]
val inlinePresentation = buildInlinePresentationForManualSelection(context, inlinePresentationSpec, pendingIntent)
inlinePresentation?.let {
builder.setInlinePresentation(it)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
inlineSuggestionsRequest?.let {
val inlinePresentationSpec = inlineSuggestionsRequest.inlinePresentationSpecs[0]
val inlinePresentation = buildInlinePresentationForManualSelection(context, inlinePresentationSpec, pendingIntent)
inlinePresentation?.let {
builder.setInlinePresentation(it)
}
}
}
builder.setValue(id, AutofillValue.forText("dummy"))
builder.setAuthentication(pendingIntent.intentSender)
responseBuilder.addDataset(builder.build())
}
}
// enable manual selection only for the form field that has focus
parseResult.focusedId?.let { autofillId ->
builder.setValue(autofillId, AutofillValue.forText("dummy"))
builder.setAuthentication(pendingIntent.intentSender)
responseBuilder.addDataset(builder.build())
}
}
return try {
@@ -413,7 +412,6 @@ object AutofillHelper {
} else {
buildResponse(activity, database, entriesInfo, result, null)
}
response.apply { }
val mReplyIntent = Intent()
Log.d(activity.javaClass.name, "Successed Autofill auth.")
mReplyIntent.putExtra(

View File

@@ -44,7 +44,6 @@ class StructureParser(private val structure: AssistStructure) {
fun parse(saveValue: Boolean = false): Result? {
try {
result = Result()
result?.focusedId = getFocusedID()
result?.apply {
allowSaveValues = saveValue
usernameIdCandidate = null
@@ -75,35 +74,6 @@ class StructureParser(private val structure: AssistStructure) {
}
}
/*
* Note: SDK >= Q provides this method...
* fillContext.getFocusedId()
*/
private fun getFocusedID(): AutofillId? {
for (i in 0 until structure.windowNodeCount) {
val windowNode = structure.getWindowNodeAt(i)
val autofillId = traverse(windowNode.rootViewNode)
if (autofillId != null) {
return autofillId
}
}
return null
}
private fun traverse(node: AssistStructure.ViewNode): AutofillId? {
if (node.visibility == View.VISIBLE && node.autofillHints != null) {
return node.autofillId
} else {
for (i in 0 until node.childCount) {
val autoFillId = traverse(node.getChildAt(i))
if (autoFillId != null) {
return autoFillId
}
}
}
return null
}
private fun parseViewNode(node: AssistStructure.ViewNode): Boolean {
// remember this
if (node.className == "android.webkit.WebView") {
@@ -447,9 +417,6 @@ class StructureParser(private val structure: AssistStructure) {
var creditCardExpirationMonthOptions: Array<CharSequence>? = null
var creditCardExpirationDayOptions: Array<CharSequence>? = null
// the AutofillId of the view that triggered autofill.
var focusedId: AutofillId? = null
var usernameId: AutofillId? = null
set(value) {
if (field == null)