# FakeHealthConnectClient

Artifact: [androidx.health.connect:connect-testing](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/testing/FakeHealthConnectClient.kt+class:androidx.health.connect.client.testing.FakeHealthConnectClient) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

*** ** * ** ***


```
class FakeHealthConnectClient : HealthConnectClient
```

<br />

*** ** * ** ***

Fake `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient` to be used in tests for components that use it as a dependency.

Features:

- Add, remove, delete and read records using an in-memory object, supporting pagination.

- Token generation and change tracking.

- Stub aggregation responses with `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClientOverrides#aggregate()`, `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClientOverrides#aggregateGroupByDuration()` and `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClientOverrides#aggregateGroupByPeriod()`.

- Stubs for every call, using the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#overrides()` property to set responses and exceptions.

Note that this fake does not check for permissions.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#DEFAULT_PACKAGE_NAME()` Default package name used in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#FakeHealthConnectClient(kotlin.String,java.time.Clock,androidx.health.connect.client.PermissionController)( packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, clock: https://developer.android.com/reference/java/time/Clock.html, permissionController: https://developer.android.com/reference/kotlin/androidx/health/connect/client/PermissionController )` |

| ### Public functions |
|---|---|
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#aggregate(androidx.health.connect.client.request.AggregateRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateRequest)` |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByDuration>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#aggregateGroupByDuration(androidx.health.connect.client.request.AggregateGroupByDurationRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByDurationRequest)` |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResultGroupedByPeriod>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#aggregateGroupByPeriod(androidx.health.connect.client.request.AggregateGroupByPeriodRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/AggregateGroupByPeriodRequest)` |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)( recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>, timeRangeFilter: https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter )` Deletes any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` in the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` (automatically filtered to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` belonging to the calling application). |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#deleteRecords(kotlin.reflect.KClass,kotlin.collections.List,kotlin.collections.List)( recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>, recordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, clientRecordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` Deletes one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` by their identifiers. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#expireToken(kotlin.String)(token: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Set a particular token as expired. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChanges(kotlin.String)(changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Retrieves changes in Health Connect, from a specific point in time represented by provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)`. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChanges(kotlin.String,kotlin.Int)(changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, pageSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 5000) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Same as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)` method but also allows specifying a preferred `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ChangesTokenRequest)` Returns a fake token which contains the key to the next change. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/InsertRecordsResponse` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#insertRecords(kotlin.collections.List)(records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>)` Fake implementation that inserts one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s into the in-memory store. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordResponse<T>` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)(recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<T>, recordId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Reads one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` point with its `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)` and `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)`. |
| `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordsResponse<T>` | `<T : https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record> https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#readRecords(androidx.health.connect.client.request.ReadRecordsRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadRecordsRequest<T>)` Returns records that match the attributes in a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadRecordsRequest`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#setPackageName(kotlin.String)(newPackage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Sets the package name used by the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient`. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#updateRecords(kotlin.collections.List)(records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>)` Updates one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of given UIDs to newly specified values. |

| ### Public properties |
|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectFeatures` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#features()` Access operations related to feature availability. |
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClientOverrides` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#overrides()` Used to override or intercept responses to emulate scenarios that this fake doesn't support. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#pageSizeGetChanges()` Overrides the page size to test pagination when calling `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChanges(kotlin.String)`. |
| `open https://developer.android.com/reference/kotlin/androidx/health/connect/client/PermissionController` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#permissionController()` grants and revokes permissions. |

### Inherited functions

From [androidx.health.connect.client.HealthConnectClient](https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient) `open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingResponse` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/ExperimentalMatchmakingApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#checkIfMatchmakingIsPossible(androidx.health.connect.client.matchmaking.MatchmakingRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest)`

Checks if launching the intent returned by `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)` with the same arguments will result in showing at least one matching application or device.
`open https://developer.android.com/reference/android/content/Intent.html` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/ExperimentalMatchmakingApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMatchmakingIntent(androidx.health.connect.client.matchmaking.MatchmakingRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/matchmaking/MatchmakingRequest)`

Creates an `https://developer.android.com/reference/android/content/Intent.html` to launch a Health Connect flow where users can:
`open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#createMedicalDataSource(androidx.health.connect.client.request.CreateMedicalDataSourceRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest)`

Creates a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` using a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/CreateMedicalDataSourceRequest`.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalDataSourceWithData(kotlin.String)(id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`

Deletes a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource` and all data contained within it.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(kotlin.collections.List)(ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId>)`

Deletes a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s by the provided list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId`s.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteMedicalResources(androidx.health.connect.client.request.DeleteMedicalResourcesRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/DeleteMedicalResourcesRequest)`

Deletes `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s based on given filters in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/DeleteMedicalResourcesRequest`.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource>` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(kotlin.collections.List)(ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>)`

Gets `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s for the provided list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource#id()`.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource>` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getMedicalDataSources(androidx.health.connect.client.request.GetMedicalDataSourcesRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest)`

Gets the requested `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalDataSource`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/GetMedicalDataSourcesRequest`.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource>` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readMedicalResources(kotlin.collections.List)(ids: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId>)`

Reads a collection of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s given a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResourceId`s.
`open suspend https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadMedicalResourcesResponse` `@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readMedicalResources(androidx.health.connect.client.request.ReadMedicalResourcesRequest)(request: https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesRequest)`

Reads `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s by request, either `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesInitialRequest` or `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadMedicalResourcesPageRequest`.
`open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.health.WRITE_MEDICAL_DATA")
@https://developer.android.com/reference/kotlin/androidx/health/connect/client/feature/ExperimentalPersonalHealthRecordApi
https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#upsertMedicalResources(kotlin.collections.List)(requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest>)`

Inserts or updates a list of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/MedicalResource`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/UpsertMedicalResourceRequest`s.

## Constants

### DEFAULT_PACKAGE_NAME

```
const val DEFAULT_PACKAGE_NAME: String
```

Default package name used in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient`.

## Public constructors

### FakeHealthConnectClient

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
FakeHealthConnectClient(
    packageName: String = DEFAULT_PACKAGE_NAME,
    clock: Clock = Clock.systemDefaultZone(),
    permissionController: PermissionController = FakePermissionController()
)
```

| Parameters |
|---|---|
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = DEFAULT_PACKAGE_NAME` | the name of the package to use to generate unique record IDs. |
| `clock: https://developer.android.com/reference/java/time/Clock.html = Clock.systemDefaultZone()` | used to close open-ended `https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter`s and record update times. |
| `permissionController: https://developer.android.com/reference/kotlin/androidx/health/connect/client/PermissionController = FakePermissionController()` | grants and revokes permissions. |

## Public functions

### aggregate

```
open suspend fun aggregate(request: AggregateRequest): AggregationResult
```

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if no overrides are configured. |

### aggregateGroupByDuration

```
open suspend fun aggregateGroupByDuration(request: AggregateGroupByDurationRequest): List<AggregationResultGroupedByDuration>
```

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if no overrides are configured. |

### aggregateGroupByPeriod

```
open suspend fun aggregateGroupByPeriod(request: AggregateGroupByPeriodRequest): List<AggregationResultGroupedByPeriod>
```

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if no overrides are configured. |

### deleteRecords

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
open suspend fun deleteRecords(
    recordType: KClass<Record>,
    timeRangeFilter: TimeRangeFilter
): Unit
```

Deletes any `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` in the given `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)` (automatically filtered to `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` belonging to the calling application). Deletion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` is executed in a transaction - if one fails, none is deleted.

```kotlin
import androidx.health.connect.client.deleteRecords
import androidx.health.connect.client.records.StepsRecord
import androidx.health.connect.client.time.TimeRangeFilter

healthConnectClient.deleteRecords<StepsRecord>(
    timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
)
```

| Parameters |
|---|---|
| `recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete, such as `StepsRecord::class` |
| `timeRangeFilter: https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter` | The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter` to delete from |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example usage to delete written steps data in a time range: |

### deleteRecords

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
open suspend fun deleteRecords(
    recordType: KClass<Record>,
    recordIdsList: List<String>,
    clientRecordIdsList: List<String>
): Unit
```

Deletes one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` by their identifiers. Deletion of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` is executed in single transaction - if one fails, none is deleted.

```kotlin
import androidx.health.connect.client.deleteRecords
import androidx.health.connect.client.records.StepsRecord

healthConnectClient.deleteRecords<StepsRecord>(
    recordIdsList = listOf(uid1, uid2),
    clientRecordIdsList = emptyList(),
)
```

| Parameters |
|---|---|
| `recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete, such as `Steps::class` |
| `recordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | List of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete |
| `clientRecordIdsList: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | List of client record IDs of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to delete |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Deleting by invalid identifiers such as a non-existing identifier or deleting the same record multiple times will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. Example usage to delete written steps data by its unique identifier: |

### expireToken

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
fun expireToken(token: String): Unit
```

Set a particular token as expired. This is used to test the response of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChanges(kotlin.String)`.

### getChanges

```
open suspend fun getChanges(changesToken: String): ChangesResponse
```

Retrieves changes in Health Connect, from a specific point in time represented by provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)`.

The response returned may not provide all the changes due to IPC or memory limits, see `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#hasMore()`. Clients can make more api calls to fetch more changes from Health Connect with updated `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#nextChangesToken()`.

Provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)` may have expired if clients have not synced for extended period of time (such as a month). In this case `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse#changesTokenExpired()` will be set, and clients should generate a new changes-token via `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)`.

```kotlin
val response = client.getChanges(changesToken)
if (response.changesTokenExpired) {
  // Consider re-sync and fetch new changes token.
} else {
  // Process new insertion/deletions, either update local storage or upload to backends.
}
```

| Parameters |
|---|---|
| `changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A changes token that represents a specific point in time in Android Health Platform. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` with changes since provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)` |   |

### getChanges

```
open suspend fun getChanges(changesToken: String, pageSize: @IntRange(from = 1, to = 5000) Int): ChangesResponse
```

Same as `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)` method but also allows specifying a preferred `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`.

`https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)` is a soft limit that serves as a recommendation to the system. The system makes best attempt to limit the number of returned change logs, however in certain cases the response might exceed the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`.

| Parameters |
|---|---|
| `changesToken: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A changes token that represents a specific point in time in Android Health Platform. |
| `pageSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 5000) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The (soft) limit of change logs to return, must be within 1, 5000. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` | a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ChangesResponse` with changes since provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChanges(kotlin.String,kotlin.Int)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#getChangesToken(androidx.health.connect.client.request.ChangesTokenRequest)` |   |

### getChangesToken

```
open suspend fun getChangesToken(request: ChangesTokenRequest): String
```

Returns a fake token which contains the key to the next change. Used with `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChanges(kotlin.String)` to track changes from the moment this function is called.

### insertRecords

```
open suspend fun insertRecords(records: List<Record>): InsertRecordsResponse
```

Fake implementation that inserts one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record`s into the in-memory store.

Supports deduplication of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#clientRecordId()`s using `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#clientRecordVersion()` to determine precedence.

### readRecord

```
open suspend fun <T : Record> readRecord(recordType: KClass<T>, recordId: String): ReadRecordResponse<T>
```

Reads one `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` point with its `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)` and `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#readRecord(kotlin.reflect.KClass,kotlin.String)`.

| Parameters |
|---|---|
| `recordType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<T>` | Which type of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to read, such as `Steps::class` |
| `recordId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata#id()` of `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` to read |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/response/ReadRecordResponse<T>` | The `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` data point. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Update with invalid identifiers will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |

### readRecords

```
open suspend fun <T : Record> readRecords(request: ReadRecordsRequest<T>): ReadRecordsResponse<T>
```

Returns records that match the attributes in a `https://developer.android.com/reference/kotlin/androidx/health/connect/client/request/ReadRecordsRequest`.

Features a simple paging implementation. Records must not be updated in between calls.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if paging is requested. |

### setPackageName

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
fun setPackageName(newPackage: String): Unit
```

Sets the package name used by the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient`.

This method overrides the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#DEFAULT_PACKAGE_NAME()` and designates the provided `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#setPackageName(kotlin.String)` as the caller for all subsequent method invocations on this `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient` instance.

| Parameters |
|---|---|
| `newPackage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The package name to be used for all calls to the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient`. |

### updateRecords

```
open suspend fun updateRecords(records: List<Record>): Unit
```

Updates one or more `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record` of given UIDs to newly specified values. Update of multiple `https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#updateRecords(kotlin.collections.List)` is executed in a transaction - if one fails, none is inserted.

| Parameters |
|---|---|
| `records: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record>` | List of records to update |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | For any IPC transportation failures. Update with invalid identifiers will result in IPC failure. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | For requests with unpermitted access. |
| `https://developer.android.com/reference/java/io/IOException.html` | For any disk I/O issues. |

## Public properties

### features

```
open val features: HealthConnectFeatures
```

Access operations related to feature availability.

### overrides

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
val overrides: FakeHealthConnectClientOverrides
```

Used to override or intercept responses to emulate scenarios that this fake doesn't support.

Every call in `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient` can be overridden.

For example:

```kotlin
import androidx.health.connect.client.testing.stubs.stub

// Sets a default return value for client.aggregate() and a queue with one item.
client.overrides.aggregate = stub(queue = listOf(resultOnce)) { result }
```

```kotlin
import androidx.health.connect.client.aggregate.AggregationResult
import androidx.health.connect.client.testing.AggregationResult
import androidx.health.connect.client.testing.stubs.MutableStub
import androidx.health.connect.client.testing.stubs.enqueue

// Sets a default exception that will be thrown for client.aggregate().
val aggregationStub = MutableStub<AggregationResult>(exception)
client.overrides.aggregate = aggregationStub

// Only the first call to client.aggregate() will return this result. Subsequent calls will
// throw the default.
aggregationStub.enqueue(result)

// Setting a default response removes the default exception.
aggregationStub.defaultHandler = { AggregationResult() }
```

```kotlin
import androidx.health.connect.client.aggregate.AggregationResult
import androidx.health.connect.client.records.ExerciseSessionRecord
import androidx.health.connect.client.records.HeartRateRecord
import androidx.health.connect.client.testing.AggregationResult
import androidx.health.connect.client.testing.stubs.stub

val result =
    AggregationResult(
        metrics =
            buildMap {
                put(HeartRateRecord.BPM_AVG, 74.0)
                put(ExerciseSessionRecord.EXERCISE_DURATION_TOTAL, Duration.ofMinutes(30))
            }
    )
client.overrides.aggregate = stub(result)
```

```kotlin
import androidx.health.connect.client.aggregate.AggregationResult
import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration
import androidx.health.connect.client.testing.AggregationResult
import androidx.health.connect.client.testing.stubs.stub

val result = buildList {
    add(
        AggregationResultGroupedByDuration(
            aggregationResult1,
            startTime1,
            endTime1,
            ZoneOffset.UTC,
        )
    )
    add(
        AggregationResultGroupedByDuration(
            aggregationResult2,
            startTime2,
            endTime2,
            ZoneOffset.UTC,
        )
    )
}
client.overrides.aggregateGroupByDuration = stub(default = result)
```

```kotlin
import androidx.health.connect.client.aggregate.AggregationResult
import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod
import androidx.health.connect.client.testing.AggregationResult
import androidx.health.connect.client.testing.stubs.stub

val result = buildList {
    add(AggregationResultGroupedByPeriod(aggregationResult1, startTime1, endTime1))
    add(AggregationResultGroupedByPeriod(aggregationResult2, startTime2, endTime2))
}
client.overrides.aggregateGroupByPeriod = stub(default = result)
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClientOverrides` |   |

### pageSizeGetChanges

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
var pageSizeGetChanges: Int
```

Overrides the page size to test pagination when calling `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/FakeHealthConnectClient#getChanges(kotlin.String)`.

This is typically used with a low number (such as 2) so that a low number of inserted records (such as 3) generate multiple pages. Use it to test token expiration as well.

### permissionController

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
open val permissionController: PermissionController
```

grants and revokes permissions.