Skip to content

Update EngageWorker snippet to use V2 isServiceAvailable API#980

Open
amulyagaur wants to merge 4 commits into
android:mainfrom
amulyagaur:main
Open

Update EngageWorker snippet to use V2 isServiceAvailable API#980
amulyagaur wants to merge 4 commits into
android:mainfrom
amulyagaur:main

Conversation

@amulyagaur

Copy link
Copy Markdown

Updates the EngageWorker.kt snippet to use the new V2 version of isServiceAvailable API supporting ClusterType filtering.

@amulyagaur amulyagaur requested a review from a team as a code owner July 10, 2026 13:15
@google-cla

google-cla Bot commented Jul 10, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

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.

Code Review

This pull request updates EngageWorker.kt to perform service availability checks based on specific cluster types rather than a general check. However, the introduction of an else block that returns Result.failure() for unknown cluster types will break publishing for other valid types, such as user account management cards. It is recommended to remove this else block to prevent these failures.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +60 to 71
if (intendedClusterType != ClusterType.TYPE_UNKNOWN) {
val request = ServiceAvailabilityRequest.Builder()
.addIntendedClusterType(intendedClusterType)
.build()
val availabilityMap = client.isServiceAvailable(request).await()
if (availabilityMap[intendedClusterType] != true) {
Log.e("EngageWorker", "Service not available for cluster type: $intendedClusterType")
return Result.failure()
}
} else {
return Result.failure()
}

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.

critical

This else block causes the worker to immediately return Result.failure() for any publish type that does not map to a standard ClusterType (such as Constants.PUBLISH_TYPE_USER_ACCOUNT_MANAGEMENT). This completely breaks the publishing of user account management cards.

Since any invalid or unsupported publish types are already handled and rejected with Result.failure() in the final when (publishType) block at the end of doWork(), we can safely remove this else block entirely.

        if (intendedClusterType != ClusterType.TYPE_UNKNOWN) {
            val request = ServiceAvailabilityRequest.Builder()
                .addIntendedClusterType(intendedClusterType)
                .build()
            val availabilityMap = client.isServiceAvailable(request).await()
            if (availabilityMap[intendedClusterType] != true) {
                Log.e("EngageWorker", "Service not available for cluster type: $intendedClusterType")
                return Result.failure()
            }
        }

@yrezgui yrezgui requested a review from huewu July 10, 2026 13:29
@huewu

huewu commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Hi @amulyagaur,

Shouldn't we update the dependency version, as well? (1.5.2 > 1.6.0). Every code in the snippet should be compilable without error and warning. So, please double check it.

Thanks.

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