Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package androidx.health.services.client |
| 18 | |
sutterlin | 747627f | 2022-11-01 23:17:17 +0000 | [diff] [blame] | 19 | import androidx.health.services.client.data.BatchingMode |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 20 | import androidx.health.services.client.data.DataPoint |
| 21 | import androidx.health.services.client.data.DataType |
Sean Kelley | e6ee363 | 2021-05-10 16:13:38 -0700 | [diff] [blame] | 22 | import androidx.health.services.client.data.ExerciseCapabilities |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 23 | import androidx.health.services.client.data.ExerciseConfig |
Jeff Gaston | bcaacc8 | 2023-05-09 22:44:28 -0400 | [diff] [blame] | 24 | import androidx.health.services.client.data.ExerciseEndReason |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 25 | import androidx.health.services.client.data.ExerciseGoal |
| 26 | import androidx.health.services.client.data.ExerciseInfo |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 27 | import androidx.health.services.client.data.ExerciseState |
| 28 | import androidx.health.services.client.data.ExerciseType |
Scarlett Song | 4634796 | 2022-10-25 16:59:48 -0700 | [diff] [blame] | 29 | import androidx.health.services.client.data.ExerciseTypeConfig |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 30 | import androidx.health.services.client.data.ExerciseUpdate |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 31 | import androidx.health.services.client.data.WarmUpConfig |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 32 | import com.google.common.util.concurrent.ListenableFuture |
| 33 | import java.util.concurrent.Executor |
| 34 | |
Julia McClellan | 1f4daf4 | 2022-11-03 15:57:36 -0400 | [diff] [blame] | 35 | @JvmDefaultWithCompatibility |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 36 | /** Client which provides a way to subscribe to the health data of a device during an exercise. */ |
| 37 | public interface ExerciseClient { |
| 38 | /** |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 39 | * Prepares for a new exercise. |
| 40 | * |
| 41 | * Once called, Health Services will warmup the sensors based on the [ExerciseType] and |
| 42 | * requested [DataType]s |
| 43 | * |
| 44 | * If the calling app already has an active exercise in progress or if it does not have the |
| 45 | * required permissions, then this call returns a failed future. If another app owns the active |
| 46 | * exercise then this call will succeed. |
| 47 | * |
| 48 | * Sensors available for warmup are GPS [DataType.LOCATION] and HeartRate |
| 49 | * [DataType.HEART_RATE_BPM]. Other [DataType]s requested for warmup based on exercise |
| 50 | * capabilities will be a no-op for the prepare stage. |
| 51 | * |
| 52 | * The DataType availability can be obtained through the |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 53 | * [ExerciseUpdateCallback.onAvailabilityChanged] callback. [ExerciseUpdate]s with the supported |
| 54 | * DataType [DataPoint] will also be returned in the [ExerciseState.PREPARING] state, though no |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 55 | * aggregation will occur until the exercise is started. |
| 56 | * |
| 57 | * If an app is actively preparing and another app starts tracking an active exercise then the |
Nagesh Pachorkar | dc9a67d | 2022-10-12 17:27:37 -0700 | [diff] [blame] | 58 | * preparing app should expect to receive an [ExerciseUpdate] with [ExerciseState.ENDED] along |
| 59 | * with the reason [ExerciseEndReason.AUTO_END_SUPERSEDED] to the [ExerciseUpdateCallback] |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 60 | * indicating that their session has been superseded and ended. At that point no additional |
| 61 | * updates to availability or data will be sent until the app calls prepareExercise again. |
| 62 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 63 | * @param configuration the [WarmUpConfig] containing the desired exercise and data types |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 64 | * @return a [ListenableFuture] that completes once Health Services starts preparing the sensors |
| 65 | * or fails due to missing permissions or the app owning another active exercise. |
| 66 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 67 | public fun prepareExerciseAsync(configuration: WarmUpConfig): ListenableFuture<Void> |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 68 | |
| 69 | /** |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 70 | * Starts a new exercise. |
| 71 | * |
Sean Kelley | e6ee363 | 2021-05-10 16:13:38 -0700 | [diff] [blame] | 72 | * Once started, Health Services will begin collecting data associated with the exercise. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 73 | * |
Sean Kelley | e6ee363 | 2021-05-10 16:13:38 -0700 | [diff] [blame] | 74 | * Since Health Services only allows a single active exercise at a time, this will terminate any |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 75 | * active exercise currently in progress before starting the new one. If this occurs, clients |
Nagesh Pachorkar | dc9a67d | 2022-10-12 17:27:37 -0700 | [diff] [blame] | 76 | * can expect to receive an [ExerciseUpdate] with [ExerciseState.ENDED] along with the reason |
| 77 | * [ExerciseEndReason.AUTO_END_SUPERSEDED] to the [ExerciseUpdateCallback] indicating that their |
| 78 | * exercise has been superseded and that no additional updates will be sent. Clients can use |
| 79 | * [getCurrentExerciseInfoAsync] (described below) to check if they or another app has an active |
| 80 | * exercise in-progress. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 81 | * |
Nagesh Pachorkar | bf89335 | 2022-11-18 11:23:27 -0800 | [diff] [blame] | 82 | * The exercise will be terminated and clients can expect to receive an [ExerciseUpdate] with |
| 83 | * [ExerciseState.ENDED] along with the reason [ExerciseEndReason.AUTO_END_MISSING_LISTENER] |
| 84 | * (indicating that their exercise has been automatically ended due to the lack of callback) if |
| 85 | * there is ever a five minute period where no [ExerciseUpdateCallback] is registered. A notable |
| 86 | * example is if the process with the registered [ExerciseUpdateCallback] dies and does not |
| 87 | * re-register the [ExerciseUpdateCallback] within five minutes. |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 88 | * |
| 89 | * Clients should only request [ExerciseType]s, [DataType]s, goals, and auto-pause enabled that |
Sean Kelley | 125448c | 2022-04-26 17:26:10 -0700 | [diff] [blame] | 90 | * matches the [ExerciseCapabilities] returned by [getCapabilitiesAsync] since Health Services |
| 91 | * will reject requests asking for unsupported configurations. |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 92 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 93 | * @param configuration the [ExerciseConfig] describing this exercise |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 94 | * @return a [ListenableFuture] that completes once the exercise has been started or fails due |
| 95 | * to the application missing the required permissions or requesting metrics which are not |
| 96 | * supported for the given [ExerciseType]. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 97 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 98 | public fun startExerciseAsync(configuration: ExerciseConfig): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * Pauses the current exercise, if it is currently started. |
| 102 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 103 | * Before transitioning to [ExerciseState.USER_PAUSED], Health Services will flush and return |
| 104 | * the sensor data. While the exercise is paused, active time and cumulative metrics such as |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 105 | * distance will not accumulate. Instantaneous measurements such as speed and heart rate will |
| 106 | * continue to update if requested in the [ExerciseConfig]. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 107 | * |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 108 | * Note that GPS and other sensors may be stopped when the exercise is paused in order to |
| 109 | * conserve battery. This may happen immediately, or after some time. (The exact behavior is |
| 110 | * hardware dependent.) Should this happen, access will automatically resume when the exercise |
| 111 | * is resumed. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 112 | * |
| 113 | * If the exercise is already paused then this method has no effect. If the exercise has ended |
| 114 | * then the returned future will fail. |
| 115 | * |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 116 | * @return a [ListenableFuture] that completes once the exercise has been paused or fails if the |
| 117 | * calling application does not own the active exercise. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 118 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 119 | public fun pauseExerciseAsync(): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Resumes the current exercise, if it is currently paused. |
| 123 | * |
| 124 | * Once resumed active time and cumulative metrics such as distance will resume accumulating. |
| 125 | * |
| 126 | * If the exercise has been started but is not currently paused this method has no effect. If |
| 127 | * the exercise has ended then the returned future will fail. |
| 128 | * |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 129 | * @return a [ListenableFuture] that completes once the exercise has been resumed or fails if |
| 130 | * the calling application does not own the active exercise. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 131 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 132 | public fun resumeExerciseAsync(): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 133 | |
| 134 | /** |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 135 | * Ends the current exercise, if it has been started. |
| 136 | * |
| 137 | * Health Services will flush and then shut down the active sensors and return an |
Sara Kato | 2153053 | 2022-05-26 17:02:30 +0000 | [diff] [blame] | 138 | * [ExerciseUpdate] with [ExerciseState.ENDED] along with the reason |
| 139 | * [ExerciseEndReason.USER_END] to the [ExerciseUpdateCallback]. If the exercise has ended then |
| 140 | * this future will fail. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 141 | * |
| 142 | * No additional metrics will be produced for the exercise and any on device persisted data |
| 143 | * about the exercise will be deleted after the summary has been sent back. |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 144 | * |
| 145 | * @return a [ListenableFuture] that completes once the exercise has been ended or fails if the |
| 146 | * calling application does not own the active exercise. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 147 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 148 | public fun endExerciseAsync(): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 151 | * Flushes the sensors for the active exercise. This call should be used sparingly and will be |
| 152 | * subject to throttling by Health Services. |
| 153 | * |
| 154 | * @return a [ListenableFuture] that completes once the flush has been completed or fails if the |
| 155 | * calling application does not own the active exercise. |
| 156 | */ |
Nagesh Pachorkar | e433156 | 2022-09-02 14:56:34 -0700 | [diff] [blame] | 157 | public fun flushAsync(): ListenableFuture<Void> |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 158 | |
| 159 | /** |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 160 | * Ends the current lap, calls [ExerciseUpdateCallback.onLapSummaryReceived] with data spanning |
| 161 | * the marked lap and starts a new lap. If the exercise supports laps this method can be called |
| 162 | * at any point after an exercise has been started and before it has been ended regardless of |
| 163 | * the exercise status. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 164 | * |
| 165 | * The metrics in the lap summary will start from either the start time of the exercise or the |
| 166 | * last time a lap was marked to the time this method is being called. |
| 167 | * |
| 168 | * If there's no exercise being tracked or if the exercise does not support laps then this |
| 169 | * future will fail. |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 170 | * |
| 171 | * @return a [ListenableFuture] that completes once the lap has been marked successfully or |
| 172 | * fails if the calling application does not own the active exercise |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 173 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 174 | public fun markLapAsync(): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 175 | |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 176 | /** |
| 177 | * Returns the current [ExerciseInfo]. |
| 178 | * |
| 179 | * This can be used by clients to determine if they or another app already owns an active |
| 180 | * exercise being tracked by Health Services. For example, if an app is killed and it learns it |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 181 | * owns the active exercise it can register a new [ExerciseUpdateCallback] and pick tracking up |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 182 | * from where it left off. |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 183 | * |
| 184 | * @return a [ListenableFuture] that contains information about the current exercise or fails if |
| 185 | * the calling application does not own the active exercise |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 186 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 187 | public fun getCurrentExerciseInfoAsync(): ListenableFuture<ExerciseInfo> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 190 | * Sets the callback for the current [ExerciseUpdate]. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 191 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 192 | * This callback won't be called until the calling application prepares or starts an exercise. |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 193 | * It will only receive updates from exercises tracked by this app. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 194 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 195 | * If an exercise is in progress, the [ExerciseUpdateCallback] is immediately called with the |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 196 | * associated [ExerciseUpdate], and subsequently whenever the state is updated or an event is |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 197 | * triggered. Health Services will cache [ExerciseUpdate]s of an active exercise that are |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 198 | * generated while a callback is not active (for example, due to the app getting killed) and |
| 199 | * deliver them as soon as the callback is registered again. If the client fails to maintain a |
| 200 | * live [ExerciseUpdateCallback] for at least five minutes during the duration of the exercise |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 201 | * Health Services can decide to terminate the exercise automatically. If this occurs, clients |
Nagesh Pachorkar | dc9a67d | 2022-10-12 17:27:37 -0700 | [diff] [blame] | 202 | * can expect to receive an [ExerciseUpdate] with [ExerciseState.ENDED] along with the reason |
| 203 | * [ExerciseEndReason.AUTO_END_MISSING_LISTENER] to the [ExerciseUpdateCallback] indicating that |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 204 | * their exercise has been automatically ended due to the lack of callback. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 205 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 206 | * Calls to the callback will be executed on the main application thread. To control where to |
| 207 | * execute the callback, see the overload taking an [Executor]. To remove the callback use |
| 208 | * [clearUpdateCallbackAsync]. |
| 209 | * |
| 210 | * @param callback the [ExerciseUpdateCallback] that will receive updates from Health Services |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 211 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 212 | public fun setUpdateCallback(callback: ExerciseUpdateCallback) |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 213 | |
| 214 | /** |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 215 | * Calls to the callback will be executed using the specified [Executor]. To execute the |
| 216 | * callback on the main application thread use the overload without the [Executor]. |
| 217 | * |
| 218 | * @param executor the [Executor] on which [callback] will be invoked |
| 219 | * @param callback the [ExerciseUpdateCallback] that will receive updates from Health Services |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 220 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 221 | public fun setUpdateCallback( |
| 222 | executor: Executor, |
| 223 | callback: ExerciseUpdateCallback |
| 224 | ) |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 225 | |
| 226 | /** |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 227 | * Clears the callback set using [setUpdateCallback]. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 228 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 229 | * If this callback is not already registered then this will be a no-op. |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 230 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 231 | * @param callback the [ExerciseUpdateCallback] to clear |
| 232 | * @return a [ListenableFuture] that completes once the callback has been cleared (or verified |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 233 | * not to be set). |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 234 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 235 | public fun clearUpdateCallbackAsync(callback: ExerciseUpdateCallback): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * Adds an [ExerciseGoal] for an active exercise. |
| 239 | * |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 240 | * Goals apply to only active exercises owned by the client, and will be invalidated once the |
| 241 | * exercise is complete. |
| 242 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 243 | * @param exerciseGoal the [ExerciseGoal] to add to this exercise |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 244 | * @return a [ListenableFuture] that completes once the exercise goal has been added. This |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 245 | * returned [ListenableFuture] fails if the calling app does not own the active exercise. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 246 | */ |
Sean Kelley | b9f566f | 2022-04-25 10:24:17 -0700 | [diff] [blame] | 247 | public fun addGoalToActiveExerciseAsync(exerciseGoal: ExerciseGoal<*>): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 248 | |
| 249 | /** |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 250 | * Removes an exercise goal for an active exercise. |
| 251 | * |
| 252 | * Takes into account equivalent milestones (i.e. milestones which are not equal but are |
| 253 | * different representation of a common milestone. e.g. milestone A for every 2kms, currently at |
| 254 | * threshold of 10kms, and milestone B for every 2kms, currently at threshold of 8kms). |
| 255 | * |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 256 | * @param exerciseGoal the [ExerciseGoal] to remove from this exercise |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 257 | * @return a [ListenableFuture] that completes once the exercise goal has been removed. This |
| 258 | * returned [ListenableFuture] fails if the exercise is not active, and will be a no-op if |
| 259 | * [exerciseGoal] has not been added in the past. |
| 260 | */ |
Sean Kelley | b9f566f | 2022-04-25 10:24:17 -0700 | [diff] [blame] | 261 | public fun removeGoalFromActiveExerciseAsync( |
| 262 | exerciseGoal: ExerciseGoal<*> |
| 263 | ): ListenableFuture<Void> |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 264 | |
| 265 | /** |
| 266 | * Enables or disables auto pause/resume for the current exercise. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 267 | * |
| 268 | * @param enabled a boolean to indicate if should be enabled or disabled |
Sean Kelley | 125448c | 2022-04-26 17:26:10 -0700 | [diff] [blame] | 269 | * @return a [ListenableFuture] that completes once the override has completed. This returned |
| 270 | * [ListenableFuture] fails if an exercise is not active for this app. |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 271 | */ |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 272 | public fun overrideAutoPauseAndResumeForActiveExerciseAsync( |
| 273 | enabled: Boolean |
| 274 | ): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 275 | |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 276 | /** |
sutterlin | 747627f | 2022-11-01 23:17:17 +0000 | [diff] [blame] | 277 | * Sets the batching mode for the current exercise. |
| 278 | * |
| 279 | * @param batchingModes [BatchingMode] overrides for exercise updates. Passing an empty set will |
| 280 | * clear all existing overrides. |
| 281 | * @return a [ListenableFuture] that completes once the override has completed. This returned |
| 282 | * [ListenableFuture] fails if an exercise is not active for this app. |
| 283 | */ |
| 284 | public fun overrideBatchingModesForActiveExerciseAsync( |
| 285 | batchingModes: Set<BatchingMode> |
| 286 | ): ListenableFuture<Void> |
| 287 | |
| 288 | /** |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 289 | * Returns the [ExerciseCapabilities] of this client for the device. |
| 290 | * |
| 291 | * This can be used to determine what [ExerciseType]s and [DataType]s this device supports. |
| 292 | * Clients should use the capabilities to inform their requests since Health Services will |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 293 | * typically reject requests made for [DataType]s or features (such as auto-pause) which are not |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 294 | * enabled for the rejected [ExerciseType]. |
Sean Kelley | be4255a | 2022-04-04 14:37:43 -0700 | [diff] [blame] | 295 | * |
| 296 | * @return a [ListenableFuture] containing the [ExerciseCapabilities] for this device |
Justin Lannin | 665af7f | 2021-09-07 17:56:57 +0000 | [diff] [blame] | 297 | */ |
Sean Kelley | 1d0bdb5 | 2022-04-23 14:53:11 -0700 | [diff] [blame] | 298 | public fun getCapabilitiesAsync(): ListenableFuture<ExerciseCapabilities> |
Scarlett Song | 4634796 | 2022-10-25 16:59:48 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Updates the configurable exercise type attributes for the current exercise. |
| 302 | * |
| 303 | * This can be used to update the configurable attributes for the ongoing exercise, as defined |
| 304 | * in [ExerciseTypeConfig]. Minimum Exercise API version for this function is 3. |
| 305 | * |
| 306 | * @param exerciseTypeConfig a configuration containing the new values for the configurable |
| 307 | * attributes |
| 308 | * @return a [ListenableFuture] that completes when the configuration has been updated. |
Scarlett Song | 4634796 | 2022-10-25 16:59:48 -0700 | [diff] [blame] | 309 | */ |
| 310 | public fun updateExerciseTypeConfigAsync( |
| 311 | exerciseTypeConfig: ExerciseTypeConfig |
Scarlett Song | e5d808e | 2022-12-09 14:38:37 -0800 | [diff] [blame] | 312 | ): ListenableFuture<Void> |
Sean Kelley | 7817f41 | 2021-05-08 17:30:48 -0700 | [diff] [blame] | 313 | } |