mirror of
https://github.com/Monkopedia/rouse-context.git
synced 2026-11-29 11:13:05 +00:00
Fix #98: Add remaining ~26 Health Connect record types
Expands RecordTypeRegistry from 13 to 39 types, covering the full set of non-medical HC 1.1.0 record types: - Activity: TotalCaloriesBurned, BasalMetabolicRate, FloorsClimbed, ElevationGained, Speed, Power, CyclingPedalingCadence, StepsCadence, WheelchairPushes - Body: Height, BodyFat, BoneMass, LeanBodyMass, Vo2Max - Vitals: RestingHeartRate, HeartRateVariabilityRmssd, BodyTemperature, BasalBodyTemperature, SkinTemperature - Reproductive (new REPRODUCTIVE category): MenstruationFlow, MenstruationPeriod, CervicalMucus, OvulationTest, IntermenstrualBleeding, SexualActivity - Mindfulness (new MINDFULNESS category): MindfulnessSession The MindfulnessSession API is still marked @ExperimentalMindfulnessSessionApi in HC 1.1.0 but is fully available, so RealHealthConnectRepository opts in at the class level. Each type gets: a registry entry, matching query handler in RealHealthConnectRepository (2-4 most useful fields serialized), a <uses-permission> declaration in the health module manifest, and an entry in RECORD_CLASS_MAP. MenstruationFlow and MenstruationPeriod share READ_MENSTRUATION, and StepsCadence/CyclingPedalingCadence reuse READ_STEPS/READ_EXERCISE respectively, matching HC's own RECORD_TYPE_TO_PERMISSION map. Test coverage: - Expanded RecordTypeRegistryTest with expected-count, category-membership, and a new test that programmatically verifies every registry permission is declared in the manifest (preventing the silent-denial class of bug that motivated keeping these lists in sync).
This commit is contained in:
parent
35b0b53f2e
commit
c7db6c5c1c
4 changed files with 971 additions and 130 deletions
|
|
@ -2,21 +2,48 @@ package com.rousecontext.app.health
|
|||
|
||||
import android.content.Context
|
||||
import androidx.health.connect.client.HealthConnectClient
|
||||
import androidx.health.connect.client.feature.ExperimentalMindfulnessSessionApi
|
||||
import androidx.health.connect.client.permission.HealthPermission
|
||||
import androidx.health.connect.client.records.ActiveCaloriesBurnedRecord
|
||||
import androidx.health.connect.client.records.BasalBodyTemperatureRecord
|
||||
import androidx.health.connect.client.records.BasalMetabolicRateRecord
|
||||
import androidx.health.connect.client.records.BloodGlucoseRecord
|
||||
import androidx.health.connect.client.records.BloodPressureRecord
|
||||
import androidx.health.connect.client.records.BodyFatRecord
|
||||
import androidx.health.connect.client.records.BodyTemperatureRecord
|
||||
import androidx.health.connect.client.records.BoneMassRecord
|
||||
import androidx.health.connect.client.records.CervicalMucusRecord
|
||||
import androidx.health.connect.client.records.CyclingPedalingCadenceRecord
|
||||
import androidx.health.connect.client.records.DistanceRecord
|
||||
import androidx.health.connect.client.records.ElevationGainedRecord
|
||||
import androidx.health.connect.client.records.ExerciseSessionRecord
|
||||
import androidx.health.connect.client.records.FloorsClimbedRecord
|
||||
import androidx.health.connect.client.records.HeartRateRecord
|
||||
import androidx.health.connect.client.records.HeartRateVariabilityRmssdRecord
|
||||
import androidx.health.connect.client.records.HeightRecord
|
||||
import androidx.health.connect.client.records.HydrationRecord
|
||||
import androidx.health.connect.client.records.IntermenstrualBleedingRecord
|
||||
import androidx.health.connect.client.records.LeanBodyMassRecord
|
||||
import androidx.health.connect.client.records.MenstruationFlowRecord
|
||||
import androidx.health.connect.client.records.MenstruationPeriodRecord
|
||||
import androidx.health.connect.client.records.MindfulnessSessionRecord
|
||||
import androidx.health.connect.client.records.NutritionRecord
|
||||
import androidx.health.connect.client.records.OvulationTestRecord
|
||||
import androidx.health.connect.client.records.OxygenSaturationRecord
|
||||
import androidx.health.connect.client.records.PowerRecord
|
||||
import androidx.health.connect.client.records.Record
|
||||
import androidx.health.connect.client.records.RespiratoryRateRecord
|
||||
import androidx.health.connect.client.records.RestingHeartRateRecord
|
||||
import androidx.health.connect.client.records.SexualActivityRecord
|
||||
import androidx.health.connect.client.records.SkinTemperatureRecord
|
||||
import androidx.health.connect.client.records.SleepSessionRecord
|
||||
import androidx.health.connect.client.records.SpeedRecord
|
||||
import androidx.health.connect.client.records.StepsCadenceRecord
|
||||
import androidx.health.connect.client.records.StepsRecord
|
||||
import androidx.health.connect.client.records.TotalCaloriesBurnedRecord
|
||||
import androidx.health.connect.client.records.Vo2MaxRecord
|
||||
import androidx.health.connect.client.records.WeightRecord
|
||||
import androidx.health.connect.client.records.WheelchairPushesRecord
|
||||
import androidx.health.connect.client.request.ReadRecordsRequest
|
||||
import androidx.health.connect.client.time.TimeRangeFilter
|
||||
import com.rousecontext.mcp.health.HEALTH_DATA_HISTORY_PERMISSION
|
||||
|
|
@ -41,6 +68,8 @@ private typealias QueryHandler =
|
|||
* Lives in `:app` because it needs an Android [Context] to obtain the
|
||||
* [HealthConnectClient] instance.
|
||||
*/
|
||||
@Suppress("LargeClass", "TooManyFunctions")
|
||||
@OptIn(ExperimentalMindfulnessSessionApi::class)
|
||||
class RealHealthConnectRepository(private val context: Context) : HealthConnectRepository {
|
||||
|
||||
private val client: HealthConnectClient by lazy {
|
||||
|
|
@ -54,19 +83,52 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
private val dateFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||
|
||||
private val queryDispatchers: Map<String, QueryHandler> = mapOf(
|
||||
// Activity
|
||||
"Steps" to ::querySteps,
|
||||
"HeartRate" to ::queryHeartRate,
|
||||
"SleepSession" to ::querySleep,
|
||||
"ActiveCaloriesBurned" to ::queryActiveCalories,
|
||||
"TotalCaloriesBurned" to ::queryTotalCalories,
|
||||
"BasalMetabolicRate" to ::queryBasalMetabolicRate,
|
||||
"Distance" to ::queryDistance,
|
||||
"ElevationGained" to ::queryElevationGained,
|
||||
"FloorsClimbed" to ::queryFloorsClimbed,
|
||||
"ExerciseSession" to ::queryExercise,
|
||||
"Speed" to ::querySpeed,
|
||||
"Power" to ::queryPower,
|
||||
"CyclingPedalingCadence" to ::queryCyclingPedalingCadence,
|
||||
"StepsCadence" to ::queryStepsCadence,
|
||||
"WheelchairPushes" to ::queryWheelchairPushes,
|
||||
// Body
|
||||
"Weight" to ::queryWeight,
|
||||
"Height" to ::queryHeight,
|
||||
"BodyFat" to ::queryBodyFat,
|
||||
"BoneMass" to ::queryBoneMass,
|
||||
"LeanBodyMass" to ::queryLeanBodyMass,
|
||||
"Vo2Max" to ::queryVo2Max,
|
||||
// Sleep
|
||||
"SleepSession" to ::querySleep,
|
||||
// Vitals
|
||||
"HeartRate" to ::queryHeartRate,
|
||||
"RestingHeartRate" to ::queryRestingHeartRate,
|
||||
"HeartRateVariabilityRmssd" to ::queryHeartRateVariability,
|
||||
"BloodPressure" to ::queryBloodPressure,
|
||||
"BloodGlucose" to ::queryBloodGlucose,
|
||||
"ActiveCaloriesBurned" to ::queryActiveCalories,
|
||||
"Distance" to ::queryDistance,
|
||||
"ExerciseSession" to ::queryExercise,
|
||||
"Hydration" to ::queryHydration,
|
||||
"OxygenSaturation" to ::queryOxygenSaturation,
|
||||
"RespiratoryRate" to ::queryRespiratoryRate,
|
||||
"Nutrition" to ::queryNutrition
|
||||
"BodyTemperature" to ::queryBodyTemperature,
|
||||
"BasalBodyTemperature" to ::queryBasalBodyTemperature,
|
||||
"SkinTemperature" to ::querySkinTemperature,
|
||||
// Nutrition
|
||||
"Hydration" to ::queryHydration,
|
||||
"Nutrition" to ::queryNutrition,
|
||||
// Reproductive
|
||||
"MenstruationFlow" to ::queryMenstruationFlow,
|
||||
"MenstruationPeriod" to ::queryMenstruationPeriod,
|
||||
"CervicalMucus" to ::queryCervicalMucus,
|
||||
"OvulationTest" to ::queryOvulationTest,
|
||||
"IntermenstrualBleeding" to ::queryIntermenstrualBleeding,
|
||||
"SexualActivity" to ::querySexualActivity,
|
||||
// Mindfulness
|
||||
"MindfulnessSession" to ::queryMindfulnessSession
|
||||
)
|
||||
|
||||
override suspend fun queryRecords(
|
||||
|
|
@ -140,7 +202,7 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
}
|
||||
}
|
||||
|
||||
// --- Per-type query methods ---
|
||||
// --- Per-type query methods: Activity ---
|
||||
|
||||
private suspend fun querySteps(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(StepsRecord::class, from, to)
|
||||
|
|
@ -158,14 +220,127 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryHeartRate(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(HeartRateRecord::class, from, to)
|
||||
private suspend fun queryActiveCalories(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(ActiveCaloriesBurnedRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("kcal", record.energy.inKilocalories)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryTotalCalories(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(TotalCaloriesBurnedRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("kcal", record.energy.inKilocalories)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryBasalMetabolicRate(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(BasalMetabolicRateRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("watts", record.basalMetabolicRate.inWatts)
|
||||
put("kcal_per_day", record.basalMetabolicRate.inKilocaloriesPerDay)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryDistance(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(DistanceRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("meters", record.distance.inMeters)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryElevationGained(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(ElevationGainedRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("meters", record.elevation.inMeters)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryFloorsClimbed(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(FloorsClimbedRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("floors", record.floors)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryExercise(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(ExerciseSessionRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("exercise_type", record.exerciseType)
|
||||
record.title?.let { put("title", it) }
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun querySpeed(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(SpeedRecord::class, from, to)
|
||||
return records
|
||||
.flatMap { record ->
|
||||
record.samples.map { sample ->
|
||||
buildJsonObject {
|
||||
put("time", sample.time.toString())
|
||||
put("bpm", sample.beatsPerMinute)
|
||||
put("meters_per_second", sample.speed.inMetersPerSecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,6 +348,163 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryPower(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(PowerRecord::class, from, to)
|
||||
return records
|
||||
.flatMap { record ->
|
||||
record.samples.map { sample ->
|
||||
buildJsonObject {
|
||||
put("time", sample.time.toString())
|
||||
put("watts", sample.power.inWatts)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryCyclingPedalingCadence(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(CyclingPedalingCadenceRecord::class, from, to)
|
||||
return records
|
||||
.flatMap { record ->
|
||||
record.samples.map { sample ->
|
||||
buildJsonObject {
|
||||
put("time", sample.time.toString())
|
||||
put("rpm", sample.revolutionsPerMinute)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryStepsCadence(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(StepsCadenceRecord::class, from, to)
|
||||
return records
|
||||
.flatMap { record ->
|
||||
record.samples.map { sample ->
|
||||
buildJsonObject {
|
||||
put("time", sample.time.toString())
|
||||
put("steps_per_minute", sample.rate)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryWheelchairPushes(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(WheelchairPushesRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("count", record.count)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
// --- Per-type query methods: Body ---
|
||||
|
||||
private suspend fun queryWeight(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(WeightRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("kg", record.weight.inKilograms)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryHeight(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(HeightRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("meters", record.height.inMeters)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryBodyFat(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(BodyFatRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("percentage", record.percentage.value)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryBoneMass(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(BoneMassRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("kg", record.mass.inKilograms)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryLeanBodyMass(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(LeanBodyMassRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("kg", record.mass.inKilograms)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryVo2Max(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(Vo2MaxRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("ml_per_min_per_kg", record.vo2MillilitersPerMinuteKilogram)
|
||||
put("measurement_method", record.measurementMethod)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
// --- Per-type query methods: Sleep ---
|
||||
|
||||
private suspend fun querySleep(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(SleepSessionRecord::class, from, to)
|
||||
return records
|
||||
|
|
@ -192,13 +524,51 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryWeight(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(WeightRecord::class, from, to)
|
||||
// --- Per-type query methods: Vitals ---
|
||||
|
||||
private suspend fun queryHeartRate(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(HeartRateRecord::class, from, to)
|
||||
return records
|
||||
.flatMap { record ->
|
||||
record.samples.map { sample ->
|
||||
buildJsonObject {
|
||||
put("time", sample.time.toString())
|
||||
put("bpm", sample.beatsPerMinute)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryRestingHeartRate(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(RestingHeartRateRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("kg", record.weight.inKilograms)
|
||||
put("bpm", record.beatsPerMinute)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryHeartRateVariability(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(HeartRateVariabilityRmssdRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("rmssd_ms", record.heartRateVariabilityMillis)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
|
|
@ -240,63 +610,6 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryActiveCalories(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(ActiveCaloriesBurnedRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("kcal", record.energy.inKilocalories)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryDistance(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(DistanceRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("meters", record.distance.inMeters)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryExercise(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(ExerciseSessionRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("exercise_type", record.exerciseType)
|
||||
record.title?.let { put("title", it) }
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryHydration(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(HydrationRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("liters", record.volume.inLiters)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryOxygenSaturation(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
|
|
@ -331,6 +644,81 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryBodyTemperature(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(BodyTemperatureRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("celsius", record.temperature.inCelsius)
|
||||
put("measurement_location", record.measurementLocation)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryBasalBodyTemperature(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(BasalBodyTemperatureRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("celsius", record.temperature.inCelsius)
|
||||
put("measurement_location", record.measurementLocation)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun querySkinTemperature(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(SkinTemperatureRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
record.baseline?.let { put("baseline_celsius", it.inCelsius) }
|
||||
put("measurement_location", record.measurementLocation)
|
||||
put(
|
||||
"deltas",
|
||||
record.deltas.joinToString(",") { delta ->
|
||||
"""{"time":"${delta.time}","delta_celsius":${delta.delta.inCelsius}}"""
|
||||
}.let { "[$it]" }
|
||||
)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
// --- Per-type query methods: Nutrition ---
|
||||
|
||||
private suspend fun queryHydration(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(HydrationRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("liters", record.volume.inLiters)
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryNutrition(from: Instant, to: Instant, limit: Int?): List<JsonObject> {
|
||||
val records = readRecords(NutritionRecord::class, from, to)
|
||||
return records
|
||||
|
|
@ -348,6 +736,130 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
// --- Per-type query methods: Reproductive ---
|
||||
|
||||
private suspend fun queryMenstruationFlow(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(MenstruationFlowRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("flow", record.flow)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryMenstruationPeriod(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(MenstruationPeriodRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryCervicalMucus(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(CervicalMucusRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("appearance", record.appearance)
|
||||
put("sensation", record.sensation)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryOvulationTest(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(OvulationTestRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("result", record.result)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun queryIntermenstrualBleeding(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(IntermenstrualBleedingRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
private suspend fun querySexualActivity(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(SexualActivityRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("time", record.time.toString())
|
||||
put("protection_used", record.protectionUsed)
|
||||
}
|
||||
}
|
||||
.sortedBy { it["time"].toString() }
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
// --- Per-type query methods: Mindfulness ---
|
||||
|
||||
private suspend fun queryMindfulnessSession(
|
||||
from: Instant,
|
||||
to: Instant,
|
||||
limit: Int?
|
||||
): List<JsonObject> {
|
||||
val records = readRecords(MindfulnessSessionRecord::class, from, to)
|
||||
return records
|
||||
.map { record ->
|
||||
buildJsonObject {
|
||||
put("start_time", record.startTime.toString())
|
||||
put("end_time", record.endTime.toString())
|
||||
put("session_type", record.mindfulnessSessionType)
|
||||
record.title?.let { put("title", it) }
|
||||
record.notes?.let { put("notes", it) }
|
||||
}
|
||||
}
|
||||
.let { if (limit != null) it.take(limit) else it }
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
||||
private suspend fun <T : Record> readRecords(
|
||||
|
|
@ -379,19 +891,52 @@ class RealHealthConnectRepository(private val context: Context) : HealthConnectR
|
|||
|
||||
/** Map record type names to Health Connect SDK record classes. */
|
||||
val RECORD_CLASS_MAP: Map<String, KClass<out Record>> = mapOf(
|
||||
// Activity
|
||||
"Steps" to StepsRecord::class,
|
||||
"HeartRate" to HeartRateRecord::class,
|
||||
"SleepSession" to SleepSessionRecord::class,
|
||||
"ActiveCaloriesBurned" to ActiveCaloriesBurnedRecord::class,
|
||||
"TotalCaloriesBurned" to TotalCaloriesBurnedRecord::class,
|
||||
"BasalMetabolicRate" to BasalMetabolicRateRecord::class,
|
||||
"Distance" to DistanceRecord::class,
|
||||
"ElevationGained" to ElevationGainedRecord::class,
|
||||
"FloorsClimbed" to FloorsClimbedRecord::class,
|
||||
"ExerciseSession" to ExerciseSessionRecord::class,
|
||||
"Speed" to SpeedRecord::class,
|
||||
"Power" to PowerRecord::class,
|
||||
"CyclingPedalingCadence" to CyclingPedalingCadenceRecord::class,
|
||||
"StepsCadence" to StepsCadenceRecord::class,
|
||||
"WheelchairPushes" to WheelchairPushesRecord::class,
|
||||
// Body
|
||||
"Weight" to WeightRecord::class,
|
||||
"Height" to HeightRecord::class,
|
||||
"BodyFat" to BodyFatRecord::class,
|
||||
"BoneMass" to BoneMassRecord::class,
|
||||
"LeanBodyMass" to LeanBodyMassRecord::class,
|
||||
"Vo2Max" to Vo2MaxRecord::class,
|
||||
// Sleep
|
||||
"SleepSession" to SleepSessionRecord::class,
|
||||
// Vitals
|
||||
"HeartRate" to HeartRateRecord::class,
|
||||
"RestingHeartRate" to RestingHeartRateRecord::class,
|
||||
"HeartRateVariabilityRmssd" to HeartRateVariabilityRmssdRecord::class,
|
||||
"BloodPressure" to BloodPressureRecord::class,
|
||||
"BloodGlucose" to BloodGlucoseRecord::class,
|
||||
"ActiveCaloriesBurned" to ActiveCaloriesBurnedRecord::class,
|
||||
"Distance" to DistanceRecord::class,
|
||||
"ExerciseSession" to ExerciseSessionRecord::class,
|
||||
"Hydration" to HydrationRecord::class,
|
||||
"OxygenSaturation" to OxygenSaturationRecord::class,
|
||||
"RespiratoryRate" to RespiratoryRateRecord::class,
|
||||
"Nutrition" to NutritionRecord::class
|
||||
"BodyTemperature" to BodyTemperatureRecord::class,
|
||||
"BasalBodyTemperature" to BasalBodyTemperatureRecord::class,
|
||||
"SkinTemperature" to SkinTemperatureRecord::class,
|
||||
// Nutrition
|
||||
"Hydration" to HydrationRecord::class,
|
||||
"Nutrition" to NutritionRecord::class,
|
||||
// Reproductive
|
||||
"MenstruationFlow" to MenstruationFlowRecord::class,
|
||||
"MenstruationPeriod" to MenstruationPeriodRecord::class,
|
||||
"CervicalMucus" to CervicalMucusRecord::class,
|
||||
"OvulationTest" to OvulationTestRecord::class,
|
||||
"IntermenstrualBleeding" to IntermenstrualBleedingRecord::class,
|
||||
"SexualActivity" to SexualActivityRecord::class,
|
||||
// Mindfulness
|
||||
"MindfulnessSession" to MindfulnessSessionRecord::class
|
||||
)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -13,19 +13,59 @@
|
|||
declared here, otherwise Health Connect silently refuses to grant it
|
||||
even when the user toggles it on in HC's settings UI. Keep this list
|
||||
in sync with RecordTypeRegistry.
|
||||
|
||||
The RecordTypeRegistryTest `all permissions match AndroidManifest` test
|
||||
verifies every registry entry has a matching <uses-permission> below.
|
||||
-->
|
||||
|
||||
<!-- Activity -->
|
||||
<uses-permission android:name="android.permission.health.READ_STEPS" />
|
||||
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
|
||||
<uses-permission android:name="android.permission.health.READ_SLEEP" />
|
||||
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
|
||||
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
|
||||
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
|
||||
<uses-permission android:name="android.permission.health.READ_DISTANCE" />
|
||||
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />
|
||||
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
|
||||
<uses-permission android:name="android.permission.health.READ_EXERCISE" />
|
||||
<uses-permission android:name="android.permission.health.READ_SPEED" />
|
||||
<uses-permission android:name="android.permission.health.READ_POWER" />
|
||||
<uses-permission android:name="android.permission.health.READ_WHEELCHAIR_PUSHES" />
|
||||
|
||||
<!-- Body -->
|
||||
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
|
||||
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
|
||||
<uses-permission android:name="android.permission.health.READ_BODY_FAT" />
|
||||
<uses-permission android:name="android.permission.health.READ_BONE_MASS" />
|
||||
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS" />
|
||||
<uses-permission android:name="android.permission.health.READ_VO2_MAX" />
|
||||
|
||||
<!-- Sleep -->
|
||||
<uses-permission android:name="android.permission.health.READ_SLEEP" />
|
||||
|
||||
<!-- Vitals -->
|
||||
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
|
||||
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
|
||||
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
|
||||
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
|
||||
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
|
||||
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
|
||||
<uses-permission android:name="android.permission.health.READ_DISTANCE" />
|
||||
<uses-permission android:name="android.permission.health.READ_EXERCISE" />
|
||||
<uses-permission android:name="android.permission.health.READ_HYDRATION" />
|
||||
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
|
||||
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />
|
||||
<uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />
|
||||
<uses-permission android:name="android.permission.health.READ_BASAL_BODY_TEMPERATURE" />
|
||||
<uses-permission android:name="android.permission.health.READ_SKIN_TEMPERATURE" />
|
||||
|
||||
<!-- Nutrition -->
|
||||
<uses-permission android:name="android.permission.health.READ_HYDRATION" />
|
||||
<uses-permission android:name="android.permission.health.READ_NUTRITION" />
|
||||
|
||||
<!-- Reproductive / cycle tracking -->
|
||||
<uses-permission android:name="android.permission.health.READ_MENSTRUATION" />
|
||||
<uses-permission android:name="android.permission.health.READ_CERVICAL_MUCUS" />
|
||||
<uses-permission android:name="android.permission.health.READ_OVULATION_TEST" />
|
||||
<uses-permission android:name="android.permission.health.READ_INTERMENSTRUAL_BLEEDING" />
|
||||
<uses-permission android:name="android.permission.health.READ_SEXUAL_ACTIVITY" />
|
||||
|
||||
<!-- Mindfulness -->
|
||||
<uses-permission android:name="android.permission.health.READ_MINDFULNESS" />
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ enum class RecordCategory(val value: String) {
|
|||
BODY("body"),
|
||||
SLEEP("sleep"),
|
||||
VITALS("vitals"),
|
||||
NUTRITION("nutrition")
|
||||
NUTRITION("nutrition"),
|
||||
REPRODUCTIVE("reproductive"),
|
||||
MINDFULNESS("mindfulness")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -36,6 +38,7 @@ enum class RecordCategory(val value: String) {
|
|||
object RecordTypeRegistry {
|
||||
|
||||
private val types: Map<String, RecordTypeInfo> = listOf(
|
||||
// --- Activity ---
|
||||
RecordTypeInfo(
|
||||
name = "Steps",
|
||||
displayName = "Steps",
|
||||
|
|
@ -44,12 +47,135 @@ object RecordTypeRegistry {
|
|||
readPermission = "android.permission.health.READ_STEPS"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "HeartRate",
|
||||
displayName = "Heart Rate",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Heart rate samples in beats per minute",
|
||||
readPermission = "android.permission.health.READ_HEART_RATE"
|
||||
name = "ActiveCaloriesBurned",
|
||||
displayName = "Active Calories",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Calories burned during activity",
|
||||
readPermission = "android.permission.health.READ_ACTIVE_CALORIES_BURNED"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "TotalCaloriesBurned",
|
||||
displayName = "Total Calories",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Total energy expenditure including basal metabolism",
|
||||
readPermission = "android.permission.health.READ_TOTAL_CALORIES_BURNED"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "BasalMetabolicRate",
|
||||
displayName = "Basal Metabolic Rate",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Resting energy expenditure in watts",
|
||||
readPermission = "android.permission.health.READ_BASAL_METABOLIC_RATE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Distance",
|
||||
displayName = "Distance",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Distance traveled in meters",
|
||||
readPermission = "android.permission.health.READ_DISTANCE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "ElevationGained",
|
||||
displayName = "Elevation Gained",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Vertical distance climbed in meters",
|
||||
readPermission = "android.permission.health.READ_ELEVATION_GAINED"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "FloorsClimbed",
|
||||
displayName = "Floors Climbed",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Number of floors ascended",
|
||||
readPermission = "android.permission.health.READ_FLOORS_CLIMBED"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "ExerciseSession",
|
||||
displayName = "Exercise",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Exercise/workout sessions with type and duration",
|
||||
readPermission = "android.permission.health.READ_EXERCISE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Speed",
|
||||
displayName = "Speed",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Movement speed samples in meters per second",
|
||||
readPermission = "android.permission.health.READ_SPEED"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Power",
|
||||
displayName = "Power",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Power output samples in watts",
|
||||
readPermission = "android.permission.health.READ_POWER"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "CyclingPedalingCadence",
|
||||
displayName = "Cycling Cadence",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Cycling pedaling cadence in RPM",
|
||||
readPermission = "android.permission.health.READ_EXERCISE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "StepsCadence",
|
||||
displayName = "Steps Cadence",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Step rate samples in steps per minute",
|
||||
readPermission = "android.permission.health.READ_STEPS"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "WheelchairPushes",
|
||||
displayName = "Wheelchair Pushes",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Wheelchair push counts",
|
||||
readPermission = "android.permission.health.READ_WHEELCHAIR_PUSHES"
|
||||
),
|
||||
|
||||
// --- Body ---
|
||||
RecordTypeInfo(
|
||||
name = "Weight",
|
||||
displayName = "Weight",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Body weight measurements in kilograms",
|
||||
readPermission = "android.permission.health.READ_WEIGHT"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Height",
|
||||
displayName = "Height",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Body height measurements in meters",
|
||||
readPermission = "android.permission.health.READ_HEIGHT"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "BodyFat",
|
||||
displayName = "Body Fat",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Body fat percentage",
|
||||
readPermission = "android.permission.health.READ_BODY_FAT"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "BoneMass",
|
||||
displayName = "Bone Mass",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Bone mass in kilograms",
|
||||
readPermission = "android.permission.health.READ_BONE_MASS"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "LeanBodyMass",
|
||||
displayName = "Lean Body Mass",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Lean body mass in kilograms",
|
||||
readPermission = "android.permission.health.READ_LEAN_BODY_MASS"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Vo2Max",
|
||||
displayName = "VO2 Max",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Maximal oxygen uptake in mL/min/kg",
|
||||
readPermission = "android.permission.health.READ_VO2_MAX"
|
||||
),
|
||||
|
||||
// --- Sleep ---
|
||||
RecordTypeInfo(
|
||||
name = "SleepSession",
|
||||
displayName = "Sleep",
|
||||
|
|
@ -57,12 +183,28 @@ object RecordTypeRegistry {
|
|||
description = "Sleep sessions with stage breakdowns",
|
||||
readPermission = "android.permission.health.READ_SLEEP"
|
||||
),
|
||||
|
||||
// --- Vitals ---
|
||||
RecordTypeInfo(
|
||||
name = "Weight",
|
||||
displayName = "Weight",
|
||||
category = RecordCategory.BODY,
|
||||
description = "Body weight measurements in kilograms",
|
||||
readPermission = "android.permission.health.READ_WEIGHT"
|
||||
name = "HeartRate",
|
||||
displayName = "Heart Rate",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Heart rate samples in beats per minute",
|
||||
readPermission = "android.permission.health.READ_HEART_RATE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "RestingHeartRate",
|
||||
displayName = "Resting Heart Rate",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Resting heart rate in beats per minute",
|
||||
readPermission = "android.permission.health.READ_RESTING_HEART_RATE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "HeartRateVariabilityRmssd",
|
||||
displayName = "Heart Rate Variability",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Heart rate variability (RMSSD) in milliseconds",
|
||||
readPermission = "android.permission.health.READ_HEART_RATE_VARIABILITY"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "BloodPressure",
|
||||
|
|
@ -78,34 +220,6 @@ object RecordTypeRegistry {
|
|||
description = "Blood glucose readings in mmol/L",
|
||||
readPermission = "android.permission.health.READ_BLOOD_GLUCOSE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "ActiveCaloriesBurned",
|
||||
displayName = "Active Calories",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Calories burned during activity",
|
||||
readPermission = "android.permission.health.READ_ACTIVE_CALORIES_BURNED"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Distance",
|
||||
displayName = "Distance",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Distance traveled in meters",
|
||||
readPermission = "android.permission.health.READ_DISTANCE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "ExerciseSession",
|
||||
displayName = "Exercise",
|
||||
category = RecordCategory.ACTIVITY,
|
||||
description = "Exercise/workout sessions with type and duration",
|
||||
readPermission = "android.permission.health.READ_EXERCISE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Hydration",
|
||||
displayName = "Hydration",
|
||||
category = RecordCategory.NUTRITION,
|
||||
description = "Fluid intake in liters",
|
||||
readPermission = "android.permission.health.READ_HYDRATION"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "OxygenSaturation",
|
||||
displayName = "Oxygen Saturation",
|
||||
|
|
@ -120,12 +234,95 @@ object RecordTypeRegistry {
|
|||
description = "Breaths per minute",
|
||||
readPermission = "android.permission.health.READ_RESPIRATORY_RATE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "BodyTemperature",
|
||||
displayName = "Body Temperature",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Body temperature in Celsius",
|
||||
readPermission = "android.permission.health.READ_BODY_TEMPERATURE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "BasalBodyTemperature",
|
||||
displayName = "Basal Body Temperature",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Basal body temperature in Celsius",
|
||||
readPermission = "android.permission.health.READ_BASAL_BODY_TEMPERATURE"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "SkinTemperature",
|
||||
displayName = "Skin Temperature",
|
||||
category = RecordCategory.VITALS,
|
||||
description = "Skin temperature baseline and deltas in Celsius",
|
||||
readPermission = "android.permission.health.READ_SKIN_TEMPERATURE"
|
||||
),
|
||||
|
||||
// --- Nutrition ---
|
||||
RecordTypeInfo(
|
||||
name = "Hydration",
|
||||
displayName = "Hydration",
|
||||
category = RecordCategory.NUTRITION,
|
||||
description = "Fluid intake in liters",
|
||||
readPermission = "android.permission.health.READ_HYDRATION"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "Nutrition",
|
||||
displayName = "Nutrition",
|
||||
category = RecordCategory.NUTRITION,
|
||||
description = "Nutritional intake including calories, macros, and micronutrients",
|
||||
readPermission = "android.permission.health.READ_NUTRITION"
|
||||
),
|
||||
|
||||
// --- Reproductive / cycle tracking ---
|
||||
RecordTypeInfo(
|
||||
name = "MenstruationFlow",
|
||||
displayName = "Menstruation Flow",
|
||||
category = RecordCategory.REPRODUCTIVE,
|
||||
description = "Menstrual flow intensity (light/medium/heavy)",
|
||||
readPermission = "android.permission.health.READ_MENSTRUATION"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "MenstruationPeriod",
|
||||
displayName = "Menstruation Period",
|
||||
category = RecordCategory.REPRODUCTIVE,
|
||||
description = "Start and end of a menstruation period",
|
||||
readPermission = "android.permission.health.READ_MENSTRUATION"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "CervicalMucus",
|
||||
displayName = "Cervical Mucus",
|
||||
category = RecordCategory.REPRODUCTIVE,
|
||||
description = "Cervical mucus appearance and sensation",
|
||||
readPermission = "android.permission.health.READ_CERVICAL_MUCUS"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "OvulationTest",
|
||||
displayName = "Ovulation Test",
|
||||
category = RecordCategory.REPRODUCTIVE,
|
||||
description = "Ovulation test results",
|
||||
readPermission = "android.permission.health.READ_OVULATION_TEST"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "IntermenstrualBleeding",
|
||||
displayName = "Intermenstrual Bleeding",
|
||||
category = RecordCategory.REPRODUCTIVE,
|
||||
description = "Bleeding outside of a menstrual period",
|
||||
readPermission = "android.permission.health.READ_INTERMENSTRUAL_BLEEDING"
|
||||
),
|
||||
RecordTypeInfo(
|
||||
name = "SexualActivity",
|
||||
displayName = "Sexual Activity",
|
||||
category = RecordCategory.REPRODUCTIVE,
|
||||
description = "Sexual activity with protection status",
|
||||
readPermission = "android.permission.health.READ_SEXUAL_ACTIVITY"
|
||||
),
|
||||
|
||||
// --- Mindfulness ---
|
||||
RecordTypeInfo(
|
||||
name = "MindfulnessSession",
|
||||
displayName = "Mindfulness",
|
||||
category = RecordCategory.MINDFULNESS,
|
||||
description = "Mindfulness sessions (meditation, breathing, etc.)",
|
||||
readPermission = "android.permission.health.READ_MINDFULNESS"
|
||||
)
|
||||
).associateBy { it.name }
|
||||
|
||||
|
|
|
|||
|
|
@ -38,22 +38,81 @@ class RecordTypeRegistryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `allPermissions returns one per type`() {
|
||||
assertEquals(
|
||||
RecordTypeRegistry.allTypes.size,
|
||||
RecordTypeRegistry.allPermissions.size
|
||||
)
|
||||
fun `allPermissions is non-empty and a subset of distinct type permissions`() {
|
||||
val typePermissions = RecordTypeRegistry.allTypes.map { it.readPermission }.toSet()
|
||||
assertEquals(typePermissions, RecordTypeRegistry.allPermissions)
|
||||
assertTrue(RecordTypeRegistry.allPermissions.isNotEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `known types are present`() {
|
||||
val expected = listOf(
|
||||
// Original 13
|
||||
"Steps", "HeartRate", "SleepSession", "Weight", "BloodPressure",
|
||||
"ActiveCaloriesBurned", "Distance", "ExerciseSession",
|
||||
"Hydration", "OxygenSaturation", "RespiratoryRate", "Nutrition"
|
||||
"BloodGlucose", "ActiveCaloriesBurned", "Distance", "ExerciseSession",
|
||||
"Hydration", "OxygenSaturation", "RespiratoryRate", "Nutrition",
|
||||
// Body additions
|
||||
"Height", "BodyFat", "BoneMass", "LeanBodyMass", "Vo2Max",
|
||||
// Vitals additions
|
||||
"HeartRateVariabilityRmssd", "RestingHeartRate",
|
||||
"BodyTemperature", "BasalBodyTemperature", "SkinTemperature",
|
||||
// Activity additions
|
||||
"TotalCaloriesBurned", "BasalMetabolicRate", "FloorsClimbed",
|
||||
"Speed", "Power", "ElevationGained", "CyclingPedalingCadence",
|
||||
"StepsCadence", "WheelchairPushes",
|
||||
// Reproductive
|
||||
"MenstruationFlow", "MenstruationPeriod", "CervicalMucus",
|
||||
"OvulationTest", "IntermenstrualBleeding", "SexualActivity",
|
||||
// Mindfulness
|
||||
"MindfulnessSession"
|
||||
)
|
||||
for (name in expected) {
|
||||
assertNotNull("Missing type: $name", RecordTypeRegistry[name])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `expected total type count`() {
|
||||
// 13 original + 5 body + 5 vitals + 9 activity + 6 reproductive + 1 mindfulness = 39
|
||||
assertEquals(39, RecordTypeRegistry.allTypes.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `menstruation flow and period share the same permission`() {
|
||||
val flow = RecordTypeRegistry["MenstruationFlow"]!!
|
||||
val period = RecordTypeRegistry["MenstruationPeriod"]!!
|
||||
assertEquals(flow.readPermission, period.readPermission)
|
||||
assertEquals("android.permission.health.READ_MENSTRUATION", flow.readPermission)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `reproductive category is used`() {
|
||||
val reproductive = RecordTypeRegistry.allTypes
|
||||
.filter { it.category == RecordCategory.REPRODUCTIVE }
|
||||
.map { it.name }
|
||||
.toSet()
|
||||
assertEquals(
|
||||
setOf(
|
||||
"MenstruationFlow",
|
||||
"MenstruationPeriod",
|
||||
"CervicalMucus",
|
||||
"OvulationTest",
|
||||
"IntermenstrualBleeding",
|
||||
"SexualActivity"
|
||||
),
|
||||
reproductive
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `all permissions match AndroidManifest`() {
|
||||
// Load the manifest file relative to the module root.
|
||||
val manifest = java.io.File("src/main/AndroidManifest.xml").readText()
|
||||
for (info in RecordTypeRegistry.allTypes) {
|
||||
assertTrue(
|
||||
"Manifest missing permission ${info.readPermission} for ${info.name}",
|
||||
manifest.contains("android:name=\"${info.readPermission}\"")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue