Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef8c8026 authored by Daniel Kim's avatar Daniel Kim Committed by Android (Google) Code Review
Browse files

Merge "Set sessionId in autofillIds in CredentialAutofillService" into main

parents 3127f157 a41b1705
Loading
Loading
Loading
Loading
+23 −7
Original line number Original line Diff line number Diff line
@@ -578,7 +578,7 @@ class CredentialAutofillService : AutofillService() {
            responseClientState: Bundle
            responseClientState: Bundle
    ): GetCredentialRequest? {
    ): GetCredentialRequest? {
        val credentialOptions: MutableList<CredentialOption> = mutableListOf()
        val credentialOptions: MutableList<CredentialOption> = mutableListOf()
        traverseStructureForRequest(structure, credentialOptions, responseClientState)
        traverseStructureForRequest(structure, credentialOptions, responseClientState, sessionId)


        if (credentialOptions.isNotEmpty()) {
        if (credentialOptions.isNotEmpty()) {
            val dataBundle = Bundle()
            val dataBundle = Bundle()
@@ -594,7 +594,8 @@ class CredentialAutofillService : AutofillService() {
    private fun traverseStructureForRequest(
    private fun traverseStructureForRequest(
            structure: AssistStructure,
            structure: AssistStructure,
            cmRequests: MutableList<CredentialOption>,
            cmRequests: MutableList<CredentialOption>,
            responseClientState: Bundle
            responseClientState: Bundle,
            sessionId: Int
    ) {
    ) {
        val traversedViewNodes: MutableSet<AutofillId> = mutableSetOf()
        val traversedViewNodes: MutableSet<AutofillId> = mutableSetOf()
        val credentialOptionsFromHints: MutableMap<String, CredentialOption> = mutableMapOf()
        val credentialOptionsFromHints: MutableMap<String, CredentialOption> = mutableMapOf()
@@ -606,7 +607,7 @@ class CredentialAutofillService : AutofillService() {
        windowNodes.forEach { windowNode: AssistStructure.WindowNode ->
        windowNodes.forEach { windowNode: AssistStructure.WindowNode ->
            traverseNodeForRequest(
            traverseNodeForRequest(
                windowNode.rootViewNode, cmRequests, responseClientState, traversedViewNodes,
                windowNode.rootViewNode, cmRequests, responseClientState, traversedViewNodes,
                credentialOptionsFromHints)
                credentialOptionsFromHints, sessionId)
        }
        }
    }
    }


@@ -615,11 +616,12 @@ class CredentialAutofillService : AutofillService() {
            cmRequests: MutableList<CredentialOption>,
            cmRequests: MutableList<CredentialOption>,
            responseClientState: Bundle,
            responseClientState: Bundle,
            traversedViewNodes: MutableSet<AutofillId>,
            traversedViewNodes: MutableSet<AutofillId>,
            credentialOptionsFromHints: MutableMap<String, CredentialOption>
            credentialOptionsFromHints: MutableMap<String, CredentialOption>,
            sessionId: Int
    ) {
    ) {
        viewNode.autofillId?.let {
        viewNode.autofillId?.let {
            cmRequests.addAll(getCredentialOptionsFromViewNode(viewNode, it, responseClientState,
            cmRequests.addAll(getCredentialOptionsFromViewNode(viewNode, it, responseClientState,
                traversedViewNodes, credentialOptionsFromHints))
                traversedViewNodes, credentialOptionsFromHints, sessionId))
            traversedViewNodes.add(it)
            traversedViewNodes.add(it)
        }
        }


@@ -630,7 +632,7 @@ class CredentialAutofillService : AutofillService() {


        children.forEach { childNode: AssistStructure.ViewNode ->
        children.forEach { childNode: AssistStructure.ViewNode ->
            traverseNodeForRequest(childNode, cmRequests, responseClientState, traversedViewNodes,
            traverseNodeForRequest(childNode, cmRequests, responseClientState, traversedViewNodes,
                credentialOptionsFromHints)
                credentialOptionsFromHints, sessionId)
        }
        }
    }
    }


@@ -639,7 +641,8 @@ class CredentialAutofillService : AutofillService() {
            autofillId: AutofillId,
            autofillId: AutofillId,
            responseClientState: Bundle,
            responseClientState: Bundle,
            traversedViewNodes: MutableSet<AutofillId>,
            traversedViewNodes: MutableSet<AutofillId>,
            credentialOptionsFromHints: MutableMap<String, CredentialOption>
            credentialOptionsFromHints: MutableMap<String, CredentialOption>,
            sessionId: Int
    ): MutableList<CredentialOption> {
    ): MutableList<CredentialOption> {
        val credentialOptions: MutableList<CredentialOption> = mutableListOf()
        val credentialOptions: MutableList<CredentialOption> = mutableListOf()
        if (Flags.autofillCredmanDevIntegration() && viewNode.credentialManagerRequest != null) {
        if (Flags.autofillCredmanDevIntegration() && viewNode.credentialManagerRequest != null) {
@@ -650,12 +653,25 @@ class CredentialAutofillService : AutofillService() {
                        .getParcelableArrayList(
                        .getParcelableArrayList(
                            CredentialProviderService.EXTRA_AUTOFILL_ID, AutofillId::class.java)
                            CredentialProviderService.EXTRA_AUTOFILL_ID, AutofillId::class.java)
                        ?.let { associatedAutofillIds ->
                        ?.let { associatedAutofillIds ->
                            // Set sessionId in autofillIds. The autofillIds stored in Credential
                            // Options do not have associated session id and will result in
                            // different hashes than the ones in assistStructure.
                            associatedAutofillIds.forEach { associatedAutofillId ->
                                associatedAutofillId.sessionId = sessionId
                            }

                            // Check whether any of the associated autofill ids have already been
                            // Check whether any of the associated autofill ids have already been
                            // traversed. If so, skip, to dedupe on duplicate credential options.
                            // traversed. If so, skip, to dedupe on duplicate credential options.
                            if ((traversedViewNodes intersect associatedAutofillIds.toSet())
                            if ((traversedViewNodes intersect associatedAutofillIds.toSet())
                                        .isEmpty()) {
                                        .isEmpty()) {
                                credentialOptions.add(credentialOption)
                                credentialOptions.add(credentialOption)
                            }
                            }

                            // Set the autofillIds with session id back to credential option.
                            credentialOption.candidateQueryData.putParcelableArrayList(
                                CredentialProviderService.EXTRA_AUTOFILL_ID,
                                associatedAutofillIds
                            )
                        }
                        }
            }
            }
        }
        }