PhilippC / keepass2android

Password manager app for Android
https://play.google.com/store/apps/details?id=keepass2android.keepass2android
GNU General Public License v3.0
4.8k stars 389 forks source link

[BUG] Android Compose + KP2A Autofill #2371

Open lolo-io opened 1 year ago

lolo-io commented 1 year ago

Hi, i'm trying to implement autofill in an Android app with Compose. I am using AutofillType and AutofillNode.

My problem is that when I want to select an entry, it shows all the entries having androidapp://some.package.name in their additional fields, and not only the one having androidapp://my.app.package.

I don't know it it is a question or a bug, because in my memories this used to work.

I created a simple project to test this : https://github.com/lolo-io/DebugAutofill with just an email an password input, and all the code in the MainActivity.

It should work with androidapp://com.lolo.io.debugautofill

Maybe I'm doing something wrong. If you have an Idea let me know.

I test on a Pixel 6a device.

Thank you,


Basically this is how I add autofill support :

private fun Modifier.autofill(
    autofillTypes: List<AutofillType>,
    onFill: ((String) -> Unit),
) = composed {
    val autofill = LocalAutofill.current
    val autofillNode = AutofillNode(onFill = onFill, autofillTypes = autofillTypes)
    LocalAutofillTree.current += autofillNode

    this
        .onGloballyPositioned {
            autofillNode.boundingBox = it.boundsInWindow()
        }
        .onFocusChanged { focusState ->
            autofill?.run {
                if (focusState.isFocused) {
                    requestAutofillForNode(autofillNode)
                } else {
                    cancelAutofillForNode(autofillNode)
                }
            }
        }
}
GoodSir42 commented 6 months ago

I am having the exact same issue. If we can log additional information from the app I am also willing to provide it. I could even contribute a fix, but that might require some bigger setup on my end first after reading the how to build guide 😅

GoodSir42 commented 6 months ago

unfortunately I cannot build the app locally as I "only" have an M1 mac at my disposal right now, but it looks like the app cannot parse the autofill structure: { "InputFields": [ { "IdEntry": null, "Hint": null, "ClassName": "android.widget.FrameLayout", "AutofillHints": null, "IsFocused": false, "InputType": 0, "HtmlInfoTag": null, "HtmlInfoTypeAttribute": null }, { "IdEntry": null, "Hint": null, "ClassName": "android.view.ViewGroup", "AutofillHints": null, "IsFocused": true, "InputType": 0, "HtmlInfoTag": null, "HtmlInfoTypeAttribute": null }, { "IdEntry": null, "Hint": null, "ClassName": null, "AutofillHints": [ "username" ], "IsFocused": true, "InputType": 0, "HtmlInfoTag": null, "HtmlInfoTypeAttribute": null }, { "IdEntry": null, "Hint": null, "ClassName": null, "AutofillHints": [ "password" ], "IsFocused": false, "InputType": 0, "HtmlInfoTag": null, "HtmlInfoTypeAttribute": null } ], "PackageId": null, "WebDomain": null } I'll see if I can reproduce that on my windows laptop later. @PhilippC do you have a hint on where I could add some additional logs that maybe parse the PackageId?

GoodSir42 commented 6 months ago

I created a pull request to change the way the package id is determined

GoodSir42 commented 1 month ago

As more and more apps are transitioning to compose this would be a really nice addition. Do you need anything else? I'm open to modify my pr if it helps

PhilippC commented 1 month ago

thanks for the PR. I haven't had time at all for maintaining the app recently, but I will have more from next week on. I will check it then.