Loading packages/CredentialManager/src/com/android/credentialmanager/autofill/CredentialAutofillService.kt +23 −7 Original line number Original line Diff line number Diff line Loading @@ -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() Loading @@ -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() Loading @@ -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) } } } } Loading @@ -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) } } Loading @@ -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) } } } } Loading @@ -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) { Loading @@ -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 ) } } } } } } Loading Loading
packages/CredentialManager/src/com/android/credentialmanager/autofill/CredentialAutofillService.kt +23 −7 Original line number Original line Diff line number Diff line Loading @@ -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() Loading @@ -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() Loading @@ -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) } } } } Loading @@ -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) } } Loading @@ -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) } } } } Loading @@ -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) { Loading @@ -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 ) } } } } } } Loading