Skip to content

Add health connect snippets#915

Open
shounbi wants to merge 3 commits into
android:mainfrom
shounbi:add-health-connect-snippets
Open

Add health connect snippets#915
shounbi wants to merge 3 commits into
android:mainfrom
shounbi:add-health-connect-snippets

Conversation

@shounbi
Copy link
Copy Markdown
Contributor

@shounbi shounbi commented May 13, 2026

Add snippets for Health Connect site

@shounbi shounbi requested review from kkuan2011 and yrezgui as code owners May 13, 2026 14:29
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented May 13, 2026

Here is the summary of changes.

You are about to add 18 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 adds several helper functions to the HealthConnectManager class for managing permissions and inserting various Health Connect records. The review identified several issues: an empty conditional block for permission checks, incorrect property usage in the PlannedExerciseSessionRecord constructor, unused function parameters, and typos in function names. Addressing these will improve code correctness, cleanliness, and maintainability.

Comment on lines +337 to +339
if (!granted.containsAll(permissions)) {
// Check if required permissions are not granted, and return
}
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.

high

The if block is empty, meaning the function does not actually return or handle the case where permissions are missing, despite the comment. This could lead to unexpected behavior if the caller assumes the permissions were verified.

Suggested change
if (!granted.containsAll(permissions)) {
// Check if required permissions are not granted, and return
}
if (!granted.containsAll(permissions)) {
return emptySet()
}

Comment on lines +461 to +462
startDate = plannedStartDate,
duration = plannedDuration,
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.

high

PlannedExerciseSessionRecord does not have startDate or duration properties. It uses startTime and endTime (both of type Instant), consistent with other Health Connect records.

Comment on lines +275 to +278
suspend fun createSetOfPermissionSleep(
healthConnectClient: HealthConnectClient,
record: StepsRecord
): Set<String> {
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 parameters healthConnectClient and record are unused in this function. Additionally, healthConnectClient is already available as a property of the HealthConnectManager class, making it redundant to pass as a parameter. The record parameter (of type StepsRecord) also seems misplaced in a function related to sleep permissions.

    suspend fun createSetOfPermissionSleep(): Set<String> {

return permissions
}

suspend fun createPermissionExcerciseSession(): Set<String> {
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

Typo in function name: 'Excercise' should be 'Exercise'.

Suggested change
suspend fun createPermissionExcerciseSession(): Set<String> {
suspend fun createPermissionExerciseSession(): Set<String> {

return permissions
}

suspend fun checkPermissionPlannedExceriseSession() {
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

Typo in function name: 'Excerise' should be 'Exercise'.

Suggested change
suspend fun checkPermissionPlannedExceriseSession() {
suspend fun checkPermissionPlannedExerciseSession() {

Comment on lines +493 to +497
suspend fun insertRecords(
healthConnectClient: HealthConnectClient,
record: ExerciseSessionRecord,
startTime: Instant
){
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 record parameter is unused. The function creates a new ExerciseSessionRecord instance named session internally and ignores the one passed as an argument.

    suspend fun insertRecords(
        healthConnectClient: HealthConnectClient,
        startTime: Instant
    ) {

}

@SuppressLint("RestrictedApi")
suspend fun insertSegmentExerciseSession(startTime: Instant, endTime: Instant, insertedPlannedExerciseSessionId: String) {
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 parameters startTime and endTime are unused. The function calculates sessionStartTime and sessionEndTime internally using Instant.now() and a fixed duration.

Suggested change
suspend fun insertSegmentExerciseSession(startTime: Instant, endTime: Instant, insertedPlannedExerciseSessionId: String) {
suspend fun insertSegmentExerciseSession(insertedPlannedExerciseSessionId: String) {

Copy link
Copy Markdown
Contributor

@yrezgui yrezgui left a comment

Choose a reason for hiding this comment

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

You need to apply spotless

}
}

suspend fun createSetOfPermissionSleep(
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.

Suggested change
suspend fun createSetOfPermissionSleep(
fun createSetOfPermissionSleep(

return permissions
}

suspend fun createSetOfPermissionVitals(
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.

Suggested change
suspend fun createSetOfPermissionVitals(
fun createSetOfPermissionVitals(

return permissions
}

suspend fun createSetOfPermissionWorkout(
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.

Suggested change
suspend fun createSetOfPermissionWorkout(
fun createSetOfPermissionWorkout(

return permissions
}

suspend fun createSetOfPermissionGetStarted(
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.

Suggested change
suspend fun createSetOfPermissionGetStarted(
fun createSetOfPermissionGetStarted(

return permissions
}

suspend fun createPermissionStep(
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.

Suggested change
suspend fun createPermissionStep(
fun createPermissionStep(


suspend fun createSetOfPermissionWorkout(
healthConnectClient: HealthConnectClient,
record: StepsRecord
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.

Parameter not needed

Comment on lines +346 to +347
healthConnectClient: HealthConnectClient,
record: StepsRecord
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.

Parameters not needed

Comment on lines +362 to +363
healthConnectClient: HealthConnectClient,
record: StepsRecord
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.

Parameters not needed

// [END android_healthconnect_check_permission_planned_excerise_session]
}

@SuppressLint("RestrictedApi")
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.

Why is this required?

// [END android_healthconnect_write_exercise_route]
}

@SuppressLint("RestrictedApi")
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.

Why is this required?

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