Skip to content

Add health connect snippets#915

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

Add health connect snippets#915
shounbi wants to merge 10 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 thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
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

Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
@shounbi shounbi requested a review from yrezgui May 18, 2026 17:08
@shounbi
Copy link
Copy Markdown
Contributor Author

shounbi commented May 18, 2026

You need to apply spotless

I have ran spotless command ( ./gradlew spotlessApply)

Comment on lines +296 to +297
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.

how about this pending comment?

Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
return permissions
}

suspend fun createPermissionHeartRate(): 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.

same here, what do you think of this pending comment?

Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
Comment thread healthconnect/src/main/java/com/example/healthconnect/HealthConnectManager.kt Outdated
@shounbi shounbi requested a review from kkuan2011 May 19, 2026 16:36
}

// [START android_healthconnect_check_permission_launcher]
val permissions = remember {
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.

I don't think we need "remember {}" here because it's a static list, can we just have permissions = setOf(...)?

if (granted?.containsAll(permissions) == true) {
val startTime = Instant.now().minusSeconds(3600)
val endTime = Instant.now()
manager.insertSteps(startTime, endTime)
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.

does this insertSteps() call need to be on an I/O thread? because I thought coroutineScope uses the main dispatcher by default

}
}

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

return value can be Unit for these createPermission..() methods in this file right?

return permissions
}

suspend fun createPermissionSleepSession(): 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.

for the methods in this file, can you double check that you only add suspend onto the functions that require it? for example, I think suspend can be removed here and we can return Unit for the method

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.

3 participants