Skip to content

Add issuer snippets#910

Merged
cy245 merged 4 commits intomainfrom
identity-dc-issue-credentials
May 8, 2026
Merged

Add issuer snippets#910
cy245 merged 4 commits intomainfrom
identity-dc-issue-credentials

Conversation

@cy245
Copy link
Copy Markdown
Contributor

@cy245 cy245 commented May 8, 2026

No description provided.

@cy245 cy245 requested review from kkuan2011 and yrezgui as code owners May 8, 2026 16:55
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented May 8, 2026

Here is the summary of changes.

You are about to add 6 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the androidx-credentials dependencies to version 1.7.0-alpha02 and introduces the DigitalCredentialIssuer class to facilitate digital credential issuance using the CredentialManager API. It also adds a JSON snippet for OpenID4VCI issuance requests. Review feedback includes correcting a spacing issue in the class declaration, changing a parameter type from Context to Activity to ensure proper UI execution, replacing an unsafe cast with a type check to avoid potential crashes, and addressing unused variables within the exception handler.

import androidx.credentials.exceptions.CreateCredentialUnknownException
import androidx.credentials.exceptions.CreateCredentialUnsupportedException

class DigitalCredentialIssuer : Activity() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is an extra space before the colon in the class declaration. Additionally, consider if this class needs to inherit from Activity. If it is intended as a utility class for snippets, the inheritance may be unnecessary. This follows the Kotlin Style Guide regarding whitespace.

Suggested change
class DigitalCredentialIssuer : Activity() {
class DigitalCredentialIssuer : Activity() {
References
  1. The Kotlin Style Guide recommends standard spacing around colons in class declarations. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


class DigitalCredentialIssuer : Activity() {
@OptIn(ExperimentalDigitalCredentialApi::class)
suspend fun issueToWallet(context: Context) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The CredentialManager.createCredential method requires an Activity context to properly launch the selector UI. It is recommended to change the parameter type from Context to Activity to ensure the caller provides a valid context for UI operations.

Suggested change
suspend fun issueToWallet(context: Context) {
suspend fun issueToWallet(context: Activity) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this Gemini suggestion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

context = context,
request = createRequest
)
handleSuccess(response as CreateDigitalCredentialResponse)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using an unsafe cast (as) can lead to a ClassCastException if the response is not of the expected type. It is safer to use a type check (is) or a safe cast (as?) before calling handleSuccess.

            if (response is CreateDigitalCredentialResponse) {
                handleSuccess(response)
            }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine as a sample since there's only one flow being illustrated

Comment on lines +74 to +75
val errorType = e.type
val errorMessage = e.message
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These variables are assigned but never used. While this is a snippet, in a real application this would trigger lint warnings and should be either used (e.g., for logging) or removed.

Copy link
Copy Markdown
Contributor

@kkuan2011 kkuan2011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments for you to consider, otherwise feel free to submit

context = context,
request = createRequest
)
handleSuccess(response as CreateDigitalCredentialResponse)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one too?


class DigitalCredentialIssuer : Activity() {
@OptIn(ExperimentalDigitalCredentialApi::class)
suspend fun issueToWallet(context: Context) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this Gemini suggestion?

import androidx.credentials.exceptions.CreateCredentialUnknownException
import androidx.credentials.exceptions.CreateCredentialUnsupportedException

class DigitalCredentialIssuer : Activity() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: even though it's not in the visible code snippet, should we make this a ComponentActivity to be more compose-first?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I don't think this hurts

@cy245 cy245 enabled auto-merge (squash) May 8, 2026 17:48
@cy245 cy245 merged commit 5b40855 into main May 8, 2026
6 checks passed
@cy245 cy245 deleted the identity-dc-issue-credentials branch May 8, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants