Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When writing an ExerciseSession, ExerciseRoute should default to undefined instead of an emptyList #85

Closed
WJimmyCook opened this issue Apr 18, 2024 · 0 comments · Fixed by #87
Assignees

Comments

@WJimmyCook
Copy link

WJimmyCook commented Apr 18, 2024

If you try to write an ExerciseSession record without an ExerciseRoute, you get the error:
Caller doesn't have android.permission.health.WRITE_EXERCISE_ROUTE to write to record type class android.health.connect.datatypes.ExerciseSessionRecord]

But I think you should be able to write an ExerciseSession record that doesn't have a route, like a weight lifting session will have an ExerciseSession but no ExerciseRoute and no required permissions for ExerciseRoute.

I think line 47 should default to undefined instead of an empty list:

ExerciseSessionRecord(
startTime = Instant.parse(it.getString("startTime")),
endTime = Instant.parse(it.getString("endTime")),
startZoneOffset = null,
endZoneOffset = null,
exerciseType = it.getSafeInt(
"exerciseType", ExerciseSessionRecord.EXERCISE_TYPE_OTHER_WORKOUT
),
notes = it.getString("notes"),
title = it.getString("title"),
laps = it.getArray("samples")?.toMapList()?.map { sample ->
ExerciseLap(
startTime = Instant.parse(sample.getString("startTime")),
endTime = Instant.parse(sample.getString("endTime")),
length = getLengthFromJsMap(sample.getMap("length")),
)
} ?: emptyList(),
segments = it.getArray("samples")?.toMapList()?.map { sample ->
ExerciseSegment(
startTime = Instant.parse(sample.getString("startTime")),
endTime = Instant.parse(sample.getString("endTime")),
segmentType = sample.getSafeInt(
"segmentType", ExerciseSegment.EXERCISE_SEGMENT_TYPE_UNKNOWN
),
repetitions = sample.getSafeInt("repetitions", 0),
)
} ?: emptyList(),

I've never written Kotlin code but if you can confirm that all I need to do is set that line to default to undefined I'm happy to make a pull request.

You can can recreate the issue by calling insertRecords like below with only ExerciseSession permissions
insertRecords([ { recordType: 'ExerciseSession', startTime: startDate.toISOString(), endTime: dateCompleted.toISOString(), exerciseType: ExerciseType.STRENGTH_TRAINING, title: 'Strength Training', }, ])

@matinzd matinzd self-assigned this Apr 23, 2024
matinzd added a commit that referenced this issue Apr 23, 2024
matinzd added a commit that referenced this issue Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants